@nhost/nhost-js 1.0.4 → 1.0.7
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/dist/clients/functions.d.ts +0 -0
- package/dist/clients/graphql.d.ts +0 -0
- package/dist/core/index.d.ts +0 -0
- package/dist/core/nhost-client.d.ts +0 -0
- package/dist/index.cjs.js +0 -0
- package/dist/index.cjs.js.map +0 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.es.js +1 -1
- package/dist/index.es.js.map +2 -2
- package/dist/types.d.ts +0 -0
- package/package.json +3 -3
- package/src/index.ts +0 -6
|
File without changes
|
|
File without changes
|
package/dist/core/index.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/dist/index.cjs.js
CHANGED
|
File without changes
|
package/dist/index.cjs.js.map
CHANGED
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
File without changes
|
package/dist/index.es.js
CHANGED
|
@@ -6,7 +6,7 @@ Event: `).concat(JSON.stringify(l.data))),n.state;if(n.status!==z.Running&&!n.op
|
|
|
6
6
|
Event: `).concat(JSON.stringify(l.data)));return n.scheduler.schedule(function(){n.forward(l);var h=n.nextState(l);n.update(h,l)}),n._state},this.sendTo=function(u,d){var l=n.parent&&(d===ge.Parent||n.parent.id===d),h=l?n.parent:A(d)?n.children.get(d)||St.get(d):xi(d)?d:void 0;if(!h){if(!l)throw new Error("Unable to send event to child '".concat(d,"' from service '").concat(n.id,"'."));D||L(!1,"Service '".concat(n.id,"' has no parent: unable to send event ").concat(u.type));return}"machine"in h?h.send(v(v({},u),{name:u.name===qr?"".concat(Ce(n.id)):u.name,origin:n.sessionId})):h.send(u.data)};var i=v(v({},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 Hr({deferEvents:this.options.deferEvents}),this.sessionId=St.bookId()}return Object.defineProperty(t.prototype,"initialState",{get:function(){var e=this;return this._initialState?this._initialState:Pe(this,function(){return e._initialState=e.machine.initialState,e._initialState})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"state",{get:function(){return D||L(this.status!==z.NotStarted,"Attempted to read state from uninitialized service '".concat(this.id,"'. Make sure the service is started first.")),this._state},enumerable:!1,configurable:!0}),t.prototype.execute=function(e,r){var n,i;try{for(var s=b(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,d=this;if(e._sessionid=this.sessionId,this._state=e,this.options.execute&&this.execute(this.state),this.children.forEach(function(O){d.state.children[O.id]=O}),this.devTools&&this.devTools.send(r.data,e),e.event)try{for(var l=b(this.eventListeners),h=l.next();!h.done;h=l.next()){var g=h.value;g(e.event)}}catch(O){n={error:O}}finally{try{h&&!h.done&&(i=l.return)&&i.call(l)}finally{if(n)throw n.error}}try{for(var E=b(this.listeners),p=E.next();!p.done;p=E.next()){var g=p.value;g(e,e.event)}}catch(O){s={error:O}}finally{try{p&&!p.done&&(o=E.return)&&o.call(E)}finally{if(s)throw s.error}}try{for(var w=b(this.contextListeners),y=w.next();!y.done;y=w.next()){var x=y.value;x(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(O){a={error:O}}finally{try{y&&!y.done&&(c=w.return)&&c.call(w)}finally{if(a)throw a.error}}var C=_e(e.configuration||[],this.machine);if(this.state.configuration&&C){var I=e.configuration.find(function(O){return O.type==="final"&&O.parent===d.machine}),B=I&&I.doneData?be(I.doneData,e.context,r):void 0;try{for(var T=b(this.doneListeners),S=T.next();!S.done;S=T.next()){var g=S.value;g(Oe(this.id,B))}}catch(O){f={error:O}}finally{try{S&&!S.done&&(u=T.return)&&u.call(T)}finally{if(f)throw f.error}}this.stop()}},t.prototype.onTransition=function(e){return this.listeners.add(e),this.status===z.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===z.Running&&s(this.state),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===z.Running)return this;this.machine._init(),St.register(this.sessionId,this),this.initialized=!0,this.status=z.Running;var n=e===void 0?this.initialState:Pe(this,function(){return Fi(e)?r.machine.resolveState(e):r.machine.resolveState(se.from(e,r.machine.context))});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(function(){r.update(n,Ae)}),this},t.prototype.stop=function(){var e,r,n,i,s,o,a,c,f,u,d=this;try{for(var l=b(this.listeners),h=l.next();!h.done;h=l.next()){var g=h.value;this.listeners.delete(g)}}catch(S){e={error:S}}finally{try{h&&!h.done&&(r=l.return)&&r.call(l)}finally{if(e)throw e.error}}try{for(var E=b(this.stopListeners),p=E.next();!p.done;p=E.next()){var g=p.value;g(),this.stopListeners.delete(g)}}catch(S){n={error:S}}finally{try{p&&!p.done&&(i=E.return)&&i.call(E)}finally{if(n)throw n.error}}try{for(var w=b(this.contextListeners),y=w.next();!y.done;y=w.next()){var g=y.value;this.contextListeners.delete(g)}}catch(S){s={error:S}}finally{try{y&&!y.done&&(o=w.return)&&o.call(w)}finally{if(s)throw s.error}}try{for(var x=b(this.doneListeners),C=x.next();!C.done;C=x.next()){var g=C.value;this.doneListeners.delete(g)}}catch(S){a={error:S}}finally{try{C&&!C.done&&(c=x.return)&&c.call(x)}finally{if(a)throw a.error}}if(!this.initialized)return this;_([],R(this.state.configuration),!1).sort(function(S,O){return O.order-S.order}).forEach(function(S){var O,U;try{for(var V=b(S.definition.exit),Q=V.next();!Q.done;Q=V.next()){var ye=Q.value;d.exec(ye,d.state)}}catch(Mt){O={error:Mt}}finally{try{Q&&!Q.done&&(U=V.return)&&U.call(V)}finally{if(O)throw O.error}}}),this.children.forEach(function(S){N(S.stop)&&S.stop()});try{for(var I=b(Object.keys(this.delayedEventsMap)),B=I.next();!B.done;B=I.next()){var T=B.value;this.clock.clearTimeout(this.delayedEventsMap[T])}}catch(S){f={error:S}}finally{try{B&&!B.done&&(u=I.return)&&u.call(I)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.initialized=!1,this.status=z.Stopped,St.free(this.sessionId),this},t.prototype.batch=function(e){var r=this;if(this.status===z.NotStarted&&this.options.deferEvents)D||L(!1,"".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,`" and are deferred. Make sure .start() is called for this service.
|
|
7
7
|
Event: `).concat(JSON.stringify(event)));else if(this.status!==z.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(l){var h=F(l);r.forward(h),s=Pe(r,function(){return r.machine.transition(s,h)}),a.push.apply(a,_([],R(s.actions.map(function(g){return Vi(g,s)})),!1)),o=o||!!s.changed};try{for(var f=b(e),u=f.next();!u.done;u=f.next()){var d=u.value;c(d)}}catch(l){n={error:l}}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,F(e[e.length-1]))})},t.prototype.sender=function(e){return this.send.bind(this,e)},t.prototype.nextState=function(e){var r=this,n=F(e);if(n.name.indexOf(kr)===0&&!this.state.nextEvents.some(function(s){return s.indexOf(kr)===0}))throw n.data.data;var i=Pe(this,function(){return r.machine.transition(r.state,n)});return i},t.prototype.forward=function(e){var r,n;try{for(var i=b(this.forwardTo),s=i.next();!s.done;s=i.next()){var 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||Yt(e.type,n),a=N(o)?o:o?o.exec:e.exec;if(a)try{return a(i,s.data,{action:e,state:this.state,_event:s})}catch(C){throw this.parent&&this.parent.send({type:"xstate.error",data:C}),C}switch(e.type){case Te: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 jt:this.cancel(e.sendId);break;case ot:{if(this.status!==z.Running)return;var f=e.activity;if(!this.state.activities[f.id||f.type])break;if(f.type===P.Invoke){var u=Xt(f.src),d=this.machine.options.services?this.machine.options.services[u.type]:void 0,l=f.id,h=f.data;D||L(!("forward"in f),"`forward` property is deprecated (found in invocation of '".concat(f.src,"' in in machine '").concat(this.machine.id,"'). ")+"Please use `autoForward` instead.");var g="autoForward"in f?f.autoForward:!!f.forward;if(!d){D||L(!1,"No service found for invocation '".concat(f.src,"' in machine '").concat(this.machine.id,"'."));return}var E=h?be(h,i,s):void 0;if(typeof d=="string")return;var p=N(d)?d(i,s.data,{data:E,src:u,meta:f.meta}):d;if(!p)return;var w=void 0;fe(p)&&(p=E?p.withContext(E):p,w={autoForward:g}),this.spawn(p,l,w)}else this.spawnActivity(f);break}case Be:{this.stopChild(e.activity.id);break}case Ft:var y=e.label,x=e.value;y?this.logger(y,x):this.logger(x);break;default:D||L(!1,"No implementation found for action type '".concat(e.type,"'"));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),N(r.stop)&&r.stop())},t.prototype.spawn=function(e,r,n){if(Mr(e))return this.spawnPromise(Promise.resolve(e),r);if(N(e))return this.spawnCallback(e,r);if(Di(e))return this.spawnActor(e,r);if(wi(e))return this.spawnObservable(e,r);if(fe(e))return this.spawnMachine(e,v(v({},n),{id:r}));if(gi(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,v(v({},this.options),{parent:this,id:r.id||e.id})),s=v(v({},yc),r);s.sync&&i.onTransition(function(a){n.send(ut,{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(F(a,{origin:i.id}))}).start(),o},t.prototype.spawnBehavior=function(e,r){var n=Gi(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(F(Oe(r,c),{origin:r})))},function(c){if(!s){i.removeChild(r);var f=Ce(r,c);try{i.send(F(f,{origin:r}))}catch(u){bi(c,u,r),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 d=ht(c,f,u),l=!1;return e.then(function(h){l||(d.next(h),!l&&d.complete())},function(h){l||d.error(h)}),{unsubscribe:function(){return l=!0}}},stop:function(){s=!0},toJSON:function(){return{id:r}},getSnapshot:function(){return o}},n[ce]=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(l){c=l,a.forEach(function(h){return h(l)}),!s&&i.send(F(l,{origin:r}))},u;try{u=e(f,function(l){o.add(l)})}catch(l){this.send(Ce(r,l))}if(Mr(u))return this.spawnPromise(u,r);var d=(n={id:r,send:function(l){return o.forEach(function(h){return h(l)})},subscribe:function(l){var h=ht(l);return a.add(h.next),{unsubscribe:function(){a.delete(h.next)}}},stop:function(){s=!0,N(u)&&u()},toJSON:function(){return{id:r}},getSnapshot:function(){return c}},n[ce]=function(){return this},n);return this.children.set(r,d),d},t.prototype.spawnObservable=function(e,r){var n,i=this,s,o=e.subscribe(function(c){s=c,i.send(F(c,{origin:r}))},function(c){i.removeChild(r),i.send(F(Ce(r,c),{origin:r}))},function(){i.removeChild(r),i.send(F(Oe(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[ce]=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){D||L(!1,"No implementation found for activity '".concat(e.type,"'"));return}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[ce]=function(){return this},n))},t.prototype.attachDev=function(){var e=er();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(v(v({name:this.id,autoPause:!0,stateSanitizer:function(n){return{value:n.value,context:n.context,actions:n.actions}}},r),{features:v({jump:!1,skip:!1},r?r.features:void 0)}),this.machine),this.devTools.init(this.state)}Hi(this)}},t.prototype.toJSON=function(){return{id:this.id}},t.prototype[ce]=function(){return this},t.prototype.getSnapshot=function(){return this.status===z.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=me,t}();function me(t,e){var r=new Ji(t,e);return r}function gc(t){if(typeof t=="string"){var e={type:t};return e.toString=function(){return t},e}return t}function wt(t){return v(v({type:at},t),{toJSON:function(){t.onDone,t.onError;var e=je(t,["onDone","onError"]);return v(v({},e),{type:at,src:gc(t.src)})}})}var $e="",Jr="#",xt="*",Je={},ze=function(t){return t[0]===Jr},Ec=function(){return{actions:{},guards:{},services:{},activities:{},delays:{}}},Sc=function(t,e,r){var n=r.slice(0,-1).some(function(s){return!("cond"in s)&&!("in"in s)&&(A(s.target)||fe(s.target))}),i=e===$e?"the transient event":"event '".concat(e,"'");L(!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.")},zi=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(Ec(),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:Vt),this.id=this.config.id||_([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,D||L(!("parallel"in this.config),'The "parallel" property is deprecated and will be removed in version 4.1. '.concat(this.config.parallel?"Replace with `type: 'parallel'`":"Use `type: '".concat(this.type,"'`")," in the config for state node '").concat(this.id,"' instead.")),this.initial=this.config.initial,this.states=this.config.states?He(this.config.states,function(f,u){var d,l=new t(f,{},void 0,{parent:s,key:u});return Object.assign(s.idMap,v((d={},d[l.id]=l,d),l.idMap)),l}):Je;var a=0;function c(f){var u,d;f.order=a++;try{for(var l=b(Ne(f)),h=l.next();!h.done;h=l.next()){var g=h.value;c(g)}}catch(E){u={error:E}}finally{try{h&&!h.done&&(d=l.return)&&d.call(l)}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===$e}):$e in this.config.on:!1),this.strict=!!this.config.strict,this.onEntry=te(this.config.entry||this.config.onEntry).map(function(f){return Ge(f)}),this.onExit=te(this.config.exit||this.config.onExit).map(function(f){return Ge(f)}),this.meta=this.config.meta,this.doneData=this.type==="final"?this.config.data:void 0,this.invoke=te(this.config.invoke).map(function(f,u){var d,l;if(fe(f)){var h=pt(s.id,u);return s.machine.options.services=v((d={},d[h]=f,d),s.machine.options.services),wt({src:h,id:h})}else if(A(f.src)){var h=f.id||pt(s.id,u);return wt(v(v({},f),{id:h,src:f.src}))}else if(fe(f.src)||N(f.src)){var h=f.id||pt(s.id,u);return s.machine.options.services=v((l={},l[h]=f.src,l),s.machine.options.services),wt(v(v({id:h},f),{src:h}))}else{var g=f.src;return wt(v(v({id:pt(s.id,u)},f),{src:g}))}}),this.activities=te(this.config.activities).concat(this.invoke).map(function(f){return Zt(f)}),this.transition=this.transition.bind(this),this.tags=te(this.config.tags)}return t.prototype._init=function(){this.__cache.transitions||Br(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:v(v({},i),e.actions),activities:v(v({},s),e.activities),guards:v(v({},o),e.guards),services:v(v({},a),e.services),delays:v(v({},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 N(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:He(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===$e,n=this.transitions.filter(function(i){var s=i.eventType===e;return r?s:s||i.eventType===xt});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=N(s)?"".concat(e.id,":delay[").concat(o,"]"):s,c=Ni(a,e.id);return e.onEntry.push(vt(c,{delay:s})),e.onExit.push(Ai(c)),c},i=pe(r)?r.map(function(s,o){var a=n(s.delay,o);return v(v({},s),{event:a})}):q(Object.keys(r).map(function(s,o){var a=r[s],c=A(a)?{target:a}:a,f=isNaN(+s)?s:+s,u=n(f,o);return te(c).map(function(d){return v(v({},d),{event:u,delay:f})})}));return i.map(function(s){var o=s.delay;return v(v({},e.formatTransition(s)),{delay:o})})},t.prototype.getStateNodes=function(e){var r,n=this;if(!e)return[];var i=e instanceof se?e.value:Ve(e,this.delimiter);if(A(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,_([],R(q(o.map(function(c){return n.getStateNode(c).getStateNodes(i[c])}))),!1)),a},t.prototype.handles=function(e){var r=Jt(e);return this.events.includes(r)},t.prototype.resolveState=function(e){var r=e instanceof se?e:se.create(e),n=Array.from(Ie([],this.getStateNodes(r.value)));return new se(v(v({},r),{value:this.resolve(r.value),configuration:n,done:_e(n,this),tags:Fr(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=b(Object.keys(e)),c=a.next();!c.done;c=a.next()){var f=c.value,u=e[f];if(!!u){var d=this.getStateNode(f),l=d._transition(u,r,n);l&&(o[f]=l)}}}catch(y){i={error:y}}finally{try{c&&!c.done&&(s=a.return)&&s.call(a)}finally{if(i)throw i.error}}var h=Object.keys(o).map(function(y){return o[y]}),g=q(h.map(function(y){return y.transitions})),E=h.some(function(y){return y.transitions.length>0});if(!E)return this.next(r,n);var p=q(h.map(function(y){return y.entrySet})),w=q(Object.keys(o).map(function(y){return o[y].configuration}));return{transitions:g,entrySet:p,exitSet:q(h.map(function(y){return y.exitSet})),configuration:w,source:r,actions:q(Object.keys(o).map(function(y){return o[y].actions}))}},t.prototype._transition=function(e,r,n){return A(e)?this.transitionLeafNode(e,r,n):Object.keys(e).length===1?this.transitionCompoundNode(e,r,n):this.transitionParallelNode(e,r,n)},t.prototype.getTransitionData=function(e,r){return this._transition(e.value,e,F(r))},t.prototype.next=function(e,r){var n,i,s=this,o=r.name,a=[],c=[],f;try{for(var u=b(this.getCandidates(o)),d=u.next();!d.done;d=u.next()){var l=d.value,h=l.cond,g=l.in,E=e.context,p=g?A(g)&&ze(g)?e.matches(Ve(this.getStateNodeById(g).path,this.delimiter)):ft(Ve(g,this.delimiter),pi(this.path.slice(0,-2))(e.value)):!0,w=!1;try{w=!h||Kt(this.machine,h,E,r,e)}catch(I){throw new Error("Unable to evaluate guard '".concat(h.name||h.type,"' in transition for event '").concat(o,"' in state node '").concat(this.id,`':
|
|
8
8
|
`).concat(I.message))}if(w&&p){l.target!==void 0&&(c=l.target),a.push.apply(a,_([],R(l.actions),!1)),f=l;break}}}catch(I){n={error:I}}finally{try{d&&!d.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 y=q(c.map(function(I){return s.getRelativeStateNodes(I,e.historyValue)})),x=!!f.internal,C=x?[]:q(y.map(function(I){return s.nodesFromChild(I)}));return{transitions:[f],entrySet:C,exitSet:x?[]:[this],configuration:y,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=Ie([],i?this.getStateNodes(i.value):[this]),u=e.configuration.length?Ie(f,e.configuration):f;try{for(var d=b(u),l=d.next();!l.done;l=d.next()){var h=l.value;Et(f,h)||e.entrySet.push(h)}}catch(T){s={error:T}}finally{try{l&&!l.done&&(o=d.return)&&o.call(d)}finally{if(s)throw s.error}}try{for(var g=b(f),E=g.next();!E.done;E=g.next()){var h=E.value;(!Et(u,h)||Et(e.exitSet,h.parent))&&e.exitSet.push(h)}}catch(T){a={error:T}}finally{try{E&&!E.done&&(c=g.return)&&c.call(g)}finally{if(a)throw a.error}}var p=q(e.entrySet.map(function(T){var S=[];if(T.type!=="final")return S;var O=T.parent;if(!O.parent)return S;S.push(yt(T.id,T.doneData),yt(O.id,T.doneData?be(T.doneData,r,n):void 0));var U=O.parent;return U.type==="parallel"&&Ne(U).every(function(V){return _e(e.configuration,V)})&&S.push(yt(U.id)),S}));e.exitSet.sort(function(T,S){return S.order-T.order}),e.entrySet.sort(function(T,S){return T.order-S.order});var w=new Set(e.entrySet),y=new Set(e.exitSet),x=R([q(Array.from(w).map(function(T){return _(_([],R(T.activities.map(function(S){return Oi(S)})),!1),R(T.onEntry),!1)})).concat(p.map(Ri)),q(Array.from(y).map(function(T){return _(_([],R(T.onExit),!1),R(T.activities.map(function(S){return Ci(S)})),!1)}))],2),C=x[0],I=x[1],B=mt(I.concat(e.actions).concat(C),this.machine.options.actions);return B},t.prototype.transition=function(e,r,n){e===void 0&&(e=this.initialState);var i=F(r),s;if(e instanceof se)s=n===void 0?e:this.resolveState(se.from(e,n));else{var o=A(e)?this.resolve(ct(this.getResolvedPath(e))):this.resolve(e),a=n!=null?n:this.machine.context;s=this.resolveState(se.from(o,a))}if(!D&&i.name===xt)throw new Error("An event cannot have the wildcard type ('".concat(xt,"')"));if(this.strict&&!this.events.includes(i.name)&&!yi(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=Ie([],this.getStateNodes(s.value)),u=c.configuration.length?Ie(f,c.configuration):f;return c.configuration=_([],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,_([],R(s),!1)),e},t.prototype.resolveTransition=function(e,r,n,i){var s,o,a=this;i===void 0&&(i=Ae);var c=e.configuration,f=!r||e.transitions.length>0,u=f?Li(this.machine,c):void 0,d=r?r.historyValue?r.historyValue:e.source?this.machine.historyValue(r.value):void 0:void 0,l=this.getActions(e,n,i,r),h=r?v({},r.activities):{};try{for(var g=b(l),E=g.next();!E.done;E=g.next()){var p=E.value;p.type===ot?h[p.activity.id||p.activity.type]=p:p.type===Be&&(h[p.activity.id||p.activity.type]=!1)}}catch(ee){s={error:ee}}finally{try{E&&!E.done&&(o=g.return)&&o.call(g)}finally{if(s)throw s.error}}var w=R(Qt(this,r,n,i,l,this.machine.config.preserveActionOrder),2),y=w[0],x=w[1],C=R($t(y,function(ee){return ee.type===Fe||ee.type===Te&&ee.to===ge.Internal}),2),I=C[0],B=C[1],T=y.filter(function(ee){var Me;return ee.type===ot&&((Me=ee.activity)===null||Me===void 0?void 0:Me.type)===at}),S=T.reduce(function(ee,Me){return ee[Me.activity.id]=ki(Me.activity,a.machine,x,i),ee},r?v({},r.children):{}),O=f?e.configuration:r?r.configuration:[],U=_e(O,this),V=new se({value:u||r.value,context:x,_event:i,_sessionid:r?r._sessionid:null,historyValue:u?d?Si(d,u):void 0:r?r.historyValue:void 0,history:!u||e.source?r:void 0,actions:u?B:[],activities:u?h:r?r.activities:{},events:[],configuration:O,transitions:e.transitions,children:S,done:U,tags:r==null?void 0:r.tags,machine:this}),Q=n!==x;V.changed=i.name===ut||Q;var ye=V.history;ye&&delete ye.history;var Mt=!U&&(this._transient||c.some(function(ee){return ee._transient}));if(!f&&(!Mt||i.name===$e))return V;var Z=V;if(!U)for(Mt&&(Z=this.resolveRaisedTransition(Z,{type:ci},i));I.length;){var Zu=I.shift();Z=this.resolveRaisedTransition(Z,Zu._event,i)}var ec=Z.changed||(ye?!!Z.actions.length||Q||typeof ye.value!=typeof Z.value||!Vr(Z.value,ye.value):void 0);return Z.changed=ec,Z.history=ye,Z.tags=Fr(Z.configuration),Z},t.prototype.getStateNode=function(e){if(ze(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=ze(e)?e.slice(Jr.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"&&ze(e))try{return this.getStateNodeById(e.slice(1))}catch{}for(var r=zt(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||Je;switch(this.type){case"parallel":return He(this.initialStateValue,function(s,o){return s?n.getStateNode(o).resolve(e[o]||s):Je});case"compound":if(A(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?He(e,function(s,o){return s?n.getStateNode(o).resolve(s):Je}):this.initialStateValue||{};default:return e||Je}},t.prototype.getResolvedPath=function(e){if(ze(e)){var r=this.machine.idMap[e.slice(Jr.length)];if(!r)throw new Error("Unable to find state node '".concat(e,"'"));return r.path}return zt(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=Ur(this.states,function(n){return n.initialStateValue||Je},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=gt(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;A(r.target)?e=ze(r.target)?ct(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(gt(this))return[this];if(this.type==="compound"&&!this.initial)return D||L(!1,"Compound state node '".concat(this.id,"' has no initial state.")),[this];var r=lt(this.initialStateValue);return q(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:Ur(this.states,function(r,n){if(!e)return r.historyValue();var i=A(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?q(lt(i).map(function(o){return n.getFromRelativePath(o)})):n.initialStateNodes}var s=mi(n.path,"states")(e).current;return A(s)?[n.getStateNode(s)]:q(lt(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=q(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=b(Object.keys(s)),c=a.next();!c.done;c=a.next()){var f=c.value,u=s[f];if(u.states)try{for(var d=(n=void 0,b(u.events)),l=d.next();!l.done;l=d.next()){var h=l.value;o.add("".concat(h))}}catch(g){n={error:g}}finally{try{l&&!l.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}}}catch(g){e={error:g}}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(!A(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,`':
|
|
9
|
-
`).concat(a.message))}else return r.getStateNodeByPath(s)})},t.prototype.formatTransition=function(e){var r=this,n=Ti(e.target),i="internal"in e?e.internal:n?n.some(function(c){return A(c)&&c[0]===r.delimiter}):!0,s=this.machine.options.guards,o=this.resolveTarget(n),a=v(v({},e),{actions:mt(te(e.actions)),cond:Wt(e.cond,s),target:o,source:this,internal:i,eventType:e.event,toJSON:function(){return v(v({},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=xt,a=s[o],c=a===void 0?[]:a,f=je(s,[typeof o=="symbol"?o:o+""]);i=q(Object.keys(f).map(function(y){!D&&y===$e&&L(!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 x=Re(y,f[y]);return D||Sc(n,y,x),x}).concat(Re(xt,c)))}var u=this.config.always?Re("",this.config.always):[],d=this.config.onDone?Re(String(yt(this.id)),this.config.onDone):[];D||L(!(this.config.onDone&&!this.parent),'Root nodes cannot have an ".onDone" transition. Please check the config of "'.concat(this.id,'".'));var l=q(this.invoke.map(function(y){var x=[];return y.onDone&&x.push.apply(x,_([],R(Re(String(Oe(y.id)),y.onDone)),!1)),y.onError&&x.push.apply(x,_([],R(Re(String(Ce(y.id)),y.onError)),!1)),x})),h=this.after,g=q(_(_(_(_([],R(d),!1),R(l),!1),R(i),!1),R(u),!1).map(function(y){return te(y).map(function(x){return n.formatTransition(x)})}));try{for(var E=b(h),p=E.next();!p.done;p=E.next()){var w=p.value;g.push(w)}}catch(y){e={error:y}}finally{try{p&&!p.done&&(r=E.return)&&r.call(E)}finally{if(e)throw e.error}}return g},t}();function oe(t,e){return new zi(t,e)}var k=Pi,$=vt;function Wi(t){return!!(t&&typeof t.then=="function")}var wc=Promise.resolve(!1),qp=Promise.resolve(!0),le=Promise.resolve();function tr(t,e){return t||(t=0),new Promise(function(r){return setTimeout(function(){return r(e)},t)})}function Ki(t,e){return Math.floor(Math.random()*(e-t+1)+t)}function Tt(){return Math.random().toString(36).substring(2)}var $i=0,zr=0;function Ee(){var t=new Date().getTime();return t===$i?(zr++,t*1e3+zr):($i=t,zr=0,t*1e3)}var Se=Object.prototype.toString.call(typeof process!="undefined"?process:0)==="[object process]";var xc=Ee,Tc="native";function bc(t){var e={messagesCallback:null,bc:new BroadcastChannel(t),subFns:[]};return e.bc.onmessage=function(r){e.messagesCallback&&e.messagesCallback(r.data)},e}function Rc(t){t.bc.close(),t.subFns=[]}function Ac(t,e){try{return t.bc.postMessage(e,!1),le}catch(r){return Promise.reject(r)}}function Oc(t,e){t.messagesCallback=e}function Cc(){if(Se&&typeof window=="undefined")return!1;if(typeof BroadcastChannel=="function"){if(BroadcastChannel._pubkey)throw new Error("BroadcastChannel: Do not overwrite window.BroadcastChannel with this module, this is not a polyfill");return!0}else return!1}function Pc(){return 150}var Xi={create:bc,close:Rc,onMessage:Oc,postMessage:Ac,canBeUsed:Cc,type:Tc,averageResponseTime:Pc,microSeconds:xc};var rr=function(){function t(e){this.ttl=e,this.set=new Set,this.timeMap=new Map}return t.prototype.has=function(e){return this.set.has(e)},t.prototype.add=function(e){var r=this;this.timeMap.set(e,Yi()),this.set.add(e),setTimeout(function(){Nc(r)},0)},t.prototype.clear=function(){this.set.clear(),this.timeMap.clear()},t}();function Nc(t){for(var e=Yi()-t.ttl,r=t.set[Symbol.iterator]();;){var n=r.next().value;if(!n)return;var i=t.timeMap.get(n);if(i<e)t.timeMap.delete(n),t.set.delete(n);else return}}function Yi(){return new Date().getTime()}function We(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=JSON.parse(JSON.stringify(t));return typeof e.webWorkerSupport=="undefined"&&(e.webWorkerSupport=!0),e.idb||(e.idb={}),e.idb.ttl||(e.idb.ttl=1e3*45),e.idb.fallbackInterval||(e.idb.fallbackInterval=150),t.idb&&typeof t.idb.onclose=="function"&&(e.idb.onclose=t.idb.onclose),e.localstorage||(e.localstorage={}),e.localstorage.removeTimeout||(e.localstorage.removeTimeout=1e3*60),t.methods&&(e.methods=t.methods),e.node||(e.node={}),e.node.ttl||(e.node.ttl=1e3*60*2),e.node.maxParallelWrites||(e.node.maxParallelWrites=2048),typeof e.node.useFastPath=="undefined"&&(e.node.useFastPath=!0),e}var Ic=Ee,_c="pubkey.broadcast-channel-0-",ve="messages",kc="idb";function Qi(){if(typeof indexedDB!="undefined")return indexedDB;if(typeof window!="undefined"){if(typeof window.mozIndexedDB!="undefined")return window.mozIndexedDB;if(typeof window.webkitIndexedDB!="undefined")return window.webkitIndexedDB;if(typeof window.msIndexedDB!="undefined")return window.msIndexedDB}return!1}function qc(t){var e=Qi(),r=_c+t,n=e.open(r,1);n.onupgradeneeded=function(s){var o=s.target.result;o.createObjectStore(ve,{keyPath:"id",autoIncrement:!0})};var i=new Promise(function(s,o){n.onerror=function(a){return o(a)},n.onsuccess=function(){s(n.result)}});return i}function Dc(t,e,r){var n=new Date().getTime(),i={uuid:e,time:n,data:r},s=t.transaction([ve],"readwrite");return new Promise(function(o,a){s.oncomplete=function(){return o()},s.onerror=function(f){return a(f)};var c=s.objectStore(ve);c.add(i)})}function Uc(t,e){var r=t.transaction(ve).objectStore(ve),n=[];function i(){try{var s=IDBKeyRange.bound(e+1,1/0);return r.openCursor(s)}catch{return r.openCursor()}}return new Promise(function(s){i().onsuccess=function(o){var a=o.target.result;a?a.value.id<e+1?a.continue(e+1):(n.push(a.value),a.continue()):s(n)}})}function Mc(t,e){var r=t.transaction([ve],"readwrite").objectStore(ve).delete(e);return new Promise(function(n){r.onsuccess=function(){return n()}})}function Lc(t,e){var r=new Date().getTime()-e,n=t.transaction(ve).objectStore(ve),i=[];return new Promise(function(s){n.openCursor().onsuccess=function(o){var a=o.target.result;if(a){var c=a.value;if(c.time<r)i.push(c),a.continue();else{s(i);return}}else s(i)}})}function jc(t,e){return Lc(t,e).then(function(r){return Promise.all(r.map(function(n){return Mc(t,n.id)}))})}function Bc(t,e){return e=We(e),qc(t).then(function(r){var n={closed:!1,lastCursorId:0,channelName:t,options:e,uuid:Tt(),eMIs:new rr(e.idb.ttl*2),writeBlockPromise:le,messagesCallback:null,readQueuePromises:[],db:r};return r.onclose=function(){n.closed=!0,e.idb.onclose&&e.idb.onclose()},Zi(n),n})}function Zi(t){t.closed||es(t).then(function(){return tr(t.options.idb.fallbackInterval)}).then(function(){return Zi(t)})}function Fc(t,e){return!(t.uuid===e.uuid||e.eMIs.has(t.id)||t.data.time<e.messagesCallbackTime)}function es(t){return t.closed?le:t.messagesCallback?Uc(t.db,t.lastCursorId).then(function(e){var r=e.filter(function(n){return!!n}).map(function(n){return n.id>t.lastCursorId&&(t.lastCursorId=n.id),n}).filter(function(n){return Fc(n,t)}).sort(function(n,i){return n.time-i.time});return r.forEach(function(n){t.messagesCallback&&(t.eMIs.add(n.id),t.messagesCallback(n.data))}),le}):le}function Vc(t){t.closed=!0,t.db.close()}function Hc(t,e){return t.writeBlockPromise=t.writeBlockPromise.then(function(){return Dc(t.db,t.uuid,e)}).then(function(){Ki(0,10)===0&&jc(t.db,t.options.idb.ttl)}),t.writeBlockPromise}function Gc(t,e,r){t.messagesCallbackTime=r,t.messagesCallback=e,es(t)}function Jc(){if(Se)return!1;var t=Qi();return!!t}function zc(t){return t.idb.fallbackInterval*2}var ts={create:Bc,close:Vc,onMessage:Gc,postMessage:Hc,canBeUsed:Jc,type:kc,averageResponseTime:zc,microSeconds:Ic};var $c=Ee,Wc="pubkey.broadcastChannel-",Kc="localstorage";function rs(){var t;if(typeof window=="undefined")return null;try{t=window.localStorage,t=window["ie8-eventlistener/storage"]||window.localStorage}catch{}return t}function ns(t){return Wc+t}function Xc(t,e){return new Promise(function(r){tr().then(function(){var n=ns(t.channelName),i={token:Tt(),time:new Date().getTime(),data:e,uuid:t.uuid},s=JSON.stringify(i);rs().setItem(n,s);var o=document.createEvent("Event");o.initEvent("storage",!0,!0),o.key=n,o.newValue=s,window.dispatchEvent(o),r()})})}function Yc(t,e){var r=ns(t),n=function(s){s.key===r&&e(JSON.parse(s.newValue))};return window.addEventListener("storage",n),n}function Qc(t){window.removeEventListener("storage",t)}function Zc(t,e){if(e=We(e),!is())throw new Error("BroadcastChannel: localstorage cannot be used");var r=Tt(),n=new rr(e.localstorage.removeTimeout),i={channelName:t,uuid:r,eMIs:n};return i.listener=Yc(t,function(s){!i.messagesCallback||s.uuid!==r&&(!s.token||n.has(s.token)||s.data.time&&s.data.time<i.messagesCallbackTime||(n.add(s.token),i.messagesCallback(s.data)))}),i}function ef(t){Qc(t.listener)}function tf(t,e,r){t.messagesCallbackTime=r,t.messagesCallback=e}function is(){if(Se)return!1;var t=rs();if(!t)return!1;try{var e="__broadcastchannel_check";t.setItem(e,"works"),t.removeItem(e)}catch{return!1}return!0}function rf(){var t=120,e=navigator.userAgent.toLowerCase();return e.includes("safari")&&!e.includes("chrome")?t*2:t}var ss={create:Zc,close:ef,onMessage:tf,postMessage:Xc,canBeUsed:is,type:Kc,averageResponseTime:rf,microSeconds:$c};var nf=Ee,sf="simulate",$r=new Set;function of(t){var e={name:t,messagesCallback:null};return $r.add(e),e}function af(t){$r.delete(t)}function uf(t,e){return new Promise(function(r){return setTimeout(function(){var n=Array.from($r);n.filter(function(i){return i.name===t.name}).filter(function(i){return i!==t}).filter(function(i){return!!i.messagesCallback}).forEach(function(i){return i.messagesCallback(e)}),r()},5)})}function cf(t,e){t.messagesCallback=e}function ff(){return!0}function lf(){return 5}var os={create:of,close:af,onMessage:cf,postMessage:uf,canBeUsed:ff,type:sf,averageResponseTime:lf,microSeconds:nf};var as=[Xi,ts,ss];function us(t){var e=[].concat(t.methods,as).filter(Boolean);if(t.type){if(t.type==="simulate")return os;var r=e.find(function(i){return i.type===t.type});if(r)return r;throw new Error("method-type "+t.type+" not found")}!t.webWorkerSupport&&!Se&&(e=e.filter(function(i){return i.type!=="idb"}));var n=e.find(function(i){return i.canBeUsed()});if(n)return n;throw new Error("No useable method found in "+JSON.stringify(as.map(function(i){return i.type})))}var Wr=new Set,df=0,ke=function(e,r){this.id=df++,Wr.add(this),this.name=e,cs&&(r=cs),this.options=We(r),this.method=us(this.options),this._iL=!1,this._onML=null,this._addEL={message:[],internal:[]},this._uMP=new Set,this._befC=[],this._prepP=null,hf(this)};ke._pubkey=!0;var cs;ke.prototype={postMessage:function(e){if(this.closed)throw new Error("BroadcastChannel.postMessage(): Cannot post message after channel has closed "+JSON.stringify(e));return fs(this,"message",e)},postInternal:function(e){return fs(this,"internal",e)},set onmessage(t){var e=this.method.microSeconds(),r={time:e,fn:t};ds(this,"message",this._onML),t&&typeof t=="function"?(this._onML=r,ls(this,"message",r)):this._onML=null},addEventListener:function(e,r){var n=this.method.microSeconds(),i={time:n,fn:r};ls(this,e,i)},removeEventListener:function(e,r){var n=this._addEL[e].find(function(i){return i.fn===r});ds(this,e,n)},close:function(){var e=this;if(!this.closed){Wr.delete(this),this.closed=!0;var r=this._prepP?this._prepP:le;return this._onML=null,this._addEL.message=[],r.then(function(){return Promise.all(Array.from(e._uMP))}).then(function(){return Promise.all(e._befC.map(function(n){return n()}))}).then(function(){return e.method.close(e._state)})}},get type(){return this.method.type},get isClosed(){return this.closed}};function fs(t,e,r){var n=t.method.microSeconds(),i={time:n,type:e,data:r},s=t._prepP?t._prepP:le;return s.then(function(){var o=t.method.postMessage(t._state,i);return t._uMP.add(o),o.catch().then(function(){return t._uMP.delete(o)}),o})}function hf(t){var e=t.method.create(t.name,t.options);Wi(e)?(t._prepP=e,e.then(function(r){t._state=r})):t._state=e}function hs(t){return t._addEL.message.length>0||t._addEL.internal.length>0}function ls(t,e,r){t._addEL[e].push(r),pf(t)}function ds(t,e,r){t._addEL[e]=t._addEL[e].filter(function(n){return n!==r}),mf(t)}function pf(t){if(!t._iL&&hs(t)){var e=function(i){t._addEL[i.type].forEach(function(s){var o=1e5,a=s.time-o;i.time>=a&&s.fn(i.data)})},r=t.method.microSeconds();t._prepP?t._prepP.then(function(){t._iL=!0,t.method.onMessage(t._state,e,r)}):(t._iL=!0,t.method.onMessage(t._state,e,r))}}function mf(t){if(t._iL&&!hs(t)){t._iL=!1;var e=t.method.microSeconds();t.method.onMessage(t._state,null,e)}}var nr="nhostRefreshToken",bt="nhostRefreshTokenExpiresAt";var qe={status:10,error:"invalid-email",message:"Email is incorrectly formatted"};var Rt={status:10,error:"invalid-password",message:"Password is incorrectly formatted"},ps={status:10,error:"invalid-phone-number",message:"Phone number is incorrectly formatted"},ms={status:10,error:"no-mfa-ticket",message:"No MFA ticket has been provided"};var bo=Lt(To());var ae=t=>{let e=bo.default.create({baseURL:t});return e.interceptors.response.use(r=>r,r=>{var n,i,s,o,a,c,f,u,d,l;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:(d=(u=(c=r.response)==null?void 0:c.status)!=null?u:(f=r.response)==null?void 0:f.data.statusCode)!=null?d:0,error:((l=r.response)==null?void 0:l.data.error)||r.request.statusText||"network"}})}),e};var Ro=(t,e)=>{let r=e&&Object.entries(e).map(([n,i])=>{let s=Array.isArray(i)?i.join(","):typeof i=="object"?JSON.stringify(i):i;return`${n}=${encodeURIComponent(s)}`}).join("&");return r?`${t}?${r}`:t},ie=(t,e)=>{var r;return e!=null&&e.redirectTo?{...e,redirectTo:(r=e==null?void 0:e.redirectTo)!=null&&r.startsWith("/")?t+e.redirectTo:e==null?void 0:e.redirectTo}:e};var Qe=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>=3,Ao=t=>!!t&&typeof t=="string";var mn={user:null,mfa:null,accessToken:{value:null,expiresAt:new Date},refreshTimer:{elapsed:0,attempts:0},refreshToken:{value:null},errors:{}};var Oo=({backendUrl:t,clientUrl:e,interpreter:r})=>{let n=ae(t);return oe({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:k({error:i=>qe}),saveRequestError:k({error:(i,{data:{error:s}})=>s}),reportError:$(i=>({type:"ERROR",error:i.error})),reportSuccess:$("SUCCESS")},guards:{invalidEmail:(i,{email:s})=>!Qe(s)},services:{requestChange:async(i,{email:s,options:o})=>(await n.post("/user/email/change",{newEmail:s,options:ie(e,o)},{headers:{authorization:`Bearer ${r==null?void 0:r.state.context.accessToken.value}`}})).data}})};var Co=({backendUrl:t,interpreter:e})=>{let r=ae(t);return oe({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:k({error:n=>Rt}),saveRequestError:k({error:(n,{data:{error:i}})=>(console.log(i),i)}),reportError:$(n=>({type:"ERROR",error:n.error})),reportSuccess:$("SUCCESS")},guards:{invalidPassword:(n,{password:i})=>!lr(i)},services:{requestChange:(n,{password:i})=>r.post("/user/password",{newPassword:i},{headers:{authorization:`Bearer ${e==null?void 0:e.state.context.accessToken.value}`}})}})};var Po=({backendUrl:t,clientUrl:e})=>{let r=ae(t);return oe({schema:{context:{},events:{}},tsTypes:{},preserveActionOrder:!0,id:"changePassword",initial:"idle",context:{error:null},states:{idle:{on:{REQUEST:"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:{saveRequestError:k({error:(n,{data:{error:i}})=>(console.log(i),i)}),reportError:$(n=>({type:"ERROR",error:n.error})),reportSuccess:$("SUCCESS")},services:{requestChange:(n,{email:i,options:s})=>r.post("/user/password/reset",{email:i,options:ie(e,s)})}})};var No=({backendUrl:t,clientUrl:e,interpreter:r})=>{let n=ae(t);return oe({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:k({error:i=>qe}),saveRequestError:k({error:(i,{data:{error:s}})=>s}),reportError:$(i=>({type:"ERROR",error:i.error})),reportSuccess:$("SUCCESS")},guards:{invalidEmail:(i,{email:s})=>!Qe(s)},services:{request:async(i,{email:s,options:o})=>(await n.post("/user/email/send-verification-email",{email:s,options:ie(e,o)})).data}})};var Io=({backendUrl:t,clientUrl:e,clientStorageGetter:r,clientStorageSetter:n,refreshIntervalTime:i,autoRefreshToken:s=!0,autoSignIn:o=!0})=>{let a=ae(t),c=async(f,u,d)=>(await a.post(f,u,d)).data;return oe({schema:{context:{},events:{}},tsTypes:{},context:mn,preserveActionOrder:!0,id:"nhost",type:"parallel",states:{authentication:{initial:"checkAutoSignIn",on:{SESSION_UPDATE:[{cond:"hasSession",actions:["saveSession","persist","resetTimer","reportTokenChanged"],target:".signedIn"}]},states:{checkAutoSignIn:{always:[{cond:"isAutoSignInDisabled",target:"importingRefreshToken"}],invoke:{id:"autoSignIn",src:"autoSignIn",onDone:{target:"signedIn",actions:["saveSession","persist","reportTokenChanged"]},onError:"importingRefreshToken"}},importingRefreshToken:{invoke:{id:"importRefreshToken",src:"importRefreshToken",onDone:{actions:"saveRefreshToken",target:"starting"}}},starting:{always:[{cond:"isSignedIn",target:"signedIn"},{cond:"hasRefreshTokenWithoutSession",target:["authenticating.token","#nhost.token.running"]},"signedOut"]},signedOut:{tags:["ready"],initial:"noErrors",entry:"reportSignedOut",states:{noErrors:{},success:{},needsEmailVerification:{},needsSmsOtp:{},needsMfa:{},failed:{exit:"resetAuthenticationError",initial:"server",states:{server:{},validation:{states:{password:{},email:{},phoneNumber:{}}}}},signingOut:{entry:"destroyToken",exit:"clearContext",invoke:{src:"signout",id:"signingOut",onDone:{target:"success"},onError:{target:"failed.server"}}}},on:{SIGNIN_PASSWORD:[{cond:"invalidEmail",actions:["saveInvalidEmail"],target:".failed.validation.email"},{cond:"invalidPassword",actions:["saveInvalidPassword"],target:".failed.validation.password"},"#nhost.authentication.authenticating.password"],SIGNIN_PASSWORDLESS_EMAIL:[{cond:"invalidEmail",actions:"saveInvalidEmail",target:".failed.validation.email"},"#nhost.authentication.authenticating.passwordlessEmail"],SIGNIN_PASSWORDLESS_SMS:[{cond:"invalidPhoneNumber",actions:"saveInvalidPhoneNumber",target:".failed.validation.phoneNumber"},"#nhost.authentication.authenticating.passwordlessSms"],SIGNIN_PASSWORDLESS_SMS_OTP:[{cond:"invalidPhoneNumber",actions:"saveInvalidPhoneNumber",target:".failed.validation.phoneNumber"},"#nhost.authentication.authenticating.passwordlessSmsOtp"],SIGNUP_EMAIL_PASSWORD:[{cond:"invalidEmail",actions:"saveInvalidSignUpEmail",target:".failed.validation.email"},{cond:"invalidPassword",actions:"saveInvalidSignUpPassword",target:".failed.validation.password"},"#nhost.authentication.registering"],SIGNIN_ANONYMOUS:"#nhost.authentication.authenticating.anonymous",SIGNIN_MFA_TOTP:[{cond:"noMfaTicket",actions:["saveNoMfaTicketError"],target:".failed"},"#nhost.authentication.authenticating.mfa.totp"]}},authenticating:{states:{passwordlessEmail:{invoke:{src:"signInPasswordlessEmail",id:"authenticatePasswordlessEmail",onDone:"#nhost.authentication.signedOut.needsEmailVerification",onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed.server"}}},passwordlessSms:{invoke:{src:"signInPasswordlessSms",id:"authenticatePasswordlessSms",onDone:"#nhost.authentication.signedOut.needsSmsOtp",onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed.server"}}},passwordlessSmsOtp:{invoke:{src:"signInPasswordlessSmsOtp",id:"authenticatePasswordlessSmsOtp",onDone:{actions:["saveSession","persist","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed.server"}}},password:{invoke:{src:"signInPassword",id:"authenticateUserWithPassword",onDone:[{cond:"hasMfaTicket",actions:["saveMfaTicket"],target:"#nhost.authentication.signedOut.needsMfa"},{actions:["saveSession","persist","reportTokenChanged"],target:"#nhost.authentication.signedIn"}],onError:[{cond:"unverified",target:"#nhost.authentication.signedOut.needsEmailVerification"},{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed.server"}]}},token:{},anonymous:{invoke:{src:"signInAnonymous",id:"authenticateAnonymously",onDone:{actions:["saveSession","persist","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed.server"}}},mfa:{states:{totp:{invoke:{src:"signInMfaTotp",id:"signInMfaTotp",onDone:{actions:["saveSession","persist","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:{actions:["saveAuthenticationError"],target:"#nhost.authentication.signedOut.failed.server"}}}}}}},registering:{entry:"resetSignUpError",invoke:{src:"registerUser",id:"registerUser",onDone:[{cond:"hasSession",target:"#nhost.authentication.signedIn",actions:["saveSession","persist","reportTokenChanged"]},{target:"#nhost.authentication.signedOut.needsEmailVerification"}],onError:[{cond:"unverified",target:"#nhost.authentication.signedOut.needsEmailVerification"},{actions:"saveRegisrationError",target:"#nhost.authentication.signedOut.failed.server"}]}},signedIn:{tags:["ready"],type:"parallel",entry:"reportSignedIn",on:{SIGNOUT:"#nhost.authentication.signedOut.signingOut",DEANONYMIZE:{target:".deanonymizing"}},states:{refreshTimer:{id:"timer",initial:"idle",states:{disabled:{type:"final"},stopped:{always:{cond:"noToken",target:"idle"}},idle:{always:[{cond:"isAutoRefreshDisabled",target:"disabled"},{cond:"hasRefreshToken",target:"running"}]},running:{initial:"pending",entry:"resetTimer",states:{pending:{after:{"1000":{actions:"tickRefreshTimer",internal:!1,target:"pending"}},always:{cond:"refreshTimerShouldRefresh",target:"refreshing"}},refreshing:{invoke:{src:"refreshToken",id:"refreshToken",onDone:{actions:["saveSession","persist","resetTimer"],target:"pending"},onError:[]}}}}}},deanonymizing:{initial:"error",states:{error:{},success:{}}}}}}},token:{initial:"idle",states:{idle:{on:{TRY_TOKEN:"running"},initial:"noErrors",states:{noErrors:{},error:{}}},running:{invoke:{src:"refreshToken",id:"authenticateWithToken",onDone:{actions:["saveSession","persist","reportTokenChanged"],target:["#nhost.authentication.signedIn","idle.noErrors"]},onError:[{cond:"isSignedIn",target:"idle.error"},{target:["#nhost.authentication.signedOut","idle.error"]}]}}}}}},{actions:{reportSignedIn:$("SIGNED_IN"),reportSignedOut:$("SIGNED_OUT"),reportTokenChanged:$("TOKEN_CHANGED"),clearContext:k(()=>mn),saveSession:k({user:(f,u)=>{var d,l;return(l=(d=u.data)==null?void 0:d.session)==null?void 0:l.user},accessToken:(f,u)=>{var d,l,h,g;return{value:(l=(d=u.data)==null?void 0:d.session)==null?void 0:l.accessToken,expiresAt:new Date(Date.now()+((g=(h=u.data)==null?void 0:h.session)==null?void 0:g.accessTokenExpiresIn)*1e3)}},refreshToken:(f,u)=>{var d,l;return{value:(l=(d=u.data)==null?void 0:d.session)==null?void 0:l.refreshToken}}}),saveMfaTicket:k({mfa:(f,u)=>{var d,l;return(l=(d=u.data)==null?void 0:d.mfa)!=null?l:null}}),resetTimer:k({refreshTimer:(f,u)=>({elapsed:0,attempts:0})}),tickRefreshTimer:k({refreshTimer:(f,u)=>({elapsed:f.refreshTimer.elapsed+1,attempts:f.refreshTimer.attempts})}),saveAuthenticationError:k({errors:({errors:f},{data:{error:u}})=>({...f,authentication:u})}),resetAuthenticationError:k({errors:({errors:{authentication:f,...u}})=>u}),saveInvalidEmail:k({errors:({errors:f})=>({...f,authentication:qe})}),saveInvalidPassword:k({errors:({errors:f})=>({...f,authentication:Rt})}),saveInvalidPhoneNumber:k({errors:({errors:f})=>({...f,authentication:ps})}),saveRegisrationError:k({errors:({errors:f},{data:{error:u}})=>({...f,registration:u})}),resetSignUpError:k({errors:({errors:{registration:f,...u}})=>u}),saveInvalidSignUpPassword:k({errors:({errors:f})=>({...f,registration:qe})}),saveInvalidSignUpEmail:k({errors:({errors:f})=>({...f,registration:Rt})}),saveNoMfaTicketError:k({errors:({errors:f})=>({...f,registration:ms})}),saveRefreshToken:k({accessToken:(f,u)=>({...f.accessToken,expiresAt:u.data.expiresAt}),refreshToken:(f,u)=>({...f.refreshToken,value:u.data.refreshToken})}),persist:(f,{data:u})=>{if(n(nr,u.session.refreshToken),u.session.accessTokenExpiresIn){let d=new Date(Date.now()+u.session.accessTokenExpiresIn*1e3).toISOString();n(bt,d)}else n(bt,null)},destroyToken:()=>{n(nr,null),n(bt,null)}},guards:{isSignedIn:f=>!!f.user&&!!f.refreshToken.value&&!!f.accessToken.value,hasRefreshTokenWithoutSession:f=>!!f.refreshToken.value&&!f.user&&!f.accessToken.value,noToken:f=>!f.refreshToken.value,noMfaTicket:(f,{ticket:u})=>{var d;return!u&&!((d=f.mfa)!=null&&d.ticket)},hasRefreshToken:f=>!!f.refreshToken.value,isAutoRefreshDisabled:()=>!s,isAutoSignInDisabled:()=>!o,refreshTimerShouldRefresh:f=>f.refreshTimer.elapsed>Math.max((Date.now()-f.accessToken.expiresAt.getTime())/1e3-900,i),unverified:(f,{data:{error:u}})=>u.status===401&&u.message==="Email is not verified",hasSession:(f,u)=>{var d;return!!((d=u.data)!=null&&d.session)},hasMfaTicket:(f,u)=>{var d;return!!((d=u.data)!=null&&d.mfa)},invalidEmail:(f,{email:u})=>!Qe(u),invalidPassword:(f,{password:u})=>!lr(u),invalidPhoneNumber:(f,{phoneNumber:u})=>!Ao(u)},services:{signInPassword:(f,{email:u,password:d})=>c("/signin/email-password",{email:u,password:d}),signInPasswordlessSms:(f,{phoneNumber:u,options:d})=>c("/signin/passwordless/sms",{phoneNumber:u,options:ie(e,d)}),signInPasswordlessSmsOtp:(f,{phoneNumber:u,otp:d})=>c("/signin/passwordless/sms/otp",{phoneNumber:u,otp:d}),signInPasswordlessEmail:(f,{email:u,options:d})=>c("/signin/passwordless/email",{email:u,options:ie(e,d)}),signInAnonymous:f=>c("/signin/anonymous"),signInMfaTotp:(f,{ticket:u,otp:d})=>{var l;return c("/signin/mfa/totp",{ticket:u||((l=f.mfa)==null?void 0:l.ticket),otp:d})},refreshToken:async(f,u)=>{let d=u.type==="TRY_TOKEN"?u.token:f.refreshToken.value;return{session:await c("/token",{refreshToken:d})}},signout:(f,u)=>c("/signout",{refreshToken:f.refreshToken.value,all:!!u.all}),registerUser:(f,{email:u,password:d,options:l})=>c("/signup/email-password",{email:u,password:d,options:ie(e,l)}),autoSignIn:async()=>{if(typeof window=="undefined"||!window.location)throw Error("window is undefined or location does not exist");let{hash:f}=window.location;if(!f)return;let d=new URLSearchParams(f.slice(1)).get("refreshToken");if(d){let l=await c("/token",{refreshToken:d});return new ke("nhost").postMessage(d),{session:l}}},importRefreshToken:async()=>{let f=await r(bt),u=f?new Date(f):null;return{refreshToken:await r(nr),expiresAt:u}}}})};function dr(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 dl={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 vn(t,e){function r(i,s,o){if(typeof document!="undefined"){o=dr({},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,"",dr({},s,{expires:-1}))},withAttributes:function(i){return vn(this.converter,dr({},this.attributes,i))},withConverter:function(i){return vn(dr({},this.converter,i),this.attributes)}},{attributes:{value:Object.freeze(e)},converter:{value:Object.freeze(t)}})}var Lv=vn(dl,{path:"/"});var _o=typeof window!="undefined",hr=new Map,pr=t=>{var e;return _o&&localStorage?localStorage.getItem(t):(e=hr.get(t))!=null?e:null},mr=(t,e)=>{_o&&localStorage?e?localStorage.setItem(t,e):localStorage.removeItem(t):e?hr.set(t,e):hr.has(t)&&hr.delete(t)};var Pt,Nt,It,_t=class{constructor({backendUrl:e,clientUrl:r=typeof window!="undefined"&&(f=>(f=window.location)==null?void 0:f.origin)()||"",clientStorageGetter:n=pr,clientStorageSetter:i=mr,refreshIntervalTime:s=60,autoSignIn:o=!0,autoRefreshToken:a=!0,start:c=!0}){Le(this,Pt,void 0);Le(this,Nt,void 0);Le(this,It,new Set);this.backendUrl=e,this.clientUrl=r,this.machine=Io({backendUrl:e,clientUrl:r,refreshIntervalTime:s,clientStorageGetter:n,clientStorageSetter:i,autoSignIn:o,autoRefreshToken:a}),c&&(this.interpreter=me(this.machine),this.interpreter.start()),typeof window!="undefined"&&o&&(st(this,Nt,new ke("nhost")),M(this,Nt).addEventListener("message",u=>{var l;let d=(l=this.interpreter)==null?void 0:l.state.context.refreshToken;this.interpreter&&u!==d&&this.interpreter.send({type:"TRY_TOKEN",token:u})}))}get interpreter(){return M(this,Pt)}set interpreter(e){st(this,Pt,e),e&&M(this,It).forEach(r=>r(this))}onStart(e){M(this,It).add(e)}};Pt=new WeakMap,Nt=new WeakMap,It=new WeakMap;var ko=()=>typeof window!="undefined",xe=t=>!t||!t.accessToken.value||!t.refreshToken.value?null:{accessToken:t.accessToken.value,accessTokenExpiresIn:(t.accessToken.expiresAt.getTime()-Date.now())/1e3,refreshToken:t.refreshToken.value,user:t.user},Ze=(t,e)=>{e.forEach(r=>{typeof t[r]!="function"&&console.error(`clientStorage.${r} is not a function`)})},qo=(t,e)=>{if(e){if(t==="react-native"||t==="custom")return Ze(e,["getItem"]),r=>{var n;return(n=e.getItem)==null?void 0:n.call(e,r)};if(t==="capacitor")return Ze(e,["get"]),r=>{var n;return(n=e.get)==null?void 0:n.call(e,{key:r})};if(t==="expo-secure-storage")return Ze(e,["getItemAsync"]),r=>{var n;return(n=e.getItemAsync)==null?void 0:n.call(e,r)}}return pr},Do=(t,e)=>{if(e){if(t==="react-native"||t==="custom")return Ze(e,["setItem","removeItem"]),(r,n)=>{var i,s;n?(i=e.setItem)==null||i.call(e,r,n):(s=e.removeItem)==null||s.call(e,r)};if(t==="capacitor")return Ze(e,["set","remove"]),(r,n)=>{var i,s;n?(i=e.set)==null||i.call(e,{key:r,value:n}):(s=e.remove)==null||s.call(e,{key:r})};if(t==="expo-secure-storage")return Ze(e,["setItemAsync","deleteItemAsync"]),async(r,n)=>{var i,s;n?await((i=e.setItemAsync)==null?void 0:i.call(e,r,n)):(s=e.deleteItemAsync)==null||s.call(e,r)}}return mr};var Uo={message:"User is already signed in",status:100},pl={message:"User is not authenticated",status:101},ml={message:"User is not anonymous",status:101},vl={message:"Email needs verification",status:102},j,yn=class{constructor({url:e,autoRefreshToken:r=!0,autoLogin:n=!0,clientStorage:i,clientStorageType:s="web",clientStorageGetter:o,clientStorageSetter:a,refreshIntervalTime:c,start:f=!0,Client:u=_t}){Le(this,j,void 0);this.onTokenChangedSubscriptions=new Set;this.onAuthStateChangedSubscriptions=new Set;st(this,j,new u({backendUrl:e,autoRefreshToken:r,autoSignIn:n,start:f,clientStorageGetter:o||qo(s,i),clientStorageSetter:a||Do(s,i),refreshIntervalTime:c}))}async signUp(e){let r=await this.waitUntilReady(),{email:n,password:i,options:s}=e;return this.isAuthenticated()?{session:null,error:Uo}:new Promise(o=>{r.send({type:"SIGNUP_EMAIL_PASSWORD",email:n,password:i,options:s}),r.onTransition(a=>{if(a.matches({authentication:{signedOut:"needsEmailVerification"}}))return o({session:null,error:null});if(a.matches({authentication:{signedOut:"failed"}}))return o({session:null,error:a.context.errors.registration||null});if(a.matches({authentication:"signedIn"}))return o({session:xe(a.context),error:null})})})}async signIn(e){let r=await this.waitUntilReady();if(this.isAuthenticated())return{session:null,mfa:null,error:Uo};if("provider"in e){let{provider:n,options:i}=e,s=Ro(`${M(this,j).backendUrl}/v1/auth/signin/provider/${n}`,ie(M(this,j).clientUrl,i));return ko()&&(window.location.href=s),{providerUrl:s,provider:n,session:null,mfa:null,error:null}}return"email"in e&&"password"in e?new Promise(n=>{r.send({type:"SIGNIN_PASSWORD",...e}),r.onTransition(i=>{i.matches({authentication:"signedIn"})?n({session:xe(i.context),mfa:null,error:null}):i.matches({authentication:{signedOut:"needsEmailVerification"}})?n({session:null,mfa:null,error:vl}):i.matches({authentication:{signedOut:"needsMfa"}})?n({session:null,mfa:i.context.mfa,error:null}):i.matches({authentication:{signedOut:"failed"}})&&n({session:null,mfa:null,error:i.context.errors.authentication||null})})}):"email"in e&&!("otp"in e)?new Promise(n=>{r.onTransition(i=>{i.matches({authentication:{signedOut:"needsEmailVerification"}})?n({session:null,mfa:null,error:null}):i.matches({authentication:{signedOut:"failed"}})&&n({session:null,mfa:null,error:i.context.errors.authentication||null})}),r.send({type:"SIGNIN_PASSWORDLESS_EMAIL",...e})}):"phoneNumber"in e&&!("otp"in e)?new Promise(n=>{r.onTransition(i=>{i.matches({authentication:{signedOut:"needsSmsOtp"}})?n({session:null,mfa:null,error:null}):i.matches({authentication:{signedOut:"failed"}})&&n({session:null,mfa:null,error:i.context.errors.authentication||null})}),r.send({type:"SIGNIN_PASSWORDLESS_SMS",...e})}):"otp"in e?new Promise(n=>{r.onTransition(i=>{i.matches({authentication:"signedIn"})?n({session:xe(i.context),mfa:null,error:null}):i.matches({authentication:{signedOut:"failed"}})&&n({session:null,mfa:null,error:i.context.errors.authentication||null})}),r.send({type:"SIGNIN_PASSWORDLESS_SMS_OTP",...e})}):{session:null,mfa:null,error:{message:"Incorrect parameters",status:500}}}async signOut(e){let r=await this.waitUntilReady();return this.isAuthenticated()?new Promise(n=>{r.send({type:"SIGNOUT",all:e==null?void 0:e.all}),r.onTransition(i=>{i.matches({authentication:{signedOut:"success"}})?n({error:null}):i.matches({authentication:{signedOut:"failed"}})&&n({error:i.context.errors.signout||null})})}):{error:pl}}async resetPassword({email:e,options:r}){return new Promise(n=>{let i=me(Po(M(this,j)));i.onTransition(({event:s})=>{if(s.type==="ERROR")return n({error:s.error});if(s.type==="SUCCESS")return n({error:null})}),i.start(),i.send({type:"REQUEST",email:e,options:r})})}async changePassword(e){return new Promise(r=>{let n=me(Co(M(this,j)));n.onTransition(({event:i})=>{if(i.type==="ERROR")return r({error:i.error});if(i.type==="SUCCESS")return r({error:null})}),n.start(),n.send({type:"REQUEST",password:e.newPassword})})}async sendVerificationEmail(e){return new Promise(r=>{let n=me(No(M(this,j)));n.onTransition(({event:i})=>{if(i.type==="ERROR")return r({error:i.error});if(i.type==="SUCCESS")return r({error:null})}),n.start(),n.send({type:"REQUEST",email:e.email,options:e.options})})}async changeEmail({newEmail:e,options:r}){return new Promise(n=>{let i=me(Oo(M(this,j)));i.onTransition(({event:s})=>{if(s.type==="ERROR")return n({error:s.error});if(s.type==="SUCCESS")return n({error:null})}),i.start(),i.send({type:"REQUEST",email:e,options:r})})}async deanonymize(e){let r=await this.waitUntilReady();return new Promise(n=>{var a;if(!this.isAuthenticated()||!((a=r.state.context.user)!=null&&a.isAnonymous))return{error:ml};r.onTransition(c=>{c.matches({authentication:{signedIn:{deanonymizing:"success"}}})?n({error:null}):c.matches({authentication:{signedIn:{deanonymizing:"error"}}})&&n({error:c.context.errors.authentication||null})}),r.start();let{signInMethod:i,connection:s,...o}=e;r.send({type:"DEANONYMIZE",signInMethod:i,connection:s,options:o})})}onTokenChanged(e){var r;return M(this,j).interpreter?this.onTokenChangedSubscriptions.add((r=M(this,j).interpreter)==null?void 0:r.onTransition(({event:n,context:i})=>{n.type==="TOKEN_CHANGED"&&e(xe(i))})):console.log("onTokenChanged: no interpreter is set yet",e),()=>{this.onTokenChangedSubscriptions.forEach(n=>n.stop())}}onAuthStateChanged(e){var r;return M(this,j).interpreter?this.onAuthStateChangedSubscriptions.add((r=M(this,j).interpreter)==null?void 0:r.onTransition(({event:n,context:i})=>{n.type==="SIGNED_IN"?e("SIGNED_IN",xe(i)):n.type==="SIGNED_OUT"&&e("SIGNED_OUT",xe(i))})):console.log("onAuthStateChanged: no interpreter is set yet",e),()=>{this.onAuthStateChangedSubscriptions.forEach(n=>n.stop())}}isAuthenticated(){var e;return!!((e=M(this,j).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=M(this,j).interpreter)==null?void 0:e.state.context.accessToken.value)!=null?r:void 0}async refreshSession(e){try{let r=await this.waitUntilReady();return r.state.matches({token:"idle"})?void 0:new Promise(n=>{let i=e||r.state.context.refreshToken.value;if(!i)return n();r==null||r.onTransition(s=>{(s.matches({token:{idle:"error"}})||s.event.type==="TOKEN_CHANGED")&&n()}),r.send({type:"TRY_TOKEN",token:i})})}catch{return}}getSession(){var e,r;return xe((r=(e=M(this,j).interpreter)==null?void 0:e.state)==null?void 0:r.context)}getUser(){var e,r,n;return((n=(r=(e=M(this,j).interpreter)==null?void 0:e.state)==null?void 0:r.context)==null?void 0:n.user)||null}waitUntilReady(){let r=M(this,j).interpreter;if(!r)throw Error("Auth interpreter not set");return r.state.hasTag("ready")?Promise.resolve(r):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("ready"))return clearTimeout(s),n(r)})})}isReady(){var e,r;return!!((r=(e=M(this,j).interpreter)==null?void 0:e.state)!=null&&r.hasTag("ready"))}get client(){return M(this,j)}};j=new WeakMap;var Ja=Lt(Ga()),Mn=class{constructor({url:e}){this.url=e,this.httpClient=Ja.default.create({baseURL:this.url})}async upload(e){try{return{fileMetadata:(await this.httpClient.post("/files",e.file,{headers:{...this.generateUploadHeaders(e),...this.generateAuthHeaders()}})).data,error:null}}catch(r){return{fileMetadata:null,error:r}}}async getPresignedUrl(e){try{let{fileId:r}=e;return{presignedUrl:(await this.httpClient.get(`/files/${r}/presignedurl`,{headers:{...this.generateAuthHeaders()}})).data,error:null}}catch(r){return{presignedUrl:null,error:r}}}async delete(e){try{let{fileId:r}=e;return await this.httpClient.delete(`/files/${r}`,{headers:{...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){let{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}`}}};var Ln=class{constructor({url:e}){this.url=e,this.api=new Mn({url:e})}async upload(e){let r=new FormData;r.append("file",e.file);let{fileMetadata:n,error:i}=await this.api.upload({...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){let{fileId:r}=e;return`${this.url}/files/${r}`}async getPresignedUrl(e){let{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){let{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}};var Yu=Lt(ii()),si=class{constructor(e){let{url:r}=e;this.accessToken=null,this.instance=Yu.default.create({baseURL:r})}async call(e,r,n){let i={...this.generateAccessTokenHeaders(),...n==null?void 0:n.headers},s;try{s=await this.instance.post(e,r,{...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(){if(!!this.accessToken)return{Authorization:`Bearer ${this.accessToken}`}}};var Qu=Lt(ii()),oi=class{constructor(e){let{url:r}=e;this.url=r,this.accessToken=null,this.instance=Qu.default.create({baseURL:r})}async request(e,r,n){let i={...n==null?void 0:n.headers,...this.generateAccessTokenHeaders()},s="",o;try{o=(await this.instance.post("",{operationName:s||void 0,query:e,variables:r},{...n,headers:i})).data}catch(a){return a instanceof Error?{data:null,error:a}:(console.error(a),{data:null,error:new Error("Unable to get do GraphQL request")})}return typeof o!="object"||Array.isArray(o)||o===null?{data:null,error:new Error("incorrect response data from GraphQL server")}:(o=o,o.errors?{data:null,error:o.errors}:{data:o.data,error:null})}getUrl(){return this.url}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){if(!!this.accessToken)return{Authorization:`Bearer ${this.accessToken}`}}};var ai=class{constructor({backendUrl:e,refreshIntervalTime:r,clientStorageGetter:n,clientStorageSetter:i,clientStorage:s,clientStorageType:o,autoRefreshToken:a,autoLogin:c,start:f=!0,Client:u}){if(!e)throw new Error("Please specify a `backendUrl`. Docs: [todo]!");this.auth=new yn({url:`${e}/v1/auth`,refreshIntervalTime:r,clientStorageGetter:n,clientStorageSetter:i,clientStorage:s,clientStorageType:o,autoRefreshToken:a,autoLogin:c,start:f,Client:u}),this.storage=new Ln({url:`${e}/v1/storage`}),this.functions=new si({url:`${e}/v1/functions`}),this.graphql=new oi({url:`${e}/v1/graphql`}),this.storage.setAccessToken(this.auth.getAccessToken()),this.functions.setAccessToken(this.auth.getAccessToken()),this.graphql.setAccessToken(this.auth.getAccessToken()),this.auth.client.onStart(()=>{this.auth.onAuthStateChanged((d,l)=>{this.storage.setAccessToken(l==null?void 0:l.accessToken),this.functions.setAccessToken(l==null?void 0:l.accessToken),this.graphql.setAccessToken(l==null?void 0:l.accessToken)}),this.auth.onTokenChanged(d=>{this.storage.setAccessToken(d==null?void 0:d.accessToken),this.functions.setAccessToken(d==null?void 0:d.accessToken),this.graphql.setAccessToken(d==null?void 0:d.accessToken)})})}};var Zg=t=>new ai(t);export{ai as NhostClient,Zg as createClient};
|
|
9
|
+
`).concat(a.message))}else return r.getStateNodeByPath(s)})},t.prototype.formatTransition=function(e){var r=this,n=Ti(e.target),i="internal"in e?e.internal:n?n.some(function(c){return A(c)&&c[0]===r.delimiter}):!0,s=this.machine.options.guards,o=this.resolveTarget(n),a=v(v({},e),{actions:mt(te(e.actions)),cond:Wt(e.cond,s),target:o,source:this,internal:i,eventType:e.event,toJSON:function(){return v(v({},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=xt,a=s[o],c=a===void 0?[]:a,f=je(s,[typeof o=="symbol"?o:o+""]);i=q(Object.keys(f).map(function(y){!D&&y===$e&&L(!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 x=Re(y,f[y]);return D||Sc(n,y,x),x}).concat(Re(xt,c)))}var u=this.config.always?Re("",this.config.always):[],d=this.config.onDone?Re(String(yt(this.id)),this.config.onDone):[];D||L(!(this.config.onDone&&!this.parent),'Root nodes cannot have an ".onDone" transition. Please check the config of "'.concat(this.id,'".'));var l=q(this.invoke.map(function(y){var x=[];return y.onDone&&x.push.apply(x,_([],R(Re(String(Oe(y.id)),y.onDone)),!1)),y.onError&&x.push.apply(x,_([],R(Re(String(Ce(y.id)),y.onError)),!1)),x})),h=this.after,g=q(_(_(_(_([],R(d),!1),R(l),!1),R(i),!1),R(u),!1).map(function(y){return te(y).map(function(x){return n.formatTransition(x)})}));try{for(var E=b(h),p=E.next();!p.done;p=E.next()){var w=p.value;g.push(w)}}catch(y){e={error:y}}finally{try{p&&!p.done&&(r=E.return)&&r.call(E)}finally{if(e)throw e.error}}return g},t}();function oe(t,e){return new zi(t,e)}var k=Pi,$=vt;function Wi(t){return!!(t&&typeof t.then=="function")}var wc=Promise.resolve(!1),qp=Promise.resolve(!0),le=Promise.resolve();function tr(t,e){return t||(t=0),new Promise(function(r){return setTimeout(function(){return r(e)},t)})}function Ki(t,e){return Math.floor(Math.random()*(e-t+1)+t)}function Tt(){return Math.random().toString(36).substring(2)}var $i=0,zr=0;function Ee(){var t=new Date().getTime();return t===$i?(zr++,t*1e3+zr):($i=t,zr=0,t*1e3)}var Se=Object.prototype.toString.call(typeof process!="undefined"?process:0)==="[object process]";var xc=Ee,Tc="native";function bc(t){var e={messagesCallback:null,bc:new BroadcastChannel(t),subFns:[]};return e.bc.onmessage=function(r){e.messagesCallback&&e.messagesCallback(r.data)},e}function Rc(t){t.bc.close(),t.subFns=[]}function Ac(t,e){try{return t.bc.postMessage(e,!1),le}catch(r){return Promise.reject(r)}}function Oc(t,e){t.messagesCallback=e}function Cc(){if(Se&&typeof window=="undefined")return!1;if(typeof BroadcastChannel=="function"){if(BroadcastChannel._pubkey)throw new Error("BroadcastChannel: Do not overwrite window.BroadcastChannel with this module, this is not a polyfill");return!0}else return!1}function Pc(){return 150}var Xi={create:bc,close:Rc,onMessage:Oc,postMessage:Ac,canBeUsed:Cc,type:Tc,averageResponseTime:Pc,microSeconds:xc};var rr=function(){function t(e){this.ttl=e,this.set=new Set,this.timeMap=new Map}return t.prototype.has=function(e){return this.set.has(e)},t.prototype.add=function(e){var r=this;this.timeMap.set(e,Yi()),this.set.add(e),setTimeout(function(){Nc(r)},0)},t.prototype.clear=function(){this.set.clear(),this.timeMap.clear()},t}();function Nc(t){for(var e=Yi()-t.ttl,r=t.set[Symbol.iterator]();;){var n=r.next().value;if(!n)return;var i=t.timeMap.get(n);if(i<e)t.timeMap.delete(n),t.set.delete(n);else return}}function Yi(){return new Date().getTime()}function We(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=JSON.parse(JSON.stringify(t));return typeof e.webWorkerSupport=="undefined"&&(e.webWorkerSupport=!0),e.idb||(e.idb={}),e.idb.ttl||(e.idb.ttl=1e3*45),e.idb.fallbackInterval||(e.idb.fallbackInterval=150),t.idb&&typeof t.idb.onclose=="function"&&(e.idb.onclose=t.idb.onclose),e.localstorage||(e.localstorage={}),e.localstorage.removeTimeout||(e.localstorage.removeTimeout=1e3*60),t.methods&&(e.methods=t.methods),e.node||(e.node={}),e.node.ttl||(e.node.ttl=1e3*60*2),e.node.maxParallelWrites||(e.node.maxParallelWrites=2048),typeof e.node.useFastPath=="undefined"&&(e.node.useFastPath=!0),e}var Ic=Ee,_c="pubkey.broadcast-channel-0-",ve="messages",kc="idb";function Qi(){if(typeof indexedDB!="undefined")return indexedDB;if(typeof window!="undefined"){if(typeof window.mozIndexedDB!="undefined")return window.mozIndexedDB;if(typeof window.webkitIndexedDB!="undefined")return window.webkitIndexedDB;if(typeof window.msIndexedDB!="undefined")return window.msIndexedDB}return!1}function qc(t){var e=Qi(),r=_c+t,n=e.open(r,1);n.onupgradeneeded=function(s){var o=s.target.result;o.createObjectStore(ve,{keyPath:"id",autoIncrement:!0})};var i=new Promise(function(s,o){n.onerror=function(a){return o(a)},n.onsuccess=function(){s(n.result)}});return i}function Dc(t,e,r){var n=new Date().getTime(),i={uuid:e,time:n,data:r},s=t.transaction([ve],"readwrite");return new Promise(function(o,a){s.oncomplete=function(){return o()},s.onerror=function(f){return a(f)};var c=s.objectStore(ve);c.add(i)})}function Uc(t,e){var r=t.transaction(ve).objectStore(ve),n=[];function i(){try{var s=IDBKeyRange.bound(e+1,1/0);return r.openCursor(s)}catch{return r.openCursor()}}return new Promise(function(s){i().onsuccess=function(o){var a=o.target.result;a?a.value.id<e+1?a.continue(e+1):(n.push(a.value),a.continue()):s(n)}})}function Mc(t,e){var r=t.transaction([ve],"readwrite").objectStore(ve).delete(e);return new Promise(function(n){r.onsuccess=function(){return n()}})}function Lc(t,e){var r=new Date().getTime()-e,n=t.transaction(ve).objectStore(ve),i=[];return new Promise(function(s){n.openCursor().onsuccess=function(o){var a=o.target.result;if(a){var c=a.value;if(c.time<r)i.push(c),a.continue();else{s(i);return}}else s(i)}})}function jc(t,e){return Lc(t,e).then(function(r){return Promise.all(r.map(function(n){return Mc(t,n.id)}))})}function Bc(t,e){return e=We(e),qc(t).then(function(r){var n={closed:!1,lastCursorId:0,channelName:t,options:e,uuid:Tt(),eMIs:new rr(e.idb.ttl*2),writeBlockPromise:le,messagesCallback:null,readQueuePromises:[],db:r};return r.onclose=function(){n.closed=!0,e.idb.onclose&&e.idb.onclose()},Zi(n),n})}function Zi(t){t.closed||es(t).then(function(){return tr(t.options.idb.fallbackInterval)}).then(function(){return Zi(t)})}function Fc(t,e){return!(t.uuid===e.uuid||e.eMIs.has(t.id)||t.data.time<e.messagesCallbackTime)}function es(t){return t.closed?le:t.messagesCallback?Uc(t.db,t.lastCursorId).then(function(e){var r=e.filter(function(n){return!!n}).map(function(n){return n.id>t.lastCursorId&&(t.lastCursorId=n.id),n}).filter(function(n){return Fc(n,t)}).sort(function(n,i){return n.time-i.time});return r.forEach(function(n){t.messagesCallback&&(t.eMIs.add(n.id),t.messagesCallback(n.data))}),le}):le}function Vc(t){t.closed=!0,t.db.close()}function Hc(t,e){return t.writeBlockPromise=t.writeBlockPromise.then(function(){return Dc(t.db,t.uuid,e)}).then(function(){Ki(0,10)===0&&jc(t.db,t.options.idb.ttl)}),t.writeBlockPromise}function Gc(t,e,r){t.messagesCallbackTime=r,t.messagesCallback=e,es(t)}function Jc(){if(Se)return!1;var t=Qi();return!!t}function zc(t){return t.idb.fallbackInterval*2}var ts={create:Bc,close:Vc,onMessage:Gc,postMessage:Hc,canBeUsed:Jc,type:kc,averageResponseTime:zc,microSeconds:Ic};var $c=Ee,Wc="pubkey.broadcastChannel-",Kc="localstorage";function rs(){var t;if(typeof window=="undefined")return null;try{t=window.localStorage,t=window["ie8-eventlistener/storage"]||window.localStorage}catch{}return t}function ns(t){return Wc+t}function Xc(t,e){return new Promise(function(r){tr().then(function(){var n=ns(t.channelName),i={token:Tt(),time:new Date().getTime(),data:e,uuid:t.uuid},s=JSON.stringify(i);rs().setItem(n,s);var o=document.createEvent("Event");o.initEvent("storage",!0,!0),o.key=n,o.newValue=s,window.dispatchEvent(o),r()})})}function Yc(t,e){var r=ns(t),n=function(s){s.key===r&&e(JSON.parse(s.newValue))};return window.addEventListener("storage",n),n}function Qc(t){window.removeEventListener("storage",t)}function Zc(t,e){if(e=We(e),!is())throw new Error("BroadcastChannel: localstorage cannot be used");var r=Tt(),n=new rr(e.localstorage.removeTimeout),i={channelName:t,uuid:r,eMIs:n};return i.listener=Yc(t,function(s){!i.messagesCallback||s.uuid!==r&&(!s.token||n.has(s.token)||s.data.time&&s.data.time<i.messagesCallbackTime||(n.add(s.token),i.messagesCallback(s.data)))}),i}function ef(t){Qc(t.listener)}function tf(t,e,r){t.messagesCallbackTime=r,t.messagesCallback=e}function is(){if(Se)return!1;var t=rs();if(!t)return!1;try{var e="__broadcastchannel_check";t.setItem(e,"works"),t.removeItem(e)}catch{return!1}return!0}function rf(){var t=120,e=navigator.userAgent.toLowerCase();return e.includes("safari")&&!e.includes("chrome")?t*2:t}var ss={create:Zc,close:ef,onMessage:tf,postMessage:Xc,canBeUsed:is,type:Kc,averageResponseTime:rf,microSeconds:$c};var nf=Ee,sf="simulate",$r=new Set;function of(t){var e={name:t,messagesCallback:null};return $r.add(e),e}function af(t){$r.delete(t)}function uf(t,e){return new Promise(function(r){return setTimeout(function(){var n=Array.from($r);n.filter(function(i){return i.name===t.name}).filter(function(i){return i!==t}).filter(function(i){return!!i.messagesCallback}).forEach(function(i){return i.messagesCallback(e)}),r()},5)})}function cf(t,e){t.messagesCallback=e}function ff(){return!0}function lf(){return 5}var os={create:of,close:af,onMessage:cf,postMessage:uf,canBeUsed:ff,type:sf,averageResponseTime:lf,microSeconds:nf};var as=[Xi,ts,ss];function us(t){var e=[].concat(t.methods,as).filter(Boolean);if(t.type){if(t.type==="simulate")return os;var r=e.find(function(i){return i.type===t.type});if(r)return r;throw new Error("method-type "+t.type+" not found")}!t.webWorkerSupport&&!Se&&(e=e.filter(function(i){return i.type!=="idb"}));var n=e.find(function(i){return i.canBeUsed()});if(n)return n;throw new Error("No useable method found in "+JSON.stringify(as.map(function(i){return i.type})))}var Wr=new Set,df=0,ke=function(e,r){this.id=df++,Wr.add(this),this.name=e,cs&&(r=cs),this.options=We(r),this.method=us(this.options),this._iL=!1,this._onML=null,this._addEL={message:[],internal:[]},this._uMP=new Set,this._befC=[],this._prepP=null,hf(this)};ke._pubkey=!0;var cs;ke.prototype={postMessage:function(e){if(this.closed)throw new Error("BroadcastChannel.postMessage(): Cannot post message after channel has closed "+JSON.stringify(e));return fs(this,"message",e)},postInternal:function(e){return fs(this,"internal",e)},set onmessage(t){var e=this.method.microSeconds(),r={time:e,fn:t};ds(this,"message",this._onML),t&&typeof t=="function"?(this._onML=r,ls(this,"message",r)):this._onML=null},addEventListener:function(e,r){var n=this.method.microSeconds(),i={time:n,fn:r};ls(this,e,i)},removeEventListener:function(e,r){var n=this._addEL[e].find(function(i){return i.fn===r});ds(this,e,n)},close:function(){var e=this;if(!this.closed){Wr.delete(this),this.closed=!0;var r=this._prepP?this._prepP:le;return this._onML=null,this._addEL.message=[],r.then(function(){return Promise.all(Array.from(e._uMP))}).then(function(){return Promise.all(e._befC.map(function(n){return n()}))}).then(function(){return e.method.close(e._state)})}},get type(){return this.method.type},get isClosed(){return this.closed}};function fs(t,e,r){var n=t.method.microSeconds(),i={time:n,type:e,data:r},s=t._prepP?t._prepP:le;return s.then(function(){var o=t.method.postMessage(t._state,i);return t._uMP.add(o),o.catch().then(function(){return t._uMP.delete(o)}),o})}function hf(t){var e=t.method.create(t.name,t.options);Wi(e)?(t._prepP=e,e.then(function(r){t._state=r})):t._state=e}function hs(t){return t._addEL.message.length>0||t._addEL.internal.length>0}function ls(t,e,r){t._addEL[e].push(r),pf(t)}function ds(t,e,r){t._addEL[e]=t._addEL[e].filter(function(n){return n!==r}),mf(t)}function pf(t){if(!t._iL&&hs(t)){var e=function(i){t._addEL[i.type].forEach(function(s){var o=1e5,a=s.time-o;i.time>=a&&s.fn(i.data)})},r=t.method.microSeconds();t._prepP?t._prepP.then(function(){t._iL=!0,t.method.onMessage(t._state,e,r)}):(t._iL=!0,t.method.onMessage(t._state,e,r))}}function mf(t){if(t._iL&&!hs(t)){t._iL=!1;var e=t.method.microSeconds();t.method.onMessage(t._state,null,e)}}var nr="nhostRefreshToken",bt="nhostRefreshTokenExpiresAt";var qe={status:10,error:"invalid-email",message:"Email is incorrectly formatted"};var Rt={status:10,error:"invalid-password",message:"Password is incorrectly formatted"},ps={status:10,error:"invalid-phone-number",message:"Phone number is incorrectly formatted"},ms={status:10,error:"no-mfa-ticket",message:"No MFA ticket has been provided"};var bo=Lt(To());var ae=t=>{let e=bo.default.create({baseURL:t});return e.interceptors.response.use(r=>r,r=>{var n,i,s,o,a,c,f,u,d,l;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:(d=(u=(c=r.response)==null?void 0:c.status)!=null?u:(f=r.response)==null?void 0:f.data.statusCode)!=null?d:0,error:((l=r.response)==null?void 0:l.data.error)||r.request.statusText||"network"}})}),e};var Ro=(t,e)=>{let r=e&&Object.entries(e).map(([n,i])=>{let s=Array.isArray(i)?i.join(","):typeof i=="object"?JSON.stringify(i):i;return`${n}=${encodeURIComponent(s)}`}).join("&");return r?`${t}?${r}`:t},ie=(t,e)=>{var r;return e!=null&&e.redirectTo?{...e,redirectTo:(r=e==null?void 0:e.redirectTo)!=null&&r.startsWith("/")?t+e.redirectTo:e==null?void 0:e.redirectTo}:e};var Qe=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>=3,Ao=t=>!!t&&typeof t=="string";var mn={user:null,mfa:null,accessToken:{value:null,expiresAt:new Date},refreshTimer:{elapsed:0,attempts:0},refreshToken:{value:null},errors:{}};var Oo=({backendUrl:t,clientUrl:e,interpreter:r})=>{let n=ae(t);return oe({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:k({error:i=>qe}),saveRequestError:k({error:(i,{data:{error:s}})=>s}),reportError:$(i=>({type:"ERROR",error:i.error})),reportSuccess:$("SUCCESS")},guards:{invalidEmail:(i,{email:s})=>!Qe(s)},services:{requestChange:async(i,{email:s,options:o})=>(await n.post("/user/email/change",{newEmail:s,options:ie(e,o)},{headers:{authorization:`Bearer ${r==null?void 0:r.state.context.accessToken.value}`}})).data}})};var Co=({backendUrl:t,interpreter:e})=>{let r=ae(t);return oe({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:k({error:n=>Rt}),saveRequestError:k({error:(n,{data:{error:i}})=>(console.log(i),i)}),reportError:$(n=>({type:"ERROR",error:n.error})),reportSuccess:$("SUCCESS")},guards:{invalidPassword:(n,{password:i})=>!lr(i)},services:{requestChange:(n,{password:i})=>r.post("/user/password",{newPassword:i},{headers:{authorization:`Bearer ${e==null?void 0:e.state.context.accessToken.value}`}})}})};var Po=({backendUrl:t,clientUrl:e})=>{let r=ae(t);return oe({schema:{context:{},events:{}},tsTypes:{},preserveActionOrder:!0,id:"changePassword",initial:"idle",context:{error:null},states:{idle:{on:{REQUEST:"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:{saveRequestError:k({error:(n,{data:{error:i}})=>(console.log(i),i)}),reportError:$(n=>({type:"ERROR",error:n.error})),reportSuccess:$("SUCCESS")},services:{requestChange:(n,{email:i,options:s})=>r.post("/user/password/reset",{email:i,options:ie(e,s)})}})};var No=({backendUrl:t,clientUrl:e,interpreter:r})=>{let n=ae(t);return oe({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:k({error:i=>qe}),saveRequestError:k({error:(i,{data:{error:s}})=>s}),reportError:$(i=>({type:"ERROR",error:i.error})),reportSuccess:$("SUCCESS")},guards:{invalidEmail:(i,{email:s})=>!Qe(s)},services:{request:async(i,{email:s,options:o})=>(await n.post("/user/email/send-verification-email",{email:s,options:ie(e,o)})).data}})};var Io=({backendUrl:t,clientUrl:e,clientStorageGetter:r,clientStorageSetter:n,refreshIntervalTime:i,autoRefreshToken:s=!0,autoSignIn:o=!0})=>{let a=ae(t),c=async(f,u,d)=>(await a.post(f,u,d)).data;return oe({schema:{context:{},events:{}},tsTypes:{},context:mn,preserveActionOrder:!0,id:"nhost",type:"parallel",states:{authentication:{initial:"checkAutoSignIn",on:{SESSION_UPDATE:[{cond:"hasSession",actions:["saveSession","persist","resetTimer","reportTokenChanged"],target:".signedIn"}]},states:{checkAutoSignIn:{always:[{cond:"isAutoSignInDisabled",target:"importingRefreshToken"}],invoke:{id:"autoSignIn",src:"autoSignIn",onDone:{target:"signedIn",actions:["saveSession","persist","reportTokenChanged"]},onError:"importingRefreshToken"}},importingRefreshToken:{invoke:{id:"importRefreshToken",src:"importRefreshToken",onDone:{actions:"saveRefreshToken",target:"starting"}}},starting:{always:[{cond:"isSignedIn",target:"signedIn"},{cond:"hasRefreshTokenWithoutSession",target:["authenticating.token","#nhost.token.running"]},"signedOut"]},signedOut:{tags:["ready"],initial:"noErrors",entry:"reportSignedOut",states:{noErrors:{},success:{},needsEmailVerification:{},needsSmsOtp:{},needsMfa:{},failed:{exit:"resetAuthenticationError",initial:"server",states:{server:{},validation:{states:{password:{},email:{},phoneNumber:{}}}}},signingOut:{entry:"destroyToken",exit:"clearContext",invoke:{src:"signout",id:"signingOut",onDone:{target:"success"},onError:{target:"failed.server"}}}},on:{SIGNIN_PASSWORD:[{cond:"invalidEmail",actions:["saveInvalidEmail"],target:".failed.validation.email"},{cond:"invalidPassword",actions:["saveInvalidPassword"],target:".failed.validation.password"},"#nhost.authentication.authenticating.password"],SIGNIN_PASSWORDLESS_EMAIL:[{cond:"invalidEmail",actions:"saveInvalidEmail",target:".failed.validation.email"},"#nhost.authentication.authenticating.passwordlessEmail"],SIGNIN_PASSWORDLESS_SMS:[{cond:"invalidPhoneNumber",actions:"saveInvalidPhoneNumber",target:".failed.validation.phoneNumber"},"#nhost.authentication.authenticating.passwordlessSms"],SIGNIN_PASSWORDLESS_SMS_OTP:[{cond:"invalidPhoneNumber",actions:"saveInvalidPhoneNumber",target:".failed.validation.phoneNumber"},"#nhost.authentication.authenticating.passwordlessSmsOtp"],SIGNUP_EMAIL_PASSWORD:[{cond:"invalidEmail",actions:"saveInvalidSignUpEmail",target:".failed.validation.email"},{cond:"invalidPassword",actions:"saveInvalidSignUpPassword",target:".failed.validation.password"},"#nhost.authentication.registering"],SIGNIN_ANONYMOUS:"#nhost.authentication.authenticating.anonymous",SIGNIN_MFA_TOTP:[{cond:"noMfaTicket",actions:["saveNoMfaTicketError"],target:".failed"},"#nhost.authentication.authenticating.mfa.totp"]}},authenticating:{states:{passwordlessEmail:{invoke:{src:"signInPasswordlessEmail",id:"authenticatePasswordlessEmail",onDone:"#nhost.authentication.signedOut.needsEmailVerification",onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed.server"}}},passwordlessSms:{invoke:{src:"signInPasswordlessSms",id:"authenticatePasswordlessSms",onDone:"#nhost.authentication.signedOut.needsSmsOtp",onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed.server"}}},passwordlessSmsOtp:{invoke:{src:"signInPasswordlessSmsOtp",id:"authenticatePasswordlessSmsOtp",onDone:{actions:["saveSession","persist","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed.server"}}},password:{invoke:{src:"signInPassword",id:"authenticateUserWithPassword",onDone:[{cond:"hasMfaTicket",actions:["saveMfaTicket"],target:"#nhost.authentication.signedOut.needsMfa"},{actions:["saveSession","persist","reportTokenChanged"],target:"#nhost.authentication.signedIn"}],onError:[{cond:"unverified",target:"#nhost.authentication.signedOut.needsEmailVerification"},{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed.server"}]}},token:{},anonymous:{invoke:{src:"signInAnonymous",id:"authenticateAnonymously",onDone:{actions:["saveSession","persist","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed.server"}}},mfa:{states:{totp:{invoke:{src:"signInMfaTotp",id:"signInMfaTotp",onDone:{actions:["saveSession","persist","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:{actions:["saveAuthenticationError"],target:"#nhost.authentication.signedOut.failed.server"}}}}}}},registering:{entry:"resetSignUpError",invoke:{src:"registerUser",id:"registerUser",onDone:[{cond:"hasSession",target:"#nhost.authentication.signedIn",actions:["saveSession","persist","reportTokenChanged"]},{target:"#nhost.authentication.signedOut.needsEmailVerification"}],onError:[{cond:"unverified",target:"#nhost.authentication.signedOut.needsEmailVerification"},{actions:"saveRegisrationError",target:"#nhost.authentication.signedOut.failed.server"}]}},signedIn:{tags:["ready"],type:"parallel",entry:"reportSignedIn",on:{SIGNOUT:"#nhost.authentication.signedOut.signingOut",DEANONYMIZE:{target:".deanonymizing"}},states:{refreshTimer:{id:"timer",initial:"idle",states:{disabled:{type:"final"},stopped:{always:{cond:"noToken",target:"idle"}},idle:{always:[{cond:"isAutoRefreshDisabled",target:"disabled"},{cond:"hasRefreshToken",target:"running"}]},running:{initial:"pending",entry:"resetTimer",states:{pending:{after:{"1000":{actions:"tickRefreshTimer",internal:!1,target:"pending"}},always:{cond:"refreshTimerShouldRefresh",target:"refreshing"}},refreshing:{invoke:{src:"refreshToken",id:"refreshToken",onDone:{actions:["saveSession","persist","resetTimer"],target:"pending"},onError:[]}}}}}},deanonymizing:{initial:"error",states:{error:{},success:{}}}}}}},token:{initial:"idle",states:{idle:{on:{TRY_TOKEN:"running"},initial:"noErrors",states:{noErrors:{},error:{}}},running:{invoke:{src:"refreshToken",id:"authenticateWithToken",onDone:{actions:["saveSession","persist","reportTokenChanged"],target:["#nhost.authentication.signedIn","idle.noErrors"]},onError:[{cond:"isSignedIn",target:"idle.error"},{target:["#nhost.authentication.signedOut","idle.error"]}]}}}}}},{actions:{reportSignedIn:$("SIGNED_IN"),reportSignedOut:$("SIGNED_OUT"),reportTokenChanged:$("TOKEN_CHANGED"),clearContext:k(()=>mn),saveSession:k({user:(f,u)=>{var d,l;return(l=(d=u.data)==null?void 0:d.session)==null?void 0:l.user},accessToken:(f,u)=>{var d,l,h,g;return{value:(l=(d=u.data)==null?void 0:d.session)==null?void 0:l.accessToken,expiresAt:new Date(Date.now()+((g=(h=u.data)==null?void 0:h.session)==null?void 0:g.accessTokenExpiresIn)*1e3)}},refreshToken:(f,u)=>{var d,l;return{value:(l=(d=u.data)==null?void 0:d.session)==null?void 0:l.refreshToken}}}),saveMfaTicket:k({mfa:(f,u)=>{var d,l;return(l=(d=u.data)==null?void 0:d.mfa)!=null?l:null}}),resetTimer:k({refreshTimer:(f,u)=>({elapsed:0,attempts:0})}),tickRefreshTimer:k({refreshTimer:(f,u)=>({elapsed:f.refreshTimer.elapsed+1,attempts:f.refreshTimer.attempts})}),saveAuthenticationError:k({errors:({errors:f},{data:{error:u}})=>({...f,authentication:u})}),resetAuthenticationError:k({errors:({errors:{authentication:f,...u}})=>u}),saveInvalidEmail:k({errors:({errors:f})=>({...f,authentication:qe})}),saveInvalidPassword:k({errors:({errors:f})=>({...f,authentication:Rt})}),saveInvalidPhoneNumber:k({errors:({errors:f})=>({...f,authentication:ps})}),saveRegisrationError:k({errors:({errors:f},{data:{error:u}})=>({...f,registration:u})}),resetSignUpError:k({errors:({errors:{registration:f,...u}})=>u}),saveInvalidSignUpPassword:k({errors:({errors:f})=>({...f,registration:qe})}),saveInvalidSignUpEmail:k({errors:({errors:f})=>({...f,registration:Rt})}),saveNoMfaTicketError:k({errors:({errors:f})=>({...f,registration:ms})}),saveRefreshToken:k({accessToken:(f,u)=>({...f.accessToken,expiresAt:u.data.expiresAt}),refreshToken:(f,u)=>({...f.refreshToken,value:u.data.refreshToken})}),persist:(f,{data:u})=>{if(n(nr,u.session.refreshToken),u.session.accessTokenExpiresIn){let d=new Date(Date.now()+u.session.accessTokenExpiresIn*1e3).toISOString();n(bt,d)}else n(bt,null)},destroyToken:()=>{n(nr,null),n(bt,null)}},guards:{isSignedIn:f=>!!f.user&&!!f.refreshToken.value&&!!f.accessToken.value,hasRefreshTokenWithoutSession:f=>!!f.refreshToken.value&&!f.user&&!f.accessToken.value,noToken:f=>!f.refreshToken.value,noMfaTicket:(f,{ticket:u})=>{var d;return!u&&!((d=f.mfa)!=null&&d.ticket)},hasRefreshToken:f=>!!f.refreshToken.value,isAutoRefreshDisabled:()=>!s,isAutoSignInDisabled:()=>!o,refreshTimerShouldRefresh:f=>f.refreshTimer.elapsed>Math.max((Date.now()-f.accessToken.expiresAt.getTime())/1e3-900,i),unverified:(f,{data:{error:u}})=>u.status===401&&u.message==="Email is not verified",hasSession:(f,u)=>{var d;return!!((d=u.data)!=null&&d.session)},hasMfaTicket:(f,u)=>{var d;return!!((d=u.data)!=null&&d.mfa)},invalidEmail:(f,{email:u})=>!Qe(u),invalidPassword:(f,{password:u})=>!lr(u),invalidPhoneNumber:(f,{phoneNumber:u})=>!Ao(u)},services:{signInPassword:(f,{email:u,password:d})=>c("/signin/email-password",{email:u,password:d}),signInPasswordlessSms:(f,{phoneNumber:u,options:d})=>c("/signin/passwordless/sms",{phoneNumber:u,options:ie(e,d)}),signInPasswordlessSmsOtp:(f,{phoneNumber:u,otp:d})=>c("/signin/passwordless/sms/otp",{phoneNumber:u,otp:d}),signInPasswordlessEmail:(f,{email:u,options:d})=>c("/signin/passwordless/email",{email:u,options:ie(e,d)}),signInAnonymous:f=>c("/signin/anonymous"),signInMfaTotp:(f,{ticket:u,otp:d})=>{var l;return c("/signin/mfa/totp",{ticket:u||((l=f.mfa)==null?void 0:l.ticket),otp:d})},refreshToken:async(f,u)=>{let d=u.type==="TRY_TOKEN"?u.token:f.refreshToken.value;return{session:await c("/token",{refreshToken:d})}},signout:(f,u)=>c("/signout",{refreshToken:f.refreshToken.value,all:!!u.all}),registerUser:(f,{email:u,password:d,options:l})=>c("/signup/email-password",{email:u,password:d,options:ie(e,l)}),autoSignIn:async()=>{if(typeof window=="undefined"||!window.location)throw Error("window is undefined or location does not exist");let{hash:f}=window.location;if(!f)throw Error("No hash in window.location");let d=new URLSearchParams(f.slice(1)).get("refreshToken");if(!d)throw Error("No refresh token in the location hash");let l=await c("/token",{refreshToken:d});return new ke("nhost").postMessage(d),{session:l}},importRefreshToken:async()=>{let f=await r(bt),u=f?new Date(f):null;return{refreshToken:await r(nr),expiresAt:u}}}})};function dr(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 dl={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 vn(t,e){function r(i,s,o){if(typeof document!="undefined"){o=dr({},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,"",dr({},s,{expires:-1}))},withAttributes:function(i){return vn(this.converter,dr({},this.attributes,i))},withConverter:function(i){return vn(dr({},this.converter,i),this.attributes)}},{attributes:{value:Object.freeze(e)},converter:{value:Object.freeze(t)}})}var Lv=vn(dl,{path:"/"});var _o=typeof window!="undefined",hr=new Map,pr=t=>{var e;return _o&&localStorage?localStorage.getItem(t):(e=hr.get(t))!=null?e:null},mr=(t,e)=>{_o&&localStorage?e?localStorage.setItem(t,e):localStorage.removeItem(t):e?hr.set(t,e):hr.has(t)&&hr.delete(t)};var Pt,Nt,It,_t=class{constructor({backendUrl:e,clientUrl:r=typeof window!="undefined"&&(f=>(f=window.location)==null?void 0:f.origin)()||"",clientStorageGetter:n=pr,clientStorageSetter:i=mr,refreshIntervalTime:s=60,autoSignIn:o=!0,autoRefreshToken:a=!0,start:c=!0}){Le(this,Pt,void 0);Le(this,Nt,void 0);Le(this,It,new Set);this.backendUrl=e,this.clientUrl=r,this.machine=Io({backendUrl:e,clientUrl:r,refreshIntervalTime:s,clientStorageGetter:n,clientStorageSetter:i,autoSignIn:o,autoRefreshToken:a}),c&&(this.interpreter=me(this.machine),this.interpreter.start()),typeof window!="undefined"&&o&&(st(this,Nt,new ke("nhost")),M(this,Nt).addEventListener("message",u=>{var l;let d=(l=this.interpreter)==null?void 0:l.state.context.refreshToken;this.interpreter&&u!==d&&this.interpreter.send({type:"TRY_TOKEN",token:u})}))}get interpreter(){return M(this,Pt)}set interpreter(e){st(this,Pt,e),e&&M(this,It).forEach(r=>r(this))}onStart(e){M(this,It).add(e)}};Pt=new WeakMap,Nt=new WeakMap,It=new WeakMap;var ko=()=>typeof window!="undefined",xe=t=>!t||!t.accessToken.value||!t.refreshToken.value?null:{accessToken:t.accessToken.value,accessTokenExpiresIn:(t.accessToken.expiresAt.getTime()-Date.now())/1e3,refreshToken:t.refreshToken.value,user:t.user},Ze=(t,e)=>{e.forEach(r=>{typeof t[r]!="function"&&console.error(`clientStorage.${r} is not a function`)})},qo=(t,e)=>{if(e){if(t==="react-native"||t==="custom")return Ze(e,["getItem"]),r=>{var n;return(n=e.getItem)==null?void 0:n.call(e,r)};if(t==="capacitor")return Ze(e,["get"]),r=>{var n;return(n=e.get)==null?void 0:n.call(e,{key:r})};if(t==="expo-secure-storage")return Ze(e,["getItemAsync"]),r=>{var n;return(n=e.getItemAsync)==null?void 0:n.call(e,r)}}return pr},Do=(t,e)=>{if(e){if(t==="react-native"||t==="custom")return Ze(e,["setItem","removeItem"]),(r,n)=>{var i,s;n?(i=e.setItem)==null||i.call(e,r,n):(s=e.removeItem)==null||s.call(e,r)};if(t==="capacitor")return Ze(e,["set","remove"]),(r,n)=>{var i,s;n?(i=e.set)==null||i.call(e,{key:r,value:n}):(s=e.remove)==null||s.call(e,{key:r})};if(t==="expo-secure-storage")return Ze(e,["setItemAsync","deleteItemAsync"]),async(r,n)=>{var i,s;n?await((i=e.setItemAsync)==null?void 0:i.call(e,r,n)):(s=e.deleteItemAsync)==null||s.call(e,r)}}return mr};var Uo={message:"User is already signed in",status:100},pl={message:"User is not authenticated",status:101},ml={message:"User is not anonymous",status:101},vl={message:"Email needs verification",status:102},j,yn=class{constructor({url:e,autoRefreshToken:r=!0,autoLogin:n=!0,clientStorage:i,clientStorageType:s="web",clientStorageGetter:o,clientStorageSetter:a,refreshIntervalTime:c,start:f=!0,Client:u=_t}){Le(this,j,void 0);this.onTokenChangedSubscriptions=new Set;this.onAuthStateChangedSubscriptions=new Set;st(this,j,new u({backendUrl:e,autoRefreshToken:r,autoSignIn:n,start:f,clientStorageGetter:o||qo(s,i),clientStorageSetter:a||Do(s,i),refreshIntervalTime:c}))}async signUp(e){let r=await this.waitUntilReady(),{email:n,password:i,options:s}=e;return this.isAuthenticated()?{session:null,error:Uo}:new Promise(o=>{r.send({type:"SIGNUP_EMAIL_PASSWORD",email:n,password:i,options:s}),r.onTransition(a=>{if(a.matches({authentication:{signedOut:"needsEmailVerification"}}))return o({session:null,error:null});if(a.matches({authentication:{signedOut:"failed"}}))return o({session:null,error:a.context.errors.registration||null});if(a.matches({authentication:"signedIn"}))return o({session:xe(a.context),error:null})})})}async signIn(e){let r=await this.waitUntilReady();if(this.isAuthenticated())return{session:null,mfa:null,error:Uo};if("provider"in e){let{provider:n,options:i}=e,s=Ro(`${M(this,j).backendUrl}/v1/auth/signin/provider/${n}`,ie(M(this,j).clientUrl,i));return ko()&&(window.location.href=s),{providerUrl:s,provider:n,session:null,mfa:null,error:null}}return"email"in e&&"password"in e?new Promise(n=>{r.send({type:"SIGNIN_PASSWORD",...e}),r.onTransition(i=>{i.matches({authentication:"signedIn"})?n({session:xe(i.context),mfa:null,error:null}):i.matches({authentication:{signedOut:"needsEmailVerification"}})?n({session:null,mfa:null,error:vl}):i.matches({authentication:{signedOut:"needsMfa"}})?n({session:null,mfa:i.context.mfa,error:null}):i.matches({authentication:{signedOut:"failed"}})&&n({session:null,mfa:null,error:i.context.errors.authentication||null})})}):"email"in e&&!("otp"in e)?new Promise(n=>{r.onTransition(i=>{i.matches({authentication:{signedOut:"needsEmailVerification"}})?n({session:null,mfa:null,error:null}):i.matches({authentication:{signedOut:"failed"}})&&n({session:null,mfa:null,error:i.context.errors.authentication||null})}),r.send({type:"SIGNIN_PASSWORDLESS_EMAIL",...e})}):"phoneNumber"in e&&!("otp"in e)?new Promise(n=>{r.onTransition(i=>{i.matches({authentication:{signedOut:"needsSmsOtp"}})?n({session:null,mfa:null,error:null}):i.matches({authentication:{signedOut:"failed"}})&&n({session:null,mfa:null,error:i.context.errors.authentication||null})}),r.send({type:"SIGNIN_PASSWORDLESS_SMS",...e})}):"otp"in e?new Promise(n=>{r.onTransition(i=>{i.matches({authentication:"signedIn"})?n({session:xe(i.context),mfa:null,error:null}):i.matches({authentication:{signedOut:"failed"}})&&n({session:null,mfa:null,error:i.context.errors.authentication||null})}),r.send({type:"SIGNIN_PASSWORDLESS_SMS_OTP",...e})}):{session:null,mfa:null,error:{message:"Incorrect parameters",status:500}}}async signOut(e){let r=await this.waitUntilReady();return this.isAuthenticated()?new Promise(n=>{r.send({type:"SIGNOUT",all:e==null?void 0:e.all}),r.onTransition(i=>{i.matches({authentication:{signedOut:"success"}})?n({error:null}):i.matches({authentication:{signedOut:"failed"}})&&n({error:i.context.errors.signout||null})})}):{error:pl}}async resetPassword({email:e,options:r}){return new Promise(n=>{let i=me(Po(M(this,j)));i.onTransition(({event:s})=>{if(s.type==="ERROR")return n({error:s.error});if(s.type==="SUCCESS")return n({error:null})}),i.start(),i.send({type:"REQUEST",email:e,options:r})})}async changePassword(e){return new Promise(r=>{let n=me(Co(M(this,j)));n.onTransition(({event:i})=>{if(i.type==="ERROR")return r({error:i.error});if(i.type==="SUCCESS")return r({error:null})}),n.start(),n.send({type:"REQUEST",password:e.newPassword})})}async sendVerificationEmail(e){return new Promise(r=>{let n=me(No(M(this,j)));n.onTransition(({event:i})=>{if(i.type==="ERROR")return r({error:i.error});if(i.type==="SUCCESS")return r({error:null})}),n.start(),n.send({type:"REQUEST",email:e.email,options:e.options})})}async changeEmail({newEmail:e,options:r}){return new Promise(n=>{let i=me(Oo(M(this,j)));i.onTransition(({event:s})=>{if(s.type==="ERROR")return n({error:s.error});if(s.type==="SUCCESS")return n({error:null})}),i.start(),i.send({type:"REQUEST",email:e,options:r})})}async deanonymize(e){let r=await this.waitUntilReady();return new Promise(n=>{var a;if(!this.isAuthenticated()||!((a=r.state.context.user)!=null&&a.isAnonymous))return{error:ml};r.onTransition(c=>{c.matches({authentication:{signedIn:{deanonymizing:"success"}}})?n({error:null}):c.matches({authentication:{signedIn:{deanonymizing:"error"}}})&&n({error:c.context.errors.authentication||null})}),r.start();let{signInMethod:i,connection:s,...o}=e;r.send({type:"DEANONYMIZE",signInMethod:i,connection:s,options:o})})}onTokenChanged(e){var r;return M(this,j).interpreter?this.onTokenChangedSubscriptions.add((r=M(this,j).interpreter)==null?void 0:r.onTransition(({event:n,context:i})=>{n.type==="TOKEN_CHANGED"&&e(xe(i))})):console.log("onTokenChanged: no interpreter is set yet",e),()=>{this.onTokenChangedSubscriptions.forEach(n=>n.stop())}}onAuthStateChanged(e){var r;return M(this,j).interpreter?this.onAuthStateChangedSubscriptions.add((r=M(this,j).interpreter)==null?void 0:r.onTransition(({event:n,context:i})=>{n.type==="SIGNED_IN"?e("SIGNED_IN",xe(i)):n.type==="SIGNED_OUT"&&e("SIGNED_OUT",xe(i))})):console.log("onAuthStateChanged: no interpreter is set yet",e),()=>{this.onAuthStateChangedSubscriptions.forEach(n=>n.stop())}}isAuthenticated(){var e;return!!((e=M(this,j).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=M(this,j).interpreter)==null?void 0:e.state.context.accessToken.value)!=null?r:void 0}async refreshSession(e){try{let r=await this.waitUntilReady();return r.state.matches({token:"idle"})?void 0:new Promise(n=>{let i=e||r.state.context.refreshToken.value;if(!i)return n();r==null||r.onTransition(s=>{(s.matches({token:{idle:"error"}})||s.event.type==="TOKEN_CHANGED")&&n()}),r.send({type:"TRY_TOKEN",token:i})})}catch{return}}getSession(){var e,r;return xe((r=(e=M(this,j).interpreter)==null?void 0:e.state)==null?void 0:r.context)}getUser(){var e,r,n;return((n=(r=(e=M(this,j).interpreter)==null?void 0:e.state)==null?void 0:r.context)==null?void 0:n.user)||null}waitUntilReady(){let r=M(this,j).interpreter;if(!r)throw Error("Auth interpreter not set");return r.state.hasTag("ready")?Promise.resolve(r):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("ready"))return clearTimeout(s),n(r)})})}isReady(){var e,r;return!!((r=(e=M(this,j).interpreter)==null?void 0:e.state)!=null&&r.hasTag("ready"))}get client(){return M(this,j)}};j=new WeakMap;var Ja=Lt(Ga()),Mn=class{constructor({url:e}){this.url=e,this.httpClient=Ja.default.create({baseURL:this.url})}async upload(e){try{return{fileMetadata:(await this.httpClient.post("/files",e.file,{headers:{...this.generateUploadHeaders(e),...this.generateAuthHeaders()}})).data,error:null}}catch(r){return{fileMetadata:null,error:r}}}async getPresignedUrl(e){try{let{fileId:r}=e;return{presignedUrl:(await this.httpClient.get(`/files/${r}/presignedurl`,{headers:{...this.generateAuthHeaders()}})).data,error:null}}catch(r){return{presignedUrl:null,error:r}}}async delete(e){try{let{fileId:r}=e;return await this.httpClient.delete(`/files/${r}`,{headers:{...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){let{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}`}}};var Ln=class{constructor({url:e}){this.url=e,this.api=new Mn({url:e})}async upload(e){let r=new FormData;r.append("file",e.file);let{fileMetadata:n,error:i}=await this.api.upload({...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){let{fileId:r}=e;return`${this.url}/files/${r}`}async getPresignedUrl(e){let{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){let{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}};var Yu=Lt(ii()),si=class{constructor(e){let{url:r}=e;this.accessToken=null,this.instance=Yu.default.create({baseURL:r})}async call(e,r,n){let i={...this.generateAccessTokenHeaders(),...n==null?void 0:n.headers},s;try{s=await this.instance.post(e,r,{...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(){if(!!this.accessToken)return{Authorization:`Bearer ${this.accessToken}`}}};var Qu=Lt(ii()),oi=class{constructor(e){let{url:r}=e;this.url=r,this.accessToken=null,this.instance=Qu.default.create({baseURL:r})}async request(e,r,n){let i={...n==null?void 0:n.headers,...this.generateAccessTokenHeaders()},s="",o;try{o=(await this.instance.post("",{operationName:s||void 0,query:e,variables:r},{...n,headers:i})).data}catch(a){return a instanceof Error?{data:null,error:a}:(console.error(a),{data:null,error:new Error("Unable to get do GraphQL request")})}return typeof o!="object"||Array.isArray(o)||o===null?{data:null,error:new Error("incorrect response data from GraphQL server")}:(o=o,o.errors?{data:null,error:o.errors}:{data:o.data,error:null})}getUrl(){return this.url}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){if(!!this.accessToken)return{Authorization:`Bearer ${this.accessToken}`}}};var ai=class{constructor({backendUrl:e,refreshIntervalTime:r,clientStorageGetter:n,clientStorageSetter:i,clientStorage:s,clientStorageType:o,autoRefreshToken:a,autoLogin:c,start:f=!0,Client:u}){if(!e)throw new Error("Please specify a `backendUrl`. Docs: [todo]!");this.auth=new yn({url:`${e}/v1/auth`,refreshIntervalTime:r,clientStorageGetter:n,clientStorageSetter:i,clientStorage:s,clientStorageType:o,autoRefreshToken:a,autoLogin:c,start:f,Client:u}),this.storage=new Ln({url:`${e}/v1/storage`}),this.functions=new si({url:`${e}/v1/functions`}),this.graphql=new oi({url:`${e}/v1/graphql`}),this.storage.setAccessToken(this.auth.getAccessToken()),this.functions.setAccessToken(this.auth.getAccessToken()),this.graphql.setAccessToken(this.auth.getAccessToken()),this.auth.client.onStart(()=>{this.auth.onAuthStateChanged((d,l)=>{this.storage.setAccessToken(l==null?void 0:l.accessToken),this.functions.setAccessToken(l==null?void 0:l.accessToken),this.graphql.setAccessToken(l==null?void 0:l.accessToken)}),this.auth.onTokenChanged(d=>{this.storage.setAccessToken(d==null?void 0:d.accessToken),this.functions.setAccessToken(d==null?void 0:d.accessToken),this.graphql.setAccessToken(d==null?void 0:d.accessToken)})})}};var Zg=t=>new ai(t);export{ai as NhostClient,Zg as createClient};
|
|
10
10
|
/*! *****************************************************************************
|
|
11
11
|
Copyright (c) Microsoft Corporation.
|
|
12
12
|
|