@clicktap/state 0.12.16 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/auth/AuthProvider.d.ts +2 -2
- package/auth/auth.d.ts +1 -1
- package/index.d.ts +2 -0
- package/index.js +51 -5
- package/index.mjs +4592 -2493
- package/package.json +3 -2
- package/quote/QuoteProvider.d.ts +205 -0
- package/quote/actions/addItems.d.ts +80 -0
- package/quote/actions/index.d.ts +3 -0
- package/quote/actions/refresh.d.ts +82 -0
- package/quote/actions/removeItems.d.ts +80 -0
- package/quote/actors/addItems.d.ts +19 -0
- package/quote/actors/index.d.ts +3 -0
- package/quote/actors/refresh.d.ts +21 -0
- package/quote/actors/removeItems.d.ts +17 -0
- package/quote/guards/canRefresh.d.ts +10 -0
- package/quote/guards/hasItems.d.ts +5 -0
- package/quote/guards/index.d.ts +1 -0
- package/quote/quote.d.ts +93 -0
- package/quote/types.d.ts +147 -0
- package/toast/ToastProvider.d.ts +8 -8
- package/toast/timer.d.ts +1 -1
- package/toast/toast.d.ts +4 -4
package/auth/AuthProvider.d.ts
CHANGED
|
@@ -96,7 +96,7 @@ export declare const AuthContext: import("react").Context<Actor<import("xstate")
|
|
|
96
96
|
}>, never, never, "refreshing" | "authenticating" | "loggedIn" | "loggedOut" | "unauthenticating", string, {
|
|
97
97
|
initialContext: Partial<import("./auth").AuthMachineContext>;
|
|
98
98
|
initialState?: string | undefined;
|
|
99
|
-
}, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, import("./auth").RefreshTokenEvent | import("./auth").LoginEvent | import("./auth").LogoutEvent | import("./auth").ClearErrorsEvent | import("xstate").DoneActorEvent<import("./auth").AuthenticateSuccessEvent> | import("xstate").DoneActorEvent<import("./auth").RefreshTokenSuccessEvent>, import("xstate").Values<{
|
|
99
|
+
}, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, import("./auth").RefreshTokenEvent | import("./auth").LoginEvent | import("./auth").LogoutEvent | import("./auth").ClearErrorsEvent | import("xstate").DoneActorEvent<import("./auth").AuthenticateSuccessEvent> | import("xstate").DoneActorEvent<import("./auth").RefreshTokenSuccessEvent>, import("xstate").Values<{
|
|
100
100
|
refreshAccessToken: {
|
|
101
101
|
src: "refreshAccessToken";
|
|
102
102
|
logic: import("xstate").PromiseActorLogic<{
|
|
@@ -265,7 +265,7 @@ export declare const getAuth: (refreshToken?: string, options?: AuthOptions) =>
|
|
|
265
265
|
}>, never, never, "refreshing" | "authenticating" | "loggedIn" | "loggedOut" | "unauthenticating", string, {
|
|
266
266
|
initialContext: Partial<import("./auth").AuthMachineContext>;
|
|
267
267
|
initialState?: string | undefined;
|
|
268
|
-
}, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, import("./auth").RefreshTokenEvent | import("./auth").LoginEvent | import("./auth").LogoutEvent | import("./auth").ClearErrorsEvent | import("xstate").DoneActorEvent<import("./auth").AuthenticateSuccessEvent> | import("xstate").DoneActorEvent<import("./auth").RefreshTokenSuccessEvent>, import("xstate").Values<{
|
|
268
|
+
}, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, import("./auth").RefreshTokenEvent | import("./auth").LoginEvent | import("./auth").LogoutEvent | import("./auth").ClearErrorsEvent | import("xstate").DoneActorEvent<import("./auth").AuthenticateSuccessEvent> | import("xstate").DoneActorEvent<import("./auth").RefreshTokenSuccessEvent>, import("xstate").Values<{
|
|
269
269
|
refreshAccessToken: {
|
|
270
270
|
src: "refreshAccessToken";
|
|
271
271
|
logic: import("xstate").PromiseActorLogic<{
|
package/auth/auth.d.ts
CHANGED
|
@@ -128,7 +128,7 @@ export declare const authMachine: import("xstate").StateMachine<AuthMachineConte
|
|
|
128
128
|
}>, never, never, "refreshing" | "authenticating" | "loggedIn" | "loggedOut" | "unauthenticating", string, {
|
|
129
129
|
initialContext: Partial<AuthMachineContext>;
|
|
130
130
|
initialState?: string | undefined;
|
|
131
|
-
}, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, RefreshTokenEvent | LoginEvent | LogoutEvent | ClearErrorsEvent | DoneActorEvent<AuthenticateSuccessEvent> | DoneActorEvent<RefreshTokenSuccessEvent>, import("xstate").Values<{
|
|
131
|
+
}, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, RefreshTokenEvent | LoginEvent | LogoutEvent | ClearErrorsEvent | DoneActorEvent<AuthenticateSuccessEvent> | DoneActorEvent<RefreshTokenSuccessEvent>, import("xstate").Values<{
|
|
132
132
|
refreshAccessToken: {
|
|
133
133
|
src: "refreshAccessToken";
|
|
134
134
|
logic: import("xstate").PromiseActorLogic<{
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,5 +1,51 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _e=require("react/jsx-runtime"),M=require("react");function ln(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global}function dn(){const t=ln();if(t.__xstate__)return t.__xstate__}const hn=t=>{if(typeof window>"u")return;const e=dn();e&&e.register(t)};class Gt{constructor(e){this._process=e,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(e){const n={value:e,next:null};if(this._current){this._last.next=n,this._last=n;return}this._current=n,this._last=n,this._active&&this.flush()}flush(){for(;this._current;){const e=this._current;this._process(e.value),this._current=e.next}this._last=null}}const Te=".",pn="",ve="",yn="#",mn="*",be="xstate.init",gn="xstate.error",K="xstate.stop";function Sn(t,e){return{type:`xstate.after.${t}.${e}`}}function _t(t,e){return{type:`xstate.done.state.${t}`,output:e}}function En(t,e){return{type:`xstate.done.actor.${t}`,output:e}}function Ae(t,e){return{type:`xstate.error.actor.${t}`,error:e}}function xe(t){return{type:be,input:t}}function x(t){setTimeout(()=>{throw t})}const wn=(()=>typeof Symbol=="function"&&Symbol.observable||"@@observable")();function Xt(t,e){return`${t.sessionId}.${e}`}let _n=0;function Tn(t,e){const n=new Map,s=new Map,r=new WeakMap,i=new Set,o={},a=e.clock,u={schedule:(f,p,y,h,m=Math.random().toString(36).slice(2))=>{const S={source:f,target:p,event:y,delay:h,id:m,startedAt:Date.now()},E=Xt(f,m);l._snapshot._scheduledEvents[E]=S;const O=a.setTimeout(()=>{delete o[E],delete l._snapshot._scheduledEvents[E],l._relay(f,p,y)},h);o[E]=O},cancel:(f,p)=>{const y=Xt(f,p),h=o[y];delete o[y],delete l._snapshot._scheduledEvents[y],a.clearTimeout(h)},cancelAll:f=>{for(const p in l._snapshot._scheduledEvents){const y=l._snapshot._scheduledEvents[p];y.source===f&&u.cancel(f,y.id)}}},c=f=>{if(!i.size)return;const p={...f,rootId:t.sessionId};i.forEach(y=>{var h;return(h=y.next)==null?void 0:h.call(y,p)})},l={_snapshot:{_scheduledEvents:((e==null?void 0:e.snapshot)&&e.snapshot.scheduler)??{}},_bookId:()=>`x:${_n++}`,_register:(f,p)=>(n.set(f,p),f),_unregister:f=>{n.delete(f.sessionId);const p=r.get(f);p!==void 0&&(s.delete(p),r.delete(f))},get:f=>s.get(f),_set:(f,p)=>{const y=s.get(f);if(y&&y!==p)throw new Error(`Actor with system ID '${f}' already exists.`);s.set(f,p),r.set(p,f)},inspect:f=>{i.add(f)},_sendInspectionEvent:c,_relay:(f,p,y)=>{l._sendInspectionEvent({type:"@xstate.event",sourceRef:f,actorRef:p,event:y}),p._send(y)},scheduler:u,getSnapshot:()=>({_scheduledEvents:{...l._snapshot._scheduledEvents}}),start:()=>{const f=l._snapshot._scheduledEvents;l._snapshot._scheduledEvents={};for(const p in f){const{source:y,target:h,event:m,delay:S,id:E}=f[p];u.schedule(y,h,m,S,E)}}};return l}function Re(t,e){const n=Yt(t),s=Yt(e);return typeof s=="string"?typeof n=="string"?s===n:!1:typeof n=="string"?n in s:Object.keys(n).every(r=>r in s?Re(n[r],s[r]):!1)}function It(t){if(ke(t))return t;let e=[],n="";for(let s=0;s<t.length;s++){switch(t.charCodeAt(s)){case 92:n+=t[s+1],s++;continue;case 46:e.push(n),n="";continue}n+=t[s]}return e.push(n),e}function Yt(t){if(Qn(t))return t.value;if(typeof t!="string")return t;const e=It(t);return vn(e)}function vn(t){if(t.length===1)return t[0];const e={};let n=e;for(let s=0;s<t.length-1;s++)if(s===t.length-2)n[t[s]]=t[s+1];else{const r=n;n={},r[t[s]]=n}return e}function Zt(t,e){const n={},s=Object.keys(t);for(let r=0;r<s.length;r++){const i=s[r];n[i]=e(t[i],i,t,r)}return n}function Oe(t){return ke(t)?t:[t]}function I(t){return t===void 0?[]:Oe(t)}function Tt(t,e,n,s){return typeof t=="function"?t({context:e,event:n,self:s}):t}function ke(t){return Array.isArray(t)}function bn(t){return t.type.startsWith("xstate.error.actor")}function N(t){return Oe(t).map(e=>typeof e>"u"||typeof e=="string"?{target:e}:e)}function Ie(t){if(!(t===void 0||t===pn))return I(t)}function Qt(t,e,n){var i,o,a;const s=typeof t=="object",r=s?t:void 0;return{next:(i=s?t.next:t)==null?void 0:i.bind(r),error:(o=s?t.error:e)==null?void 0:o.bind(r),complete:(a=s?t.complete:n)==null?void 0:a.bind(r)}}function te(t,e){return`${e}.${t}`}function Ct(t,e){const n=e.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!n)return t.implementations.actors[e];const[,s,r]=n,o=t.getStateNodeById(r).config.invoke;return(Array.isArray(o)?o[s]:o).src}const Pt=1;let _=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const An={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class xn{constructor(e,n){this.logic=e,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new Gt(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=_.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const s={...An,...n},{clock:r,logger:i,parent:o,syncSnapshot:a,id:u,systemId:c,inspect:l}=s;this.system=o?o.system:Tn(this,{clock:r}),l&&!o&&this.system.inspect(Qt(l)),this.sessionId=this.system._bookId(),this.id=u??this.sessionId,this.logger=i,this.clock=r,this._parent=o,this._syncSnapshot=a,this.options=s,this.src=s.src??e,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:f=>{this._deferred.push(f)},system:this.system,stopChild:f=>{if(f._parent!==this)throw new Error(`Cannot stop child actor ${f.id} of ${this.id} because it is not a child`);f._stop()},emit:f=>{const p=this.eventListeners.get(f.type);if(p)for(const y of Array.from(p))y(f)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),c&&(this._systemId=c,this.system._set(c,this)),this._initState((n==null?void 0:n.snapshot)??(n==null?void 0:n.state)),c&&this._snapshot.status!=="active"&&this.system._unregister(this)}_initState(e){var n;try{this._snapshot=e?this.logic.restoreSnapshot?this.logic.restoreSnapshot(e,this._actorScope):e:this.logic.getInitialSnapshot(this._actorScope,(n=this.options)==null?void 0:n.input)}catch(s){this._snapshot={status:"error",output:void 0,error:s}}}update(e,n){var r,i;this._snapshot=e;let s;for(;s=this._deferred.shift();)try{s()}catch(o){this._deferred.length=0,this._snapshot={...e,status:"error",error:o}}switch(this._snapshot.status){case"active":for(const o of this.observers)try{(r=o.next)==null||r.call(o,e)}catch(a){x(a)}break;case"done":for(const o of this.observers)try{(i=o.next)==null||i.call(o,e)}catch(a){x(a)}this._stopProcedure(),this._complete(),this._doneEvent=En(this.id,this._snapshot.output),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error);break}this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:n,snapshot:e})}subscribe(e,n,s){var i;const r=Qt(e,n,s);if(this._processingStatus!==_.Stopped)this.observers.add(r);else switch(this._snapshot.status){case"done":try{(i=r.complete)==null||i.call(r)}catch(o){x(o)}break;case"error":{const o=this._snapshot.error;if(!r.error)x(o);else try{r.error(o)}catch(a){x(a)}break}}return{unsubscribe:()=>{this.observers.delete(r)}}}on(e,n){let s=this.eventListeners.get(e);s||(s=new Set,this.eventListeners.set(e,s));const r=n.bind(void 0);return s.add(r),{unsubscribe:()=>{s.delete(r)}}}start(){if(this._processingStatus===_.Running)return this;this._syncSnapshot&&this.subscribe({next:s=>{s.status==="active"&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:s})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=_.Running;const e=xe(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:e}),this._snapshot.status){case"done":return this.update(this._snapshot,e),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(s){return this._snapshot={...this._snapshot,status:"error",error:s},this._error(s),this}return this.update(this._snapshot,e),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(e){let n,s;try{n=this.logic.transition(this._snapshot,e,this._actorScope)}catch(r){s={err:r}}if(s){const{err:r}=s;this._snapshot={...this._snapshot,status:"error",error:r},this._error(r);return}this.update(n,e),e.type===K&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===_.Stopped?this:(this.mailbox.clear(),this._processingStatus===_.NotStarted?(this._processingStatus=_.Stopped,this):(this.mailbox.enqueue({type:K}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){var e;for(const n of this.observers)try{(e=n.complete)==null||e.call(n)}catch(s){x(s)}this.observers.clear()}_reportError(e){if(!this.observers.size){this._parent||x(e);return}let n=!1;for(const s of this.observers){const r=s.error;n||(n=!r);try{r==null||r(e)}catch(i){x(i)}}this.observers.clear(),n&&x(e)}_error(e){this._stopProcedure(),this._reportError(e),this._parent&&this.system._relay(this,this._parent,Ae(this.id,e))}_stopProcedure(){return this._processingStatus!==_.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new Gt(this._process.bind(this)),this._processingStatus=_.Stopped,this.system._unregister(this),this)}_send(e){this._processingStatus!==_.Stopped&&this.mailbox.enqueue(e)}send(e){this.system._relay(void 0,this,e)}attachDevTools(){const{devTools:e}=this.options;e&&(typeof e=="function"?e:hn)(this)}toJSON(){return{xstate$$type:Pt,id:this.id}}getPersistedSnapshot(e){return this.logic.getPersistedSnapshot(this._snapshot,e)}[wn](){return this}getSnapshot(){return this._snapshot}}function L(t,...[e]){return new xn(t,e)}function Rn(t,e,n,s,{sendId:r}){const i=typeof r=="function"?r(n,s):r;return[e,i]}function On(t,e){t.defer(()=>{t.system.scheduler.cancel(t.self,e)})}function kn(t){function e(n,s){}return e.type="xstate.cancel",e.sendId=t,e.resolve=Rn,e.execute=On,e}function In(t,e,n,s,{id:r,systemId:i,src:o,input:a,syncSnapshot:u}){const c=typeof o=="string"?Ct(e.machine,o):o,l=typeof r=="function"?r(n):r;let f;return c&&(f=L(c,{id:l,src:o,parent:t.self,syncSnapshot:u,systemId:i,input:typeof a=="function"?a({context:e.context,event:n.event,self:t.self}):a})),[U(e,{children:{...e.children,[l]:f}}),{id:r,actorRef:f}]}function Cn(t,{id:e,actorRef:n}){n&&t.defer(()=>{n._processingStatus!==_.Stopped&&n.start()})}function Pn(...[t,{id:e,systemId:n,input:s,syncSnapshot:r=!1}={}]){function i(o,a){}return i.type="snapshot.spawnChild",i.id=e,i.systemId=n,i.src=t,i.input=s,i.syncSnapshot=r,i.resolve=In,i.execute=Cn,i}function Dn(t,e,n,s,{actorRef:r}){const i=typeof r=="function"?r(n,s):r,o=typeof i=="string"?e.children[i]:i;let a=e.children;return o&&(a={...a},delete a[o.id]),[U(e,{children:a}),o]}function Mn(t,e){if(e){if(t.system._unregister(e),e._processingStatus!==_.Running){t.stopChild(e);return}t.defer(()=>{t.stopChild(e)})}}function Ce(t){function e(n,s){}return e.type="xstate.stopChild",e.actorRef=t,e.resolve=Dn,e.execute=Mn,e}function Dt(t,e,n,s){const{machine:r}=s,i=typeof t=="function",o=i?t:r.implementations.guards[typeof t=="string"?t:t.type];if(!i&&!o)throw new Error(`Guard '${typeof t=="string"?t:t.type}' is not implemented.'.`);if(typeof o!="function")return Dt(o,e,n,s);const a={context:e,event:n},u=i||typeof t=="string"?void 0:"params"in t?typeof t.params=="function"?t.params({context:e,event:n}):t.params:void 0;return"check"in o?o.check(s,a,o):o(a,u)}const Mt=t=>t.type==="atomic"||t.type==="final";function B(t){return Object.values(t.states).filter(e=>e.type!=="history")}function G(t,e){const n=[];if(e===t)return n;let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function rt(t){const e=new Set(t),n=De(e);for(const s of e)if(s.type==="compound"&&(!n.get(s)||!n.get(s).length))ee(s).forEach(r=>e.add(r));else if(s.type==="parallel"){for(const r of B(s))if(r.type!=="history"&&!e.has(r)){const i=ee(r);for(const o of i)e.add(o)}}for(const s of e){let r=s.parent;for(;r;)e.add(r),r=r.parent}return e}function Pe(t,e){const n=e.get(t);if(!n)return{};if(t.type==="compound"){const r=n[0];if(r){if(Mt(r))return r.key}else return{}}const s={};for(const r of n)s[r.key]=Pe(r,e);return s}function De(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function Me(t,e){const n=rt(e);return Pe(t,De(n))}function Ut(t,e){return e.type==="compound"?B(e).some(n=>n.type==="final"&&t.has(n)):e.type==="parallel"?B(e).every(n=>Ut(t,n)):e.type==="final"}const ct=t=>t[0]===yn;function Un(t,e){return t.transitions.get(e)||[...t.transitions.keys()].filter(s=>{if(s===mn)return!0;if(!s.endsWith(".*"))return!1;const r=s.split("."),i=e.split(".");for(let o=0;o<r.length;o++){const a=r[o],u=i[o];if(a==="*")return o===r.length-1;if(a!==u)return!1}return!0}).sort((s,r)=>r.length-s.length).flatMap(s=>t.transitions.get(s))}function jn(t){const e=t.config.after;if(!e)return[];const n=(r,i)=>{const o=Sn(r,t.id),a=o.type;return t.entry.push(cs(o,{id:a,delay:r})),t.exit.push(kn(a)),a};return Object.keys(e).flatMap((r,i)=>{const o=e[r],a=typeof o=="string"?{target:o}:o,u=Number.isNaN(+r)?r:+r,c=n(u);return I(a).map(l=>({...l,event:c,delay:u}))}).map(r=>{const{delay:i}=r;return{...P(t,r.event,r),delay:i}})}function P(t,e,n){const s=Ie(n.target),r=n.reenter??!1,i=Ln(t,s),o={...n,actions:I(n.actions),guard:n.guard,target:i,source:t,reenter:r,eventType:e,toJSON:()=>({...o,source:`#${t.id}`,target:i?i.map(a=>`#${a.id}`):void 0})};return o}function Nn(t){const e=new Map;if(t.config.on)for(const n of Object.keys(t.config.on)){if(n===ve)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const s=t.config.on[n];e.set(n,N(s).map(r=>P(t,n,r)))}if(t.config.onDone){const n=`xstate.done.state.${t.id}`;e.set(n,N(t.config.onDone).map(s=>P(t,n,s)))}for(const n of t.invoke){if(n.onDone){const s=`xstate.done.actor.${n.id}`;e.set(s,N(n.onDone).map(r=>P(t,s,r)))}if(n.onError){const s=`xstate.error.actor.${n.id}`;e.set(s,N(n.onError).map(r=>P(t,s,r)))}if(n.onSnapshot){const s=`xstate.snapshot.${n.id}`;e.set(s,N(n.onSnapshot).map(r=>P(t,s,r)))}}for(const n of t.after){let s=e.get(n.eventType);s||(s=[],e.set(n.eventType,s)),s.push(n)}return e}function $n(t,e){const n=typeof e=="string"?t.states[e]:e?t.states[e.target]:void 0;if(!n&&e)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);const s={source:t,actions:!e||typeof e=="string"?[]:I(e.actions),eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...s,source:`#${t.id}`,target:n?[`#${n.id}`]:[]})};return s}function Ln(t,e){if(e!==void 0)return e.map(n=>{if(typeof n!="string")return n;if(ct(n))return t.machine.getStateNodeById(n);const s=n[0]===Te;if(s&&!t.parent)return it(t,n.slice(1));const r=s?t.key+n:n;if(t.parent)try{return it(t.parent,r)}catch(i){throw new Error(`Invalid transition definition for state node '${t.id}':
|
|
2
|
-
${i.message}`)}else throw new Error(`Invalid target: "${n}" is not a valid target from the root node. Did you mean ".${n}"?`)})}function Ue(t){const e=Ie(t.config.target);return e?{target:e.map(n=>typeof n=="string"?it(t.parent,n):n)}:t.parent.initial}function D(t){return t.type==="history"}function ee(t){const e=je(t);for(const n of e)for(const s of G(n,t))e.add(s);return e}function je(t){const e=new Set;function n(s){if(!e.has(s)){if(e.add(s),s.type==="compound")n(s.initial.target[0]);else if(s.type==="parallel")for(const r of B(s))n(r)}}return n(t),e}function F(t,e){if(ct(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function it(t,e){if(typeof e=="string"&&ct(e))try{return t.machine.getStateNodeById(e)}catch{}const n=It(e).slice();let s=t;for(;n.length;){const r=n.shift();if(!r.length)break;s=F(s,r)}return s}function ot(t,e){if(typeof e=="string"){const r=t.states[e];if(!r)throw new Error(`State '${e}' does not exist on '${t.id}'`);return[t,r]}const n=Object.keys(e),s=n.map(r=>F(t,r)).filter(Boolean);return[t.machine.root,t].concat(s,n.reduce((r,i)=>{const o=F(t,i);if(!o)return r;const a=ot(o,e[i]);return r.concat(a)},[]))}function Bn(t,e,n,s){const i=F(t,e).next(n,s);return!i||!i.length?t.next(n,s):i}function Fn(t,e,n,s){const r=Object.keys(e),i=F(t,r[0]),o=jt(i,e[r[0]],n,s);return!o||!o.length?t.next(n,s):o}function Hn(t,e,n,s){const r=[];for(const i of Object.keys(e)){const o=e[i];if(!o)continue;const a=F(t,i),u=jt(a,o,n,s);u&&r.push(...u)}return r.length?r:t.next(n,s)}function jt(t,e,n,s){return typeof e=="string"?Bn(t,e,n,s):Object.keys(e).length===1?Fn(t,e,n,s):Hn(t,e,n,s)}function qn(t){return Object.keys(t.states).map(e=>t.states[e]).filter(e=>e.type==="history")}function C(t,e){let n=t;for(;n.parent&&n.parent!==e;)n=n.parent;return n.parent===e}function zn(t,e){const n=new Set(t),s=new Set(e);for(const r of n)if(s.has(r))return!0;for(const r of s)if(n.has(r))return!0;return!1}function Ne(t,e,n){const s=new Set;for(const r of t){let i=!1;const o=new Set;for(const a of s)if(zn(vt([r],e,n),vt([a],e,n)))if(C(r.source,a.source))o.add(a);else{i=!0;break}if(!i){for(const a of o)s.delete(a);s.add(r)}}return Array.from(s)}function Jn(t){const[e,...n]=t;for(const s of G(e,void 0))if(n.every(r=>C(r,s)))return s}function Nt(t,e){if(!t.target)return[];const n=new Set;for(const s of t.target)if(D(s))if(e[s.id])for(const r of e[s.id])n.add(r);else for(const r of Nt(Ue(s),e))n.add(r);else n.add(s);return[...n]}function $e(t,e){const n=Nt(t,e);if(!n)return;if(!t.reenter&&n.every(r=>r===t.source||C(r,t.source)))return t.source;const s=Jn(n.concat(t.source));if(s)return s;if(!t.reenter)return t.source.machine.root}function vt(t,e,n){var r;const s=new Set;for(const i of t)if((r=i.target)!=null&&r.length){const o=$e(i,n);i.reenter&&i.source===o&&s.add(o);for(const a of e)C(a,o)&&s.add(a)}return[...s]}function Wn(t,e){if(t.length!==e.size)return!1;for(const n of t)if(!e.has(n))return!1;return!0}function bt(t,e,n,s,r,i){if(!t.length)return e;const o=new Set(e._nodes);let a=e.historyValue;const u=Ne(t,o,a);let c=e;r||([c,a]=Xn(c,s,n,u,o,a,i)),c=H(c,s,n,u.flatMap(f=>f.actions),i),c=Vn(c,s,n,u,o,i,a,r);const l=[...o];c.status==="done"&&(c=H(c,s,n,l.sort((f,p)=>p.order-f.order).flatMap(f=>f.exit),i));try{return a===e.historyValue&&Wn(e._nodes,o)?c:U(c,{_nodes:l,historyValue:a})}catch(f){throw f}}function Kn(t,e,n,s,r){if(s.output===void 0)return;const i=_t(r.id,r.output!==void 0&&r.parent?Tt(r.output,t.context,e,n.self):void 0);return Tt(s.output,t.context,i,n.self)}function Vn(t,e,n,s,r,i,o,a){let u=t;const c=new Set,l=new Set;Gn(s,o,l,c),a&&l.add(t.machine.root);const f=new Set;for(const p of[...c].sort((y,h)=>y.order-h.order)){r.add(p);const y=[];y.push(...p.entry);for(const h of p.invoke)y.push(Pn(h.src,{...h,syncSnapshot:!!h.onSnapshot}));if(l.has(p)){const h=p.initial.actions;y.push(...h)}if(u=H(u,e,n,y,i,p.invoke.map(h=>h.id)),p.type==="final"){const h=p.parent;let m=(h==null?void 0:h.type)==="parallel"?h:h==null?void 0:h.parent,S=m||p;for((h==null?void 0:h.type)==="compound"&&i.push(_t(h.id,p.output!==void 0?Tt(p.output,u.context,e,n.self):void 0));(m==null?void 0:m.type)==="parallel"&&!f.has(m)&&Ut(r,m);)f.add(m),i.push(_t(m.id)),S=m,m=m.parent;if(m)continue;u=U(u,{status:"done",output:Kn(u,e,n,u.machine.root,S)})}}return u}function Gn(t,e,n,s){for(const r of t){const i=$e(r,e);for(const a of r.target||[])!D(a)&&(r.source!==a||r.source!==i||r.reenter)&&(s.add(a),n.add(a)),$(a,e,n,s);const o=Nt(r,e);for(const a of o){const u=G(a,i);(i==null?void 0:i.type)==="parallel"&&u.push(i),Le(s,e,n,u,!r.source.parent&&r.reenter?void 0:i)}}}function $(t,e,n,s){var r;if(D(t))if(e[t.id]){const i=e[t.id];for(const o of i)s.add(o),$(o,e,n,s);for(const o of i)pt(o,t.parent,s,e,n)}else{const i=Ue(t);for(const o of i.target)s.add(o),i===((r=t.parent)==null?void 0:r.initial)&&n.add(t.parent),$(o,e,n,s);for(const o of i.target)pt(o,t.parent,s,e,n)}else if(t.type==="compound"){const[i]=t.initial.target;D(i)||(s.add(i),n.add(i)),$(i,e,n,s),pt(i,t,s,e,n)}else if(t.type==="parallel")for(const i of B(t).filter(o=>!D(o)))[...s].some(o=>C(o,i))||(D(i)||(s.add(i),n.add(i)),$(i,e,n,s))}function Le(t,e,n,s,r){for(const i of s)if((!r||C(i,r))&&t.add(i),i.type==="parallel")for(const o of B(i).filter(a=>!D(a)))[...t].some(a=>C(a,o))||(t.add(o),$(o,e,n,t))}function pt(t,e,n,s,r){Le(n,s,r,G(t,e))}function Xn(t,e,n,s,r,i,o){let a=t;const u=vt(s,r,i);u.sort((l,f)=>f.order-l.order);let c;for(const l of u)for(const f of qn(l)){let p;f.history==="deep"?p=y=>Mt(y)&&C(y,l):p=y=>y.parent===l,c??(c={...i}),c[f.id]=Array.from(r).filter(p)}for(const l of u)a=H(a,e,n,[...l.exit,...l.invoke.map(f=>Ce(f.id))],o),r.delete(l);return[a,c||i]}function Be(t,e,n,s,r,i){const{machine:o}=t;let a=t;for(const u of s){let y=function(){n.system._sendInspectionEvent({type:"@xstate.action",actorRef:n.self,action:{type:typeof u=="string"?u:typeof u=="object"?u.type:u.name||"(anonymous)",params:p}}),l(f,p)};const c=typeof u=="function",l=c?u:o.implementations.actions[typeof u=="string"?u:u.type];if(!l)continue;const f={context:a.context,event:e,self:n.self,system:n.system},p=c||typeof u=="string"?void 0:"params"in u?typeof u.params=="function"?u.params({context:a.context,event:e}):u.params:void 0;if(!("resolve"in l)){n.self._processingStatus===_.Running?y():n.defer(()=>{y()});continue}const h=l,[m,S,E]=h.resolve(n,a,f,p,l,r);a=m,"retryResolve"in h&&(i==null||i.push([h,S])),"execute"in h&&(n.self._processingStatus===_.Running?h.execute(n,S):n.defer(h.execute.bind(null,n,S))),E&&(a=Be(a,e,n,E,r,i))}return a}function H(t,e,n,s,r,i){const o=i?[]:void 0,a=Be(t,e,n,s,{internalQueue:r,deferredActorIds:i},o);return o==null||o.forEach(([u,c])=>{u.retryResolve(n,a,c)}),a}function yt(t,e,n,s=[]){let r=t;const i=[];function o(c,l,f){n.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:n.self,event:l,snapshot:c,_transitions:f}),i.push(c)}if(e.type===K)return r=U(ne(r,e,n),{status:"stopped"}),o(r,e,[]),{snapshot:r,microstates:i};let a=e;if(a.type!==be){const c=a,l=bn(c),f=se(c,r);if(l&&!f.length)return r=U(t,{status:"error",error:c.error}),o(r,c,[]),{snapshot:r,microstates:i};r=bt(f,t,n,a,!1,s),o(r,c,f)}let u=!0;for(;r.status==="active";){let c=u?Yn(r,a):[];const l=c.length?r:void 0;if(!c.length){if(!s.length)break;a=s.shift(),c=se(a,r)}r=bt(c,r,n,a,!1,s),u=r!==l,o(r,a,c)}return r.status!=="active"&&ne(r,a,n),{snapshot:r,microstates:i}}function ne(t,e,n){return H(t,e,n,Object.values(t.children).map(s=>Ce(s)),[])}function se(t,e){return e.machine.getTransitionData(e,t)}function Yn(t,e){const n=new Set,s=t._nodes.filter(Mt);for(const r of s)t:for(const i of[r].concat(G(r,void 0)))if(i.always){for(const o of i.always)if(o.guard===void 0||Dt(o.guard,t.context,e,t)){n.add(o);break t}}return Ne(Array.from(n),new Set(t._nodes),t.historyValue)}function Zn(t,e){const n=rt(ot(t,e));return Me(t,[...n])}function Qn(t){return!!t&&typeof t=="object"&&"machine"in t&&"value"in t}const ts=function(e){return Re(e,this.value)},es=function(e){return this.tags.has(e)},ns=function(e){const n=this.machine.getTransitionData(this,e);return!!(n!=null&&n.length)&&n.some(s=>s.target!==void 0||s.actions.length)},ss=function(){const{_nodes:e,tags:n,machine:s,getMeta:r,toJSON:i,can:o,hasTag:a,matches:u,...c}=this;return{...c,tags:Array.from(n)}},rs=function(){return this._nodes.reduce((e,n)=>(n.meta!==void 0&&(e[n.id]=n.meta),e),{})};function Q(t,e){return{status:t.status,output:t.output,error:t.error,machine:e,context:t.context,_nodes:t._nodes,value:Me(e.root,t._nodes),tags:new Set(t._nodes.flatMap(n=>n.tags)),children:t.children,historyValue:t.historyValue||{},matches:ts,hasTag:es,can:ns,getMeta:rs,toJSON:ss}}function U(t,e={}){return Q({...t,...e},t.machine)}function is(t,e){const{_nodes:n,tags:s,machine:r,children:i,context:o,can:a,hasTag:u,matches:c,getMeta:l,toJSON:f,...p}=t,y={};for(const m in i){const S=i[m];y[m]={snapshot:S.getPersistedSnapshot(e),src:S.src,systemId:S._systemId,syncSnapshot:S._syncSnapshot}}return{...p,context:Fe(o),children:y}}function Fe(t){let e;for(const n in t){const s=t[n];if(s&&typeof s=="object")if("sessionId"in s&&"send"in s&&"ref"in s)e??(e=Array.isArray(t)?t.slice():{...t}),e[n]={xstate$$type:Pt,id:s.id};else{const r=Fe(s);r!==s&&(e??(e=Array.isArray(t)?t.slice():{...t}),e[n]=r)}}return e??t}function os(t,e,n,s,{event:r,id:i,delay:o},{internalQueue:a}){const u=e.machine.implementations.delays;if(typeof r=="string")throw new Error(`Only event objects may be used with raise; use raise({ type: "${r}" }) instead`);const c=typeof r=="function"?r(n,s):r;let l;if(typeof o=="string"){const f=u&&u[o];l=typeof f=="function"?f(n,s):f}else l=typeof o=="function"?o(n,s):o;return typeof l!="number"&&a.push(c),[e,{event:c,id:i,delay:l}]}function as(t,e){const{event:n,delay:s,id:r}=e;if(typeof s=="number"){t.defer(()=>{const i=t.self;t.system.scheduler.schedule(i,i,n,s,r)});return}}function cs(t,e){function n(s,r){}return n.type="xstate.raise",n.event=t,n.id=e==null?void 0:e.id,n.delay=e==null?void 0:e.delay,n.resolve=os,n.execute=as,n}const re=new WeakMap;function us(t){return{config:t,start:(n,s)=>{const{self:r,system:i}=s,o={receivers:void 0,dispose:void 0};re.set(r,o),o.dispose=t({input:n.input,system:i,self:r,sendBack:a=>{r.getSnapshot().status!=="stopped"&&r._parent&&i._relay(r,r._parent,a)},receive:a=>{o.receivers??(o.receivers=new Set),o.receivers.add(a)}})},transition:(n,s,r)=>{var o,a;const i=re.get(r.self);return s.type===K?(n={...n,status:"stopped",error:void 0},(o=i.dispose)==null||o.call(i),n):((a=i.receivers)==null||a.forEach(u=>u(s)),n)},getInitialSnapshot:(n,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:n=>n,restoreSnapshot:n=>n}}const ie="xstate.promise.resolve",oe="xstate.promise.reject";function mt(t){return{config:t,transition:(n,s)=>{if(n.status!=="active")return n;switch(s.type){case ie:{const r=s.data;return{...n,status:"done",output:r,input:void 0}}case oe:return{...n,status:"error",error:s.data,input:void 0};case K:return{...n,status:"stopped",input:void 0};default:return n}},start:(n,{self:s,system:r})=>{if(n.status!=="active")return;Promise.resolve(t({input:n.input,system:r,self:s})).then(o=>{s.getSnapshot().status==="active"&&r._relay(s,s,{type:ie,data:o})},o=>{s.getSnapshot().status==="active"&&r._relay(s,s,{type:oe,data:o})})},getInitialSnapshot:(n,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:n=>n,restoreSnapshot:n=>n}}function fs(t,{machine:e,context:n},s,r){const i=(o,a={})=>{const{systemId:u,input:c}=a;if(typeof o=="string"){const l=Ct(e,o);if(!l)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const f=L(l,{id:a.id,parent:t.self,syncSnapshot:a.syncSnapshot,input:typeof c=="function"?c({context:n,event:s,self:t.self}):c,src:o,systemId:u});return r[f.id]=f,f}else return L(o,{id:a.id,parent:t.self,syncSnapshot:a.syncSnapshot,input:a.input,src:o,systemId:u})};return(o,a)=>{const u=i(o,a);return r[u.id]=u,t.defer(()=>{u._processingStatus!==_.Stopped&&u.start()}),u}}function ls(t,e,n,s,{assignment:r}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},o={context:e.context,event:n.event,spawn:fs(t,e,n.event,i),self:t.self,system:t.system};let a={};if(typeof r=="function")a=r(o,s);else for(const c of Object.keys(r)){const l=r[c];a[c]=typeof l=="function"?l(o,s):l}const u=Object.assign({},e.context,a);return[U(e,{context:u,children:Object.keys(i).length?{...e.children,...i}:e.children})]}function v(t){function e(n,s){}return e.type="xstate.assign",e.assignment=t,e.resolve=ls,e}let ae=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function ds(t,e,n,s,{to:r,event:i,id:o,delay:a},u){var h;const c=e.machine.implementations.delays;if(typeof i=="string")throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${i}" }) instead`);const l=typeof i=="function"?i(n,s):i;let f;if(typeof a=="string"){const m=c&&c[a];f=typeof m=="function"?m(n,s):m}else f=typeof a=="function"?a(n,s):a;const p=typeof r=="function"?r(n,s):r;let y;if(typeof p=="string"){if(p===ae.Parent?y=t.self._parent:p===ae.Internal?y=t.self:p.startsWith("#_")?y=e.children[p.slice(2)]:y=(h=u.deferredActorIds)!=null&&h.includes(p)?p:e.children[p],!y)throw new Error(`Unable to send event to actor '${p}' from machine '${e.machine.id}'.`)}else y=p||t.self;return[e,{to:y,event:l,id:o,delay:f}]}function hs(t,e,n){typeof n.to=="string"&&(n.to=e.children[n.to])}function ps(t,e){t.defer(()=>{const{to:n,event:s,delay:r,id:i}=e;if(typeof r=="number"){t.system.scheduler.schedule(t.self,n,s,r,i);return}t.system._relay(t.self,n,s.type===gn?Ae(t.self.id,s.data):s)})}function ce(t,e,n){function s(r,i){}return s.type="xsnapshot.sendTo",s.to=t,s.event=e,s.id=n==null?void 0:n.id,s.delay=n==null?void 0:n.delay,s.resolve=ds,s.retryResolve=hs,s.execute=ps,s}const ue=new WeakMap;function j(t,e,n){let s=ue.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},ue.set(t,s)),s[e]}const ys={},J=t=>typeof t=="string"?{type:t}:typeof t=="function"?"resolve"in t?{type:t.type}:{type:t.name}:t;class $t{constructor(e,n){if(this.config=e,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=n._parent,this.key=n._key,this.machine=n._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(Te),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?Zt(this.config.states,(s,r)=>new $t(s,{_parent:this,_key:r,_machine:this.machine})):ys,this.type==="compound"&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=this.config.history===!0?"shallow":this.config.history||!1,this.entry=I(this.config.entry).slice(),this.exit=I(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type==="final"||!this.parent?this.config.output:void 0,this.tags=I(e.tags).slice()}_initialize(){this.transitions=Nn(this),this.config.always&&(this.always=N(this.config.always).map(e=>P(this,ve,e))),Object.keys(this.states).forEach(e=>{this.states[e]._initialize()})}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(J),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(e=>`#${e.id}`),source:`#${this.id}`,actions:this.initial.actions.map(J),eventType:null})}:void 0,history:this.history,states:Zt(this.states,e=>e.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(e=>({...e,actions:e.actions.map(J)})),entry:this.entry.map(J),exit:this.exit.map(J),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return j(this,"invoke",()=>I(this.config.invoke).map((e,n)=>{const{src:s,systemId:r}=e,i=e.id??te(this.id,n),o=typeof s=="string"?s:`xstate.invoke.${te(this.id,n)}`;return{...e,src:o,id:i,systemId:r,toJSON(){const{onDone:a,onError:u,...c}=e;return{...c,type:"xstate.invoke",src:o,id:i}}}}))}get on(){return j(this,"on",()=>[...this.transitions].flatMap(([n,s])=>s.map(r=>[n,r])).reduce((n,[s,r])=>(n[s]=n[s]||[],n[s].push(r),n),{}))}get after(){return j(this,"delayedTransitions",()=>jn(this))}get initial(){return j(this,"initial",()=>$n(this,this.config.initial))}next(e,n){const s=n.type,r=[];let i;const o=j(this,`candidates-${s}`,()=>Un(this,s));for(const a of o){const{guard:u}=a,c=e.context;let l=!1;try{l=!u||Dt(u,c,n,e)}catch(f){const p=typeof u=="string"?u:typeof u=="object"?u.type:void 0;throw new Error(`Unable to evaluate guard ${p?`'${p}' `:""}in transition for event '${s}' in state node '${this.id}':
|
|
3
|
-
${f.message}`)}if(l){r.push(...a.actions),i=a;break}}return i?[i]:void 0}get events(){return j(this,"events",()=>{const{states:e}=this,n=new Set(this.ownEvents);if(e)for(const s of Object.keys(e)){const r=e[s];if(r.states)for(const i of r.events)n.add(`${i}`)}return Array.from(n)})}get ownEvents(){const e=new Set([...this.transitions.keys()].filter(n=>this.transitions.get(n).some(s=>!(!s.target&&!s.actions.length&&!s.reenter))));return Array.from(e)}}const ms="#";class Lt{constructor(e,n){this.config=e,this.version=void 0,this.schemas=void 0,this.implementations=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.__TResolvedTypesMeta=void 0,this.id=e.id||"(machine)",this.implementations={actors:(n==null?void 0:n.actors)??{},actions:(n==null?void 0:n.actions)??{},delays:(n==null?void 0:n.delays)??{},guards:(n==null?void 0:n.guards)??{}},this.version=this.config.version,this.schemas=this.config.schemas,this.transition=this.transition.bind(this),this.getInitialSnapshot=this.getInitialSnapshot.bind(this),this.getPersistedSnapshot=this.getPersistedSnapshot.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new $t(e,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(e){const{actions:n,guards:s,actors:r,delays:i}=this.implementations;return new Lt(this.config,{actions:{...n,...e.actions},guards:{...s,...e.guards},actors:{...r,...e.actors},delays:{...i,...e.delays}})}resolveState(e){const n=Zn(this.root,e.value),s=rt(ot(this.root,n));return Q({_nodes:[...s],context:e.context||{},children:{},status:Ut(s,this.root)?"done":e.status||"active",output:e.output,error:e.error,historyValue:e.historyValue},this)}transition(e,n,s){return yt(e,n,s).snapshot}microstep(e,n,s){return yt(e,n,s).microstates}getTransitionData(e,n){return jt(this.root,e.value,e,n)||[]}getPreInitialState(e,n,s){const{context:r}=this.config,i=Q({context:typeof r!="function"&&r?r:{},_nodes:[this.root],children:{},status:"active"},this);return typeof r=="function"?H(i,n,e,[v(({spawn:a,event:u,self:c})=>r({spawn:a,input:u.input,self:c}))],s):i}getInitialSnapshot(e,n){const s=xe(n),r=[],i=this.getPreInitialState(e,s,r),o=bt([{target:[...je(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],i,e,s,!0,r),{snapshot:a}=yt(o,s,e,r);return a}start(e){Object.values(e.children).forEach(n=>{n.getSnapshot().status==="active"&&n.start()})}getStateNodeById(e){const n=It(e),s=n.slice(1),r=ct(n[0])?n[0].slice(ms.length):n[0],i=this.idMap.get(r);if(!i)throw new Error(`Child state node '#${r}' does not exist on machine '${this.id}'`);return it(i,s)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(e,n){return is(e,n)}restoreSnapshot(e,n){const s={},r=e.children;Object.keys(r).forEach(u=>{const c=r[u],l=c.snapshot,f=c.src,p=typeof f=="string"?Ct(this,f):f;if(!p)return;const y=L(p,{id:u,parent:n.self,syncSnapshot:c.syncSnapshot,snapshot:l,src:f,systemId:c.systemId});s[u]=y});const i=Q({...e,children:s,_nodes:Array.from(rt(ot(this.root,e.value)))},this);let o=new Set;function a(u,c){if(!o.has(u)){o.add(u);for(let l in u){const f=u[l];if(f&&typeof f=="object"){if("xstate$$type"in f&&f.xstate$$type===Pt){u[l]=c[f.id];continue}a(f,c)}}}}return a(i.context,s),i}}function gs(t,e){return new Lt(t,e)}function Bt({schemas:t,actors:e,actions:n,guards:s,delays:r}){return{createMachine:i=>gs({...i,schemas:t},{actors:e,actions:n,guards:s,delays:r})}}function He(t,e){return function(){return t.apply(e,arguments)}}const{toString:Ss}=Object.prototype,{getPrototypeOf:Ft}=Object,ut=(t=>e=>{const n=Ss.call(e);return t[n]||(t[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),A=t=>(t=t.toLowerCase(),e=>ut(e)===t),ft=t=>e=>typeof e===t,{isArray:z}=Array,V=ft("undefined");function Es(t){return t!==null&&!V(t)&&t.constructor!==null&&!V(t.constructor)&&T(t.constructor.isBuffer)&&t.constructor.isBuffer(t)}const qe=A("ArrayBuffer");function ws(t){let e;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?e=ArrayBuffer.isView(t):e=t&&t.buffer&&qe(t.buffer),e}const _s=ft("string"),T=ft("function"),ze=ft("number"),lt=t=>t!==null&&typeof t=="object",Ts=t=>t===!0||t===!1,tt=t=>{if(ut(t)!=="object")return!1;const e=Ft(t);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in t)&&!(Symbol.iterator in t)},vs=A("Date"),bs=A("File"),As=A("Blob"),xs=A("FileList"),Rs=t=>lt(t)&&T(t.pipe),Os=t=>{let e;return t&&(typeof FormData=="function"&&t instanceof FormData||T(t.append)&&((e=ut(t))==="formdata"||e==="object"&&T(t.toString)&&t.toString()==="[object FormData]"))},ks=A("URLSearchParams"),Is=t=>t.trim?t.trim():t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function X(t,e,{allOwnKeys:n=!1}={}){if(t===null||typeof t>"u")return;let s,r;if(typeof t!="object"&&(t=[t]),z(t))for(s=0,r=t.length;s<r;s++)e.call(null,t[s],s,t);else{const i=n?Object.getOwnPropertyNames(t):Object.keys(t),o=i.length;let a;for(s=0;s<o;s++)a=i[s],e.call(null,t[a],a,t)}}function Je(t,e){e=e.toLowerCase();const n=Object.keys(t);let s=n.length,r;for(;s-- >0;)if(r=n[s],e===r.toLowerCase())return r;return null}const We=(()=>typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global)(),Ke=t=>!V(t)&&t!==We;function At(){const{caseless:t}=Ke(this)&&this||{},e={},n=(s,r)=>{const i=t&&Je(e,r)||r;tt(e[i])&&tt(s)?e[i]=At(e[i],s):tt(s)?e[i]=At({},s):z(s)?e[i]=s.slice():e[i]=s};for(let s=0,r=arguments.length;s<r;s++)arguments[s]&&X(arguments[s],n);return e}const Cs=(t,e,n,{allOwnKeys:s}={})=>(X(e,(r,i)=>{n&&T(r)?t[i]=He(r,n):t[i]=r},{allOwnKeys:s}),t),Ps=t=>(t.charCodeAt(0)===65279&&(t=t.slice(1)),t),Ds=(t,e,n,s)=>{t.prototype=Object.create(e.prototype,s),t.prototype.constructor=t,Object.defineProperty(t,"super",{value:e.prototype}),n&&Object.assign(t.prototype,n)},Ms=(t,e,n,s)=>{let r,i,o;const a={};if(e=e||{},t==null)return e;do{for(r=Object.getOwnPropertyNames(t),i=r.length;i-- >0;)o=r[i],(!s||s(o,t,e))&&!a[o]&&(e[o]=t[o],a[o]=!0);t=n!==!1&&Ft(t)}while(t&&(!n||n(t,e))&&t!==Object.prototype);return e},Us=(t,e,n)=>{t=String(t),(n===void 0||n>t.length)&&(n=t.length),n-=e.length;const s=t.indexOf(e,n);return s!==-1&&s===n},js=t=>{if(!t)return null;if(z(t))return t;let e=t.length;if(!ze(e))return null;const n=new Array(e);for(;e-- >0;)n[e]=t[e];return n},Ns=(t=>e=>t&&e instanceof t)(typeof Uint8Array<"u"&&Ft(Uint8Array)),$s=(t,e)=>{const s=(t&&t[Symbol.iterator]).call(t);let r;for(;(r=s.next())&&!r.done;){const i=r.value;e.call(t,i[0],i[1])}},Ls=(t,e)=>{let n;const s=[];for(;(n=t.exec(e))!==null;)s.push(n);return s},Bs=A("HTMLFormElement"),Fs=t=>t.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,s,r){return s.toUpperCase()+r}),fe=(({hasOwnProperty:t})=>(e,n)=>t.call(e,n))(Object.prototype),Hs=A("RegExp"),Ve=(t,e)=>{const n=Object.getOwnPropertyDescriptors(t),s={};X(n,(r,i)=>{let o;(o=e(r,i,t))!==!1&&(s[i]=o||r)}),Object.defineProperties(t,s)},qs=t=>{Ve(t,(e,n)=>{if(T(t)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const s=t[n];if(T(s)){if(e.enumerable=!1,"writable"in e){e.writable=!1;return}e.set||(e.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},zs=(t,e)=>{const n={},s=r=>{r.forEach(i=>{n[i]=!0})};return z(t)?s(t):s(String(t).split(e)),n},Js=()=>{},Ws=(t,e)=>(t=+t,Number.isFinite(t)?t:e),gt="abcdefghijklmnopqrstuvwxyz",le="0123456789",Ge={DIGIT:le,ALPHA:gt,ALPHA_DIGIT:gt+gt.toUpperCase()+le},Ks=(t=16,e=Ge.ALPHA_DIGIT)=>{let n="";const{length:s}=e;for(;t--;)n+=e[Math.random()*s|0];return n};function Vs(t){return!!(t&&T(t.append)&&t[Symbol.toStringTag]==="FormData"&&t[Symbol.iterator])}const Gs=t=>{const e=new Array(10),n=(s,r)=>{if(lt(s)){if(e.indexOf(s)>=0)return;if(!("toJSON"in s)){e[r]=s;const i=z(s)?[]:{};return X(s,(o,a)=>{const u=n(o,r+1);!V(u)&&(i[a]=u)}),e[r]=void 0,i}}return s};return n(t,0)},Xs=A("AsyncFunction"),Ys=t=>t&&(lt(t)||T(t))&&T(t.then)&&T(t.catch),d={isArray:z,isArrayBuffer:qe,isBuffer:Es,isFormData:Os,isArrayBufferView:ws,isString:_s,isNumber:ze,isBoolean:Ts,isObject:lt,isPlainObject:tt,isUndefined:V,isDate:vs,isFile:bs,isBlob:As,isRegExp:Hs,isFunction:T,isStream:Rs,isURLSearchParams:ks,isTypedArray:Ns,isFileList:xs,forEach:X,merge:At,extend:Cs,trim:Is,stripBOM:Ps,inherits:Ds,toFlatObject:Ms,kindOf:ut,kindOfTest:A,endsWith:Us,toArray:js,forEachEntry:$s,matchAll:Ls,isHTMLForm:Bs,hasOwnProperty:fe,hasOwnProp:fe,reduceDescriptors:Ve,freezeMethods:qs,toObjectSet:zs,toCamelCase:Fs,noop:Js,toFiniteNumber:Ws,findKey:Je,global:We,isContextDefined:Ke,ALPHABET:Ge,generateString:Ks,isSpecCompliantForm:Vs,toJSONObject:Gs,isAsyncFn:Xs,isThenable:Ys};function g(t,e,n,s,r){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=t,this.name="AxiosError",e&&(this.code=e),n&&(this.config=n),s&&(this.request=s),r&&(this.response=r)}d.inherits(g,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:d.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});const Xe=g.prototype,Ye={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(t=>{Ye[t]={value:t}});Object.defineProperties(g,Ye);Object.defineProperty(Xe,"isAxiosError",{value:!0});g.from=(t,e,n,s,r,i)=>{const o=Object.create(Xe);return d.toFlatObject(t,o,function(u){return u!==Error.prototype},a=>a!=="isAxiosError"),g.call(o,t.message,e,n,s,r),o.cause=t,o.name=t.name,i&&Object.assign(o,i),o};const Zs=null;function xt(t){return d.isPlainObject(t)||d.isArray(t)}function Ze(t){return d.endsWith(t,"[]")?t.slice(0,-2):t}function de(t,e,n){return t?t.concat(e).map(function(r,i){return r=Ze(r),!n&&i?"["+r+"]":r}).join(n?".":""):e}function Qs(t){return d.isArray(t)&&!t.some(xt)}const tr=d.toFlatObject(d,{},null,function(e){return/^is[A-Z]/.test(e)});function dt(t,e,n){if(!d.isObject(t))throw new TypeError("target must be an object");e=e||new FormData,n=d.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,S){return!d.isUndefined(S[m])});const s=n.metaTokens,r=n.visitor||l,i=n.dots,o=n.indexes,u=(n.Blob||typeof Blob<"u"&&Blob)&&d.isSpecCompliantForm(e);if(!d.isFunction(r))throw new TypeError("visitor must be a function");function c(h){if(h===null)return"";if(d.isDate(h))return h.toISOString();if(!u&&d.isBlob(h))throw new g("Blob is not supported. Use a Buffer instead.");return d.isArrayBuffer(h)||d.isTypedArray(h)?u&&typeof Blob=="function"?new Blob([h]):Buffer.from(h):h}function l(h,m,S){let E=h;if(h&&!S&&typeof h=="object"){if(d.endsWith(m,"{}"))m=s?m:m.slice(0,-2),h=JSON.stringify(h);else if(d.isArray(h)&&Qs(h)||(d.isFileList(h)||d.endsWith(m,"[]"))&&(E=d.toArray(h)))return m=Ze(m),E.forEach(function(Z,fn){!(d.isUndefined(Z)||Z===null)&&e.append(o===!0?de([m],fn,i):o===null?m:m+"[]",c(Z))}),!1}return xt(h)?!0:(e.append(de(S,m,i),c(h)),!1)}const f=[],p=Object.assign(tr,{defaultVisitor:l,convertValue:c,isVisitable:xt});function y(h,m){if(!d.isUndefined(h)){if(f.indexOf(h)!==-1)throw Error("Circular reference detected in "+m.join("."));f.push(h),d.forEach(h,function(E,O){(!(d.isUndefined(E)||E===null)&&r.call(e,E,d.isString(O)?O.trim():O,m,p))===!0&&y(E,m?m.concat(O):[O])}),f.pop()}}if(!d.isObject(t))throw new TypeError("data must be an object");return y(t),e}function he(t){const e={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(t).replace(/[!'()~]|%20|%00/g,function(s){return e[s]})}function Ht(t,e){this._pairs=[],t&&dt(t,this,e)}const Qe=Ht.prototype;Qe.append=function(e,n){this._pairs.push([e,n])};Qe.toString=function(e){const n=e?function(s){return e.call(this,s,he)}:he;return this._pairs.map(function(r){return n(r[0])+"="+n(r[1])},"").join("&")};function er(t){return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function tn(t,e,n){if(!e)return t;const s=n&&n.encode||er,r=n&&n.serialize;let i;if(r?i=r(e,n):i=d.isURLSearchParams(e)?e.toString():new Ht(e,n).toString(s),i){const o=t.indexOf("#");o!==-1&&(t=t.slice(0,o)),t+=(t.indexOf("?")===-1?"?":"&")+i}return t}class nr{constructor(){this.handlers=[]}use(e,n,s){return this.handlers.push({fulfilled:e,rejected:n,synchronous:s?s.synchronous:!1,runWhen:s?s.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){d.forEach(this.handlers,function(s){s!==null&&e(s)})}}const pe=nr,en={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},sr=typeof URLSearchParams<"u"?URLSearchParams:Ht,rr=typeof FormData<"u"?FormData:null,ir=typeof Blob<"u"?Blob:null,or=(()=>{let t;return typeof navigator<"u"&&((t=navigator.product)==="ReactNative"||t==="NativeScript"||t==="NS")?!1:typeof window<"u"&&typeof document<"u"})(),ar=(()=>typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function")(),b={isBrowser:!0,classes:{URLSearchParams:sr,FormData:rr,Blob:ir},isStandardBrowserEnv:or,isStandardBrowserWebWorkerEnv:ar,protocols:["http","https","file","blob","url","data"]};function cr(t,e){return dt(t,new b.classes.URLSearchParams,Object.assign({visitor:function(n,s,r,i){return b.isNode&&d.isBuffer(n)?(this.append(s,n.toString("base64")),!1):i.defaultVisitor.apply(this,arguments)}},e))}function ur(t){return d.matchAll(/\w+|\[(\w*)]/g,t).map(e=>e[0]==="[]"?"":e[1]||e[0])}function fr(t){const e={},n=Object.keys(t);let s;const r=n.length;let i;for(s=0;s<r;s++)i=n[s],e[i]=t[i];return e}function nn(t){function e(n,s,r,i){let o=n[i++];const a=Number.isFinite(+o),u=i>=n.length;return o=!o&&d.isArray(r)?r.length:o,u?(d.hasOwnProp(r,o)?r[o]=[r[o],s]:r[o]=s,!a):((!r[o]||!d.isObject(r[o]))&&(r[o]=[]),e(n,s,r[o],i)&&d.isArray(r[o])&&(r[o]=fr(r[o])),!a)}if(d.isFormData(t)&&d.isFunction(t.entries)){const n={};return d.forEachEntry(t,(s,r)=>{e(ur(s),r,n,0)}),n}return null}function lr(t,e,n){if(d.isString(t))try{return(e||JSON.parse)(t),d.trim(t)}catch(s){if(s.name!=="SyntaxError")throw s}return(n||JSON.stringify)(t)}const qt={transitional:en,adapter:b.isNode?"http":"xhr",transformRequest:[function(e,n){const s=n.getContentType()||"",r=s.indexOf("application/json")>-1,i=d.isObject(e);if(i&&d.isHTMLForm(e)&&(e=new FormData(e)),d.isFormData(e))return r&&r?JSON.stringify(nn(e)):e;if(d.isArrayBuffer(e)||d.isBuffer(e)||d.isStream(e)||d.isFile(e)||d.isBlob(e))return e;if(d.isArrayBufferView(e))return e.buffer;if(d.isURLSearchParams(e))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let a;if(i){if(s.indexOf("application/x-www-form-urlencoded")>-1)return cr(e,this.formSerializer).toString();if((a=d.isFileList(e))||s.indexOf("multipart/form-data")>-1){const u=this.env&&this.env.FormData;return dt(a?{"files[]":e}:e,u&&new u,this.formSerializer)}}return i||r?(n.setContentType("application/json",!1),lr(e)):e}],transformResponse:[function(e){const n=this.transitional||qt.transitional,s=n&&n.forcedJSONParsing,r=this.responseType==="json";if(e&&d.isString(e)&&(s&&!this.responseType||r)){const o=!(n&&n.silentJSONParsing)&&r;try{return JSON.parse(e)}catch(a){if(o)throw a.name==="SyntaxError"?g.from(a,g.ERR_BAD_RESPONSE,this,null,this.response):a}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:b.classes.FormData,Blob:b.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};d.forEach(["delete","get","head","post","put","patch"],t=>{qt.headers[t]={}});const zt=qt,dr=d.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),hr=t=>{const e={};let n,s,r;return t&&t.split(`
|
|
4
|
-
|
|
5
|
-
`)}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...n){const s=new this(e);return n.forEach(r=>s.set(r)),s}static accessor(e){const s=(this[ye]=this[ye]={accessors:{}}).accessors,r=this.prototype;function i(o){const a=W(o);s[a]||(gr(r,o),s[a]=!0)}return d.isArray(e)?e.forEach(i):i(e),this}}ht.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);d.reduceDescriptors(ht.prototype,({value:t},e)=>{let n=e[0].toUpperCase()+e.slice(1);return{get:()=>t,set(s){this[n]=s}}});d.freezeMethods(ht);const R=ht;function Et(t,e){const n=this||zt,s=e||n,r=R.from(s.headers);let i=s.data;return d.forEach(t,function(a){i=a.call(n,i,r.normalize(),e?e.status:void 0)}),r.normalize(),i}function sn(t){return!!(t&&t.__CANCEL__)}function Y(t,e,n){g.call(this,t??"canceled",g.ERR_CANCELED,e,n),this.name="CanceledError"}d.inherits(Y,g,{__CANCEL__:!0});function Sr(t,e,n){const s=n.config.validateStatus;!n.status||!s||s(n.status)?t(n):e(new g("Request failed with status code "+n.status,[g.ERR_BAD_REQUEST,g.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}const Er=b.isStandardBrowserEnv?function(){return{write:function(n,s,r,i,o,a){const u=[];u.push(n+"="+encodeURIComponent(s)),d.isNumber(r)&&u.push("expires="+new Date(r).toGMTString()),d.isString(i)&&u.push("path="+i),d.isString(o)&&u.push("domain="+o),a===!0&&u.push("secure"),document.cookie=u.join("; ")},read:function(n){const s=document.cookie.match(new RegExp("(^|;\\s*)("+n+")=([^;]*)"));return s?decodeURIComponent(s[3]):null},remove:function(n){this.write(n,"",Date.now()-864e5)}}}():function(){return{write:function(){},read:function(){return null},remove:function(){}}}();function wr(t){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)}function _r(t,e){return e?t.replace(/\/+$/,"")+"/"+e.replace(/^\/+/,""):t}function rn(t,e){return t&&!wr(e)?_r(t,e):e}const Tr=b.isStandardBrowserEnv?function(){const e=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");let s;function r(i){let o=i;return e&&(n.setAttribute("href",o),o=n.href),n.setAttribute("href",o),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:n.pathname.charAt(0)==="/"?n.pathname:"/"+n.pathname}}return s=r(window.location.href),function(o){const a=d.isString(o)?r(o):o;return a.protocol===s.protocol&&a.host===s.host}}():function(){return function(){return!0}}();function vr(t){const e=/^([-+\w]{1,25})(:?\/\/|:)/.exec(t);return e&&e[1]||""}function br(t,e){t=t||10;const n=new Array(t),s=new Array(t);let r=0,i=0,o;return e=e!==void 0?e:1e3,function(u){const c=Date.now(),l=s[i];o||(o=c),n[r]=u,s[r]=c;let f=i,p=0;for(;f!==r;)p+=n[f++],f=f%t;if(r=(r+1)%t,r===i&&(i=(i+1)%t),c-o<e)return;const y=l&&c-l;return y?Math.round(p*1e3/y):void 0}}function me(t,e){let n=0;const s=br(50,250);return r=>{const i=r.loaded,o=r.lengthComputable?r.total:void 0,a=i-n,u=s(a),c=i<=o;n=i;const l={loaded:i,total:o,progress:o?i/o:void 0,bytes:a,rate:u||void 0,estimated:u&&o&&c?(o-i)/u:void 0,event:r};l[e?"download":"upload"]=!0,t(l)}}const Ar=typeof XMLHttpRequest<"u",xr=Ar&&function(t){return new Promise(function(n,s){let r=t.data;const i=R.from(t.headers).normalize(),o=t.responseType;let a;function u(){t.cancelToken&&t.cancelToken.unsubscribe(a),t.signal&&t.signal.removeEventListener("abort",a)}d.isFormData(r)&&(b.isStandardBrowserEnv||b.isStandardBrowserWebWorkerEnv?i.setContentType(!1):i.setContentType("multipart/form-data;",!1));let c=new XMLHttpRequest;if(t.auth){const y=t.auth.username||"",h=t.auth.password?unescape(encodeURIComponent(t.auth.password)):"";i.set("Authorization","Basic "+btoa(y+":"+h))}const l=rn(t.baseURL,t.url);c.open(t.method.toUpperCase(),tn(l,t.params,t.paramsSerializer),!0),c.timeout=t.timeout;function f(){if(!c)return;const y=R.from("getAllResponseHeaders"in c&&c.getAllResponseHeaders()),m={data:!o||o==="text"||o==="json"?c.responseText:c.response,status:c.status,statusText:c.statusText,headers:y,config:t,request:c};Sr(function(E){n(E),u()},function(E){s(E),u()},m),c=null}if("onloadend"in c?c.onloadend=f:c.onreadystatechange=function(){!c||c.readyState!==4||c.status===0&&!(c.responseURL&&c.responseURL.indexOf("file:")===0)||setTimeout(f)},c.onabort=function(){c&&(s(new g("Request aborted",g.ECONNABORTED,t,c)),c=null)},c.onerror=function(){s(new g("Network Error",g.ERR_NETWORK,t,c)),c=null},c.ontimeout=function(){let h=t.timeout?"timeout of "+t.timeout+"ms exceeded":"timeout exceeded";const m=t.transitional||en;t.timeoutErrorMessage&&(h=t.timeoutErrorMessage),s(new g(h,m.clarifyTimeoutError?g.ETIMEDOUT:g.ECONNABORTED,t,c)),c=null},b.isStandardBrowserEnv){const y=(t.withCredentials||Tr(l))&&t.xsrfCookieName&&Er.read(t.xsrfCookieName);y&&i.set(t.xsrfHeaderName,y)}r===void 0&&i.setContentType(null),"setRequestHeader"in c&&d.forEach(i.toJSON(),function(h,m){c.setRequestHeader(m,h)}),d.isUndefined(t.withCredentials)||(c.withCredentials=!!t.withCredentials),o&&o!=="json"&&(c.responseType=t.responseType),typeof t.onDownloadProgress=="function"&&c.addEventListener("progress",me(t.onDownloadProgress,!0)),typeof t.onUploadProgress=="function"&&c.upload&&c.upload.addEventListener("progress",me(t.onUploadProgress)),(t.cancelToken||t.signal)&&(a=y=>{c&&(s(!y||y.type?new Y(null,t,c):y),c.abort(),c=null)},t.cancelToken&&t.cancelToken.subscribe(a),t.signal&&(t.signal.aborted?a():t.signal.addEventListener("abort",a)));const p=vr(l);if(p&&b.protocols.indexOf(p)===-1){s(new g("Unsupported protocol "+p+":",g.ERR_BAD_REQUEST,t));return}c.send(r||null)})},nt={http:Zs,xhr:xr};d.forEach(nt,(t,e)=>{if(t){try{Object.defineProperty(t,"name",{value:e})}catch{}Object.defineProperty(t,"adapterName",{value:e})}});const on={getAdapter:t=>{t=d.isArray(t)?t:[t];const{length:e}=t;let n,s;for(let r=0;r<e&&(n=t[r],!(s=d.isString(n)?nt[n.toLowerCase()]:n));r++);if(!s)throw s===!1?new g(`Adapter ${n} is not supported by the environment`,"ERR_NOT_SUPPORT"):new Error(d.hasOwnProp(nt,n)?`Adapter '${n}' is not available in the build`:`Unknown adapter '${n}'`);if(!d.isFunction(s))throw new TypeError("adapter is not a function");return s},adapters:nt};function wt(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new Y(null,t)}function ge(t){return wt(t),t.headers=R.from(t.headers),t.data=Et.call(t,t.transformRequest),["post","put","patch"].indexOf(t.method)!==-1&&t.headers.setContentType("application/x-www-form-urlencoded",!1),on.getAdapter(t.adapter||zt.adapter)(t).then(function(s){return wt(t),s.data=Et.call(t,t.transformResponse,s),s.headers=R.from(s.headers),s},function(s){return sn(s)||(wt(t),s&&s.response&&(s.response.data=Et.call(t,t.transformResponse,s.response),s.response.headers=R.from(s.response.headers))),Promise.reject(s)})}const Se=t=>t instanceof R?t.toJSON():t;function q(t,e){e=e||{};const n={};function s(c,l,f){return d.isPlainObject(c)&&d.isPlainObject(l)?d.merge.call({caseless:f},c,l):d.isPlainObject(l)?d.merge({},l):d.isArray(l)?l.slice():l}function r(c,l,f){if(d.isUndefined(l)){if(!d.isUndefined(c))return s(void 0,c,f)}else return s(c,l,f)}function i(c,l){if(!d.isUndefined(l))return s(void 0,l)}function o(c,l){if(d.isUndefined(l)){if(!d.isUndefined(c))return s(void 0,c)}else return s(void 0,l)}function a(c,l,f){if(f in e)return s(c,l);if(f in t)return s(void 0,c)}const u={url:i,method:i,data:i,baseURL:o,transformRequest:o,transformResponse:o,paramsSerializer:o,timeout:o,timeoutMessage:o,withCredentials:o,adapter:o,responseType:o,xsrfCookieName:o,xsrfHeaderName:o,onUploadProgress:o,onDownloadProgress:o,decompress:o,maxContentLength:o,maxBodyLength:o,beforeRedirect:o,transport:o,httpAgent:o,httpsAgent:o,cancelToken:o,socketPath:o,responseEncoding:o,validateStatus:a,headers:(c,l)=>r(Se(c),Se(l),!0)};return d.forEach(Object.keys(Object.assign({},t,e)),function(l){const f=u[l]||r,p=f(t[l],e[l],l);d.isUndefined(p)&&f!==a||(n[l]=p)}),n}const an="1.5.0",Jt={};["object","boolean","number","function","string","symbol"].forEach((t,e)=>{Jt[t]=function(s){return typeof s===t||"a"+(e<1?"n ":" ")+t}});const Ee={};Jt.transitional=function(e,n,s){function r(i,o){return"[Axios v"+an+"] Transitional option '"+i+"'"+o+(s?". "+s:"")}return(i,o,a)=>{if(e===!1)throw new g(r(o," has been removed"+(n?" in "+n:"")),g.ERR_DEPRECATED);return n&&!Ee[o]&&(Ee[o]=!0,console.warn(r(o," has been deprecated since v"+n+" and will be removed in the near future"))),e?e(i,o,a):!0}};function Rr(t,e,n){if(typeof t!="object")throw new g("options must be an object",g.ERR_BAD_OPTION_VALUE);const s=Object.keys(t);let r=s.length;for(;r-- >0;){const i=s[r],o=e[i];if(o){const a=t[i],u=a===void 0||o(a,i,t);if(u!==!0)throw new g("option "+i+" must be "+u,g.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new g("Unknown option "+i,g.ERR_BAD_OPTION)}}const Rt={assertOptions:Rr,validators:Jt},k=Rt.validators;class at{constructor(e){this.defaults=e,this.interceptors={request:new pe,response:new pe}}request(e,n){typeof e=="string"?(n=n||{},n.url=e):n=e||{},n=q(this.defaults,n);const{transitional:s,paramsSerializer:r,headers:i}=n;s!==void 0&&Rt.assertOptions(s,{silentJSONParsing:k.transitional(k.boolean),forcedJSONParsing:k.transitional(k.boolean),clarifyTimeoutError:k.transitional(k.boolean)},!1),r!=null&&(d.isFunction(r)?n.paramsSerializer={serialize:r}:Rt.assertOptions(r,{encode:k.function,serialize:k.function},!0)),n.method=(n.method||this.defaults.method||"get").toLowerCase();let o=i&&d.merge(i.common,i[n.method]);i&&d.forEach(["delete","get","head","post","put","patch","common"],h=>{delete i[h]}),n.headers=R.concat(o,i);const a=[];let u=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(u=u&&m.synchronous,a.unshift(m.fulfilled,m.rejected))});const c=[];this.interceptors.response.forEach(function(m){c.push(m.fulfilled,m.rejected)});let l,f=0,p;if(!u){const h=[ge.bind(this),void 0];for(h.unshift.apply(h,a),h.push.apply(h,c),p=h.length,l=Promise.resolve(n);f<p;)l=l.then(h[f++],h[f++]);return l}p=a.length;let y=n;for(f=0;f<p;){const h=a[f++],m=a[f++];try{y=h(y)}catch(S){m.call(this,S);break}}try{l=ge.call(this,y)}catch(h){return Promise.reject(h)}for(f=0,p=c.length;f<p;)l=l.then(c[f++],c[f++]);return l}getUri(e){e=q(this.defaults,e);const n=rn(e.baseURL,e.url);return tn(n,e.params,e.paramsSerializer)}}d.forEach(["delete","get","head","options"],function(e){at.prototype[e]=function(n,s){return this.request(q(s||{},{method:e,url:n,data:(s||{}).data}))}});d.forEach(["post","put","patch"],function(e){function n(s){return function(i,o,a){return this.request(q(a||{},{method:e,headers:s?{"Content-Type":"multipart/form-data"}:{},url:i,data:o}))}}at.prototype[e]=n(),at.prototype[e+"Form"]=n(!0)});const st=at;class Wt{constructor(e){if(typeof e!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(i){n=i});const s=this;this.promise.then(r=>{if(!s._listeners)return;let i=s._listeners.length;for(;i-- >0;)s._listeners[i](r);s._listeners=null}),this.promise.then=r=>{let i;const o=new Promise(a=>{s.subscribe(a),i=a}).then(r);return o.cancel=function(){s.unsubscribe(i)},o},e(function(i,o,a){s.reason||(s.reason=new Y(i,o,a),n(s.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const n=this._listeners.indexOf(e);n!==-1&&this._listeners.splice(n,1)}static source(){let e;return{token:new Wt(function(r){e=r}),cancel:e}}}const Or=Wt;function kr(t){return function(n){return t.apply(null,n)}}function Ir(t){return d.isObject(t)&&t.isAxiosError===!0}const Ot={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Ot).forEach(([t,e])=>{Ot[e]=t});const Cr=Ot;function cn(t){const e=new st(t),n=He(st.prototype.request,e);return d.extend(n,st.prototype,e,{allOwnKeys:!0}),d.extend(n,e,null,{allOwnKeys:!0}),n.create=function(r){return cn(q(t,r))},n}const w=cn(zt);w.Axios=st;w.CanceledError=Y;w.CancelToken=Or;w.isCancel=sn;w.VERSION=an;w.toFormData=dt;w.AxiosError=g;w.Cancel=w.CanceledError;w.all=function(e){return Promise.all(e)};w.spread=kr;w.isAxiosError=Ir;w.mergeConfig=q;w.AxiosHeaders=R;w.formToJSON=t=>nn(d.isHTMLForm(t)?new FormData(t):t);w.getAdapter=on.getAdapter;w.HttpStatusCode=Cr;w.default=w;const Pr=w;async function we(t,e){const n=await fetch(t,e);return n.status===200?n.json():Promise.resolve({message:n.statusText,success:!1})}const kt=Bt({types:{context:{},events:{},input:{}},actions:{setUserContext:v(({context:t,event:e})=>{if(!e.type.includes("xstate.done.actor"))return t;const n=e;return n.output.type!=="AUTHENTICATE_SUCCESS"?t:{accessToken:n.output.accessToken,ignoreRefreshToken:!1}}),unsetUserContext:v(()=>({user:null,accessToken:"",refreshToken:"",ignoreRefreshToken:!1})),setAccessToken:v(({context:t,event:e})=>{if(!e.type.includes("xstate.done.actor"))return t;const n=e;return n.output.type!=="REFRESH_TOKEN_SUCCESS"?t:{accessToken:n.output.accessToken,ignoreRefreshToken:!1}}),unsetRefreshToken:v(()=>({refreshToken:""})),setIgnoreRefreshToken:v(()=>({ignoreRefreshToken:!0})),addError:v(({context:t,event:e})=>{if(!e.type.includes("xstate.error.actor"))return t;const n=e;return{errors:[...t.errors,String(n.error).replace("Error: ","")]}}),clearErrors:v(()=>({errors:[]}))},actors:{refreshAccessToken:mt(async({input:t})=>{let e;if(typeof window>"u"){if(t.context.refreshToken==="")throw new Error("Unauthorized.");try{const n=await Pr.post(t.context.endpoints.ssrRefresh,{},{headers:{Cookie:`refresh_token=${t.context.refreshToken}`,"Content-Type":"application/json","clicktap-scope":"view","clicktap-scope-id":"default"},withCredentials:!0});console.log("refreshAccessToken axios res",n);const{data:s}=n;if(console.log("refreshAccessToken axios res.data",s),typeof s.accessToken>"u")throw new Error("Unauthorized.");return{type:"REFRESH_TOKEN_SUCCESS",accessToken:s.accessToken}}catch(n){throw console.log(n),new Error("Could not complete refresh request (server)")}}else{e=await we(t.context.endpoints.refresh,{method:"POST",mode:"cors",credentials:"include",headers:{"Content-Type":"application/json","clicktap-scope":"view","clicktap-scope-id":"default"},body:JSON.stringify({grant_type:"refresh_token"}).toString()}),console.log("refreshAccessToken fetch response",e);const n=e;if(typeof n.accessToken>"u")throw new Error("Unauthorized.");return{type:"REFRESH_TOKEN_SUCCESS",accessToken:n.accessToken}}}),authenticate:mt(async({input:t})=>{var s;const n=await we(t.context.endpoints.login,{method:"POST",mode:"cors",credentials:"include",headers:{"Content-Type":"application/json","clicktap-scope":"view","clicktap-scope-id":"default"},body:JSON.stringify({username:t.username,password:t.password}).toString()});if(!n.success)throw new Error(((s=n.message)==null?void 0:s.toString())??"Sign in failed. Please try again.");return{type:"AUTHENTICATE_SUCCESS",accessToken:n.accessToken}}),unauthenticate:mt(async({input:t})=>(await fetch(t.context.endpoints.logout,{method:"POST",mode:"cors",credentials:"include",headers:{"clicktap-scope":"view","clicktap-scope-id":"default"}}),{type:"UNAUTHENTICATE"}))}}).createMachine({id:"auth",context:({input:t})=>{var e,n;return{user:null,accessToken:"",refreshToken:((e=t==null?void 0:t.initialContext)==null?void 0:e.refreshToken)??"",ignoreRefreshToken:!1,endpoints:((n=t==null?void 0:t.initialContext)==null?void 0:n.endpoints)??{login:"",logout:"",refresh:"",ssrRefresh:""},errors:[]}},initial:"refreshing",states:{authenticating:{invoke:{src:"authenticate",input:({context:t,event:e})=>e.type!=="LOGIN"?{context:t,username:"",password:""}:{context:t,username:e.username,password:e.password},onDone:[{actions:"setUserContext",target:"loggedIn"}],onError:[{actions:"addError",target:"loggedOut"}]}},unauthenticating:{invoke:{src:"unauthenticate",input:({context:t})=>({context:t}),onDone:[{actions:"unsetUserContext",target:"loggedOut"}],onError:[{actions:["unsetUserContext","setIgnoreRefreshToken"],target:"loggedOut"}]}},refreshing:{invoke:{src:"refreshAccessToken",input:({context:t})=>({context:t}),onDone:[{actions:["unsetRefreshToken","setAccessToken"],target:"loggedIn"}],onError:[{actions:"unsetRefreshToken",target:"unauthenticating"}]}},loggedOut:{on:{LOGIN:{target:"authenticating"},CLEAR_ERRORS:{actions:"clearErrors"}}},loggedIn:{after:{84e4:{guard:()=>typeof window<"u",target:"refreshing"}},on:{LOGOUT:{target:"unauthenticating"},CLEAR_ERRORS:{actions:"clearErrors"}}}}}),Kt=M.createContext({}),Dr=()=>{const t=M.useContext(Kt),[e,n]=M.useState(typeof window<"u"&&t.getSnapshot().value==="loggedIn");return M.useEffect(()=>{if(typeof window>"u")return;const s=t.subscribe(r=>{(r.value==="loggedIn"||r.value==="loggedOut")&&n(r.value==="loggedIn")});return()=>{s.unsubscribe()}},[t]),{authActor:t,isLoggedIn:e}},Mr=async(t="",e={inspect:void 0,endpoints:{login:"",logout:"",refresh:"",ssrRefresh:""}})=>typeof window<"u"?(console.warn("App.getInitialProps::getAuth should not be run on the frontend. You are probably missing getServerSideProps in your page."),L(kt,{inspect:e.inspect,input:{initialContext:{endpoints:e.endpoints}}}).start()):L(kt,{input:{initialContext:{endpoints:e.endpoints,refreshToken:t}},inspect:e.inspect}).start();function Ur({actor:t,children:e}){return _e.jsx(Kt.Provider,{value:t,children:e})}let jr=(t=21)=>crypto.getRandomValues(new Uint8Array(t)).reduce((e,n)=>(n&=63,n<36?e+=n.toString(36):n<62?e+=(n-26).toString(36).toUpperCase():n>62?e+="-":e+="_",e),"");const un=Bt({actors:{tick:us(({sendBack:t,input:e})=>{const n=setInterval(()=>{t({type:"TICK"})},e.interval);return()=>{clearInterval(n)}})},types:{context:{},events:{},input:{}}}).createMachine({id:"timer",initial:"running",context:({input:t})=>({elapsed:0,duration:t.initialContext.duration??3e3,interval:100,intervalId:null}),states:{paused:{on:{RESUME_TIMER:{target:"running",guard:({context:t})=>t.elapsed<t.duration}}},running:{invoke:{input:({context:t})=>({interval:t.interval}),src:"tick"},always:[{target:"completed",guard:({context:t})=>t.elapsed>=t.duration}],on:{TICK:{actions:v(({context:t,event:e})=>e.type!=="TICK"?t:{elapsed:t.elapsed+t.interval})},PAUSE_TIMER:{target:"paused"}}},completed:{type:"final"}}}),Nr=Bt({actors:{timer:un},types:{context:{},events:{},input:{}},actions:{addItem:v(({context:t,event:e})=>{if(e.type!=="ADD_ITEM")return t;const n=`notification-${jr()}`,s=e.duration??t.duration,r=M.cloneElement(e.item,{duration:s,id:n,key:e.item.key??n,...e.item.props}),i={duration:s,id:n,element:r},o=t.items;return t.order==="desc"?o.push(i):o.unshift(i),{items:o,activeItem:n}}),removeItem:v(({context:t,event:e})=>{if(e.type!=="REMOVE_ITEM"&&e.type!=="xstate.done.actor.timer")return t;const n=t.items;return t.order==="desc"?(n.pop(),{items:n,activeItem:n.length>0?n[n.length-1].id:null}):(n.shift(),{items:n,activeItem:n.length>0?n[0].id:null})})},delays:{ITEM_TIMEOUT:({context:t})=>t.items[t.items.length-1].duration??t.duration},guards:{itemHasTimeout:({context:t})=>t.items[t.items.length-1].duration>0||t.duration>0}}).createMachine({id:"toast",context:{items:[],order:"desc",duration:0,activeItem:null},initial:"idle",states:{idle:{on:{ADD_ITEM:{target:"adding"}}},active:{invoke:{id:"timer",src:"timer",input:({context:t})=>({initialContext:{duration:t.items[t.items.length-1].duration??t.duration}}),onDone:{target:"removing",guard:"itemHasTimeout"}},on:{ADD_ITEM:{target:"adding"},REMOVE_ITEM:{target:"removing"},SET_IDLE:{target:"idle"},RESUME_TIMER:{actions:ce("timer",{type:"RESUME_TIMER"})},PAUSE_TIMER:{actions:ce("timer",{type:"PAUSE_TIMER"})}}},adding:{entry:["addItem"],on:{SET_IDLE:{target:"idle"},SET_ACTIVE:{target:"active"}}},removing:{entry:"removeItem",on:{SET_IDLE:{target:"idle"},SET_ACTIVE:{target:"active"}}}}}),Vt=M.createContext({}),$r=()=>M.useContext(Vt);function Lr({children:t,actor:e}){return _e.jsx(Vt.Provider,{value:e,children:t})}exports.AuthContext=Kt;exports.AuthProvider=Ur;exports.ToastContext=Vt;exports.ToastProvider=Lr;exports.authMachine=kt;exports.getAuth=Mr;exports.timerMachine=un;exports.toastMachine=Nr;exports.useAuth=Dr;exports.useToast=$r;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Je=require("react/jsx-runtime"),F=require("react");function gn(e,t){for(var n=0;n<t.length;n++){const s=t[n];if(typeof s!="string"&&!Array.isArray(s)){for(const r in s)if(r!=="default"&&!(r in e)){const i=Object.getOwnPropertyDescriptor(s,r);i&&Object.defineProperty(e,r,i.get?i:{enumerable:!0,get:()=>s[r]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}function En(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global}function vn(){const e=En();if(e.__xstate__)return e.__xstate__}const Tn=e=>{if(typeof window>"u")return;const t=vn();t&&t.register(e)};class dt{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const n={value:t,next:null};if(this._current){this._last.next=n,this._last=n;return}this._current=n,this._last=n,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const Rt=".",_n="",Lt="",In="#",Sn="*",Mt="xstate.init",xn="xstate.error",ce="xstate.stop";function An(e,t){return{type:`xstate.after.${e}.${t}`}}function qe(e,t){return{type:`xstate.done.state.${e}`,output:t}}function wn(e,t){return{type:`xstate.done.actor.${e}`,output:t}}function Pt(e,t){return{type:`xstate.error.actor.${e}`,error:t}}function qt(e){return{type:Mt,input:e}}function q(e){setTimeout(()=>{throw e})}const bn=(()=>typeof Symbol=="function"&&Symbol.observable||"@@observable")();function lt(e,t){return`${e.sessionId}.${t}`}let On=0;function Nn(e,t){const n=new Map,s=new Map,r=new WeakMap,i=new Set,o={},{clock:a,logger:c}=t,u={schedule:(h,m,y,v,S=Math.random().toString(36).slice(2))=>{const A={source:h,target:m,event:y,delay:v,id:S,startedAt:Date.now()},R=lt(h,S);l._snapshot._scheduledEvents[R]=A;const D=a.setTimeout(()=>{delete o[R],delete l._snapshot._scheduledEvents[R],l._relay(h,m,y)},v);o[R]=D},cancel:(h,m)=>{const y=lt(h,m),v=o[y];delete o[y],delete l._snapshot._scheduledEvents[y],a.clearTimeout(v)},cancelAll:h=>{for(const m in l._snapshot._scheduledEvents){const y=l._snapshot._scheduledEvents[m];y.source===h&&u.cancel(h,y.id)}}},f=h=>{if(!i.size)return;const m={...h,rootId:e.sessionId};i.forEach(y=>{var v;return(v=y.next)==null?void 0:v.call(y,m)})},l={_snapshot:{_scheduledEvents:((t==null?void 0:t.snapshot)&&t.snapshot.scheduler)??{}},_bookId:()=>`x:${On++}`,_register:(h,m)=>(n.set(h,m),h),_unregister:h=>{n.delete(h.sessionId);const m=r.get(h);m!==void 0&&(s.delete(m),r.delete(h))},get:h=>s.get(h),_set:(h,m)=>{const y=s.get(h);if(y&&y!==m)throw new Error(`Actor with system ID '${h}' already exists.`);s.set(h,m),r.set(m,h)},inspect:h=>{i.add(h)},_sendInspectionEvent:f,_relay:(h,m,y)=>{l._sendInspectionEvent({type:"@xstate.event",sourceRef:h,actorRef:m,event:y}),m._send(y)},scheduler:u,getSnapshot:()=>({_scheduledEvents:{...l._snapshot._scheduledEvents}}),start:()=>{const h=l._snapshot._scheduledEvents;l._snapshot._scheduledEvents={};for(const m in h){const{source:y,target:v,event:S,delay:A,id:R}=h[m];u.schedule(y,v,S,A,R)}},_clock:a,_logger:c};return l}function Ft(e,t){const n=ht(e),s=ht(t);return typeof s=="string"?typeof n=="string"?s===n:!1:typeof n=="string"?n in s:Object.keys(n).every(r=>r in s?Ft(n[r],s[r]):!1)}function Ye(e){if(Bt(e))return e;let t=[],n="";for(let s=0;s<e.length;s++){switch(e.charCodeAt(s)){case 92:n+=e[s+1],s++;continue;case 46:t.push(n),n="";continue}n+=e[s]}return t.push(n),t}function ht(e){if(os(e))return e.value;if(typeof e!="string")return e;const t=Ye(e);return kn(t)}function kn(e){if(e.length===1)return e[0];const t={};let n=t;for(let s=0;s<e.length-1;s++)if(s===e.length-2)n[e[s]]=e[s+1];else{const r=n;n={},r[e[s]]=n}return t}function ft(e,t){const n={},s=Object.keys(e);for(let r=0;r<s.length;r++){const i=s[r];n[i]=t(e[i],i,e,r)}return n}function Ut(e){return Bt(e)?e:[e]}function U(e){return e===void 0?[]:Ut(e)}function Fe(e,t,n,s){return typeof e=="function"?e({context:t,event:n,self:s}):e}function Bt(e){return Array.isArray(e)}function Cn(e){return e.type.startsWith("xstate.error.actor")}function X(e){return Ut(e).map(t=>typeof t>"u"||typeof t=="string"?{target:t}:t)}function jt(e){if(!(e===void 0||e===_n))return U(e)}function pt(e,t,n){var i,o,a;const s=typeof e=="object",r=s?e:void 0;return{next:(i=s?e.next:e)==null?void 0:i.bind(r),error:(o=s?e.error:t)==null?void 0:o.bind(r),complete:(a=s?e.complete:n)==null?void 0:a.bind(r)}}function yt(e,t){return`${t}.${e}`}function Qe(e,t){const n=t.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!n)return e.implementations.actors[t];const[,s,r]=n,o=e.getStateNodeById(r).config.invoke;return(Array.isArray(o)?o[s]:o).src}const Xe=1;let k=function(e){return e[e.NotStarted=0]="NotStarted",e[e.Running=1]="Running",e[e.Stopped=2]="Stopped",e}({});const Dn={clock:{setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e)},logger:console.log.bind(console),devTools:!1};class Rn{constructor(t,n){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new dt(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=k.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const s={...Dn,...n},{clock:r,logger:i,parent:o,syncSnapshot:a,id:c,systemId:u,inspect:f}=s;this.system=o?o.system:Nn(this,{clock:r,logger:i}),f&&!o&&this.system.inspect(pt(f)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=(n==null?void 0:n.logger)??this.system._logger,this.clock=(n==null?void 0:n.clock)??this.system._clock,this._parent=o,this._syncSnapshot=a,this.options=s,this.src=s.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:l=>{this._deferred.push(l)},system:this.system,stopChild:l=>{if(l._parent!==this)throw new Error(`Cannot stop child actor ${l.id} of ${this.id} because it is not a child`);l._stop()},emit:l=>{const h=this.eventListeners.get(l.type);if(h)for(const m of Array.from(h))m(l)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),u&&(this._systemId=u,this.system._set(u,this)),this._initState((n==null?void 0:n.snapshot)??(n==null?void 0:n.state)),u&&this._snapshot.status!=="active"&&this.system._unregister(this)}_initState(t){var n;try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,(n=this.options)==null?void 0:n.input)}catch(s){this._snapshot={status:"error",output:void 0,error:s}}}update(t,n){var r,i;this._snapshot=t;let s;for(;s=this._deferred.shift();)try{s()}catch(o){this._deferred.length=0,this._snapshot={...t,status:"error",error:o}}switch(this._snapshot.status){case"active":for(const o of this.observers)try{(r=o.next)==null||r.call(o,t)}catch(a){q(a)}break;case"done":for(const o of this.observers)try{(i=o.next)==null||i.call(o,t)}catch(a){q(a)}this._stopProcedure(),this._complete(),this._doneEvent=wn(this.id,this._snapshot.output),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error);break}this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:n,snapshot:t})}subscribe(t,n,s){var i;const r=pt(t,n,s);if(this._processingStatus!==k.Stopped)this.observers.add(r);else switch(this._snapshot.status){case"done":try{(i=r.complete)==null||i.call(r)}catch(o){q(o)}break;case"error":{const o=this._snapshot.error;if(!r.error)q(o);else try{r.error(o)}catch(a){q(a)}break}}return{unsubscribe:()=>{this.observers.delete(r)}}}on(t,n){let s=this.eventListeners.get(t);s||(s=new Set,this.eventListeners.set(t,s));const r=n.bind(void 0);return s.add(r),{unsubscribe:()=>{s.delete(r)}}}start(){if(this._processingStatus===k.Running)return this;this._syncSnapshot&&this.subscribe({next:s=>{s.status==="active"&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:s})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=k.Running;const t=qt(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t}),this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(s){return this._snapshot={...this._snapshot,status:"error",error:s},this._error(s),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let n,s;try{n=this.logic.transition(this._snapshot,t,this._actorScope)}catch(r){s={err:r}}if(s){const{err:r}=s;this._snapshot={...this._snapshot,status:"error",error:r},this._error(r);return}this.update(n,t),t.type===ce&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===k.Stopped?this:(this.mailbox.clear(),this._processingStatus===k.NotStarted?(this._processingStatus=k.Stopped,this):(this.mailbox.enqueue({type:ce}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){var t;for(const n of this.observers)try{(t=n.complete)==null||t.call(n)}catch(s){q(s)}this.observers.clear()}_reportError(t){if(!this.observers.size){this._parent||q(t);return}let n=!1;for(const s of this.observers){const r=s.error;n||(n=!r);try{r==null||r(t)}catch(i){q(i)}}this.observers.clear(),n&&q(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,Pt(this.id,t))}_stopProcedure(){return this._processingStatus!==k.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new dt(this._process.bind(this)),this._processingStatus=k.Stopped,this.system._unregister(this),this)}_send(t){this._processingStatus!==k.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}attachDevTools(){const{devTools:t}=this.options;t&&(typeof t=="function"?t:Tn)(this)}toJSON(){return{xstate$$type:Xe,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[bn](){return this}getSnapshot(){return this._snapshot}}function B(e,...[t]){return new Rn(e,t)}function Ln(e,t,n,s,{sendId:r}){const i=typeof r=="function"?r(n,s):r;return[t,i]}function Mn(e,t){e.defer(()=>{e.system.scheduler.cancel(e.self,t)})}function Pn(e){function t(n,s){}return t.type="xstate.cancel",t.sendId=e,t.resolve=Ln,t.execute=Mn,t}function qn(e,t,n,s,{id:r,systemId:i,src:o,input:a,syncSnapshot:c}){const u=typeof o=="string"?Qe(t.machine,o):o,f=typeof r=="function"?r(n):r;let l;return u&&(l=B(u,{id:f,src:o,parent:e.self,syncSnapshot:c,systemId:i,input:typeof a=="function"?a({context:t.context,event:n.event,self:e.self}):a})),[G(t,{children:{...t.children,[f]:l}}),{id:r,actorRef:l}]}function Fn(e,{id:t,actorRef:n}){n&&e.defer(()=>{n._processingStatus!==k.Stopped&&n.start()})}function Un(...[e,{id:t,systemId:n,input:s,syncSnapshot:r=!1}={}]){function i(o,a){}return i.type="snapshot.spawnChild",i.id=t,i.systemId=n,i.src=e,i.input=s,i.syncSnapshot=r,i.resolve=qn,i.execute=Fn,i}function Bn(e,t,n,s,{actorRef:r}){const i=typeof r=="function"?r(n,s):r,o=typeof i=="string"?t.children[i]:i;let a=t.children;return o&&(a={...a},delete a[o.id]),[G(t,{children:a}),o]}function jn(e,t){if(t){if(e.system._unregister(t),t._processingStatus!==k.Running){e.stopChild(t);return}e.defer(()=>{e.stopChild(t)})}}function $t(e){function t(n,s){}return t.type="xstate.stopChild",t.actorRef=e,t.resolve=Bn,t.execute=jn,t}function We(e,t,n,s){const{machine:r}=s,i=typeof e=="function",o=i?e:r.implementations.guards[typeof e=="string"?e:e.type];if(!i&&!o)throw new Error(`Guard '${typeof e=="string"?e:e.type}' is not implemented.'.`);if(typeof o!="function")return We(o,t,n,s);const a={context:t,event:n},c=i||typeof e=="string"?void 0:"params"in e?typeof e.params=="function"?e.params({context:t,event:n}):e.params:void 0;return"check"in o?o.check(s,a,o):o(a,c)}const Ke=e=>e.type==="atomic"||e.type==="final";function ee(e){return Object.values(e.states).filter(t=>t.type!=="history")}function de(e,t){const n=[];if(t===e)return n;let s=e.parent;for(;s&&s!==t;)n.push(s),s=s.parent;return n}function Te(e){const t=new Set(e),n=Ht(t);for(const s of t)if(s.type==="compound"&&(!n.get(s)||!n.get(s).length))mt(s).forEach(r=>t.add(r));else if(s.type==="parallel"){for(const r of ee(s))if(r.type!=="history"&&!t.has(r)){const i=mt(r);for(const o of i)t.add(o)}}for(const s of t){let r=s.parent;for(;r;)t.add(r),r=r.parent}return t}function Vt(e,t){const n=t.get(e);if(!n)return{};if(e.type==="compound"){const r=n[0];if(r){if(Ke(r))return r.key}else return{}}const s={};for(const r of n)s[r.key]=Vt(r,t);return s}function Ht(e){const t=new Map;for(const n of e)t.has(n)||t.set(n,[]),n.parent&&(t.has(n.parent)||t.set(n.parent,[]),t.get(n.parent).push(n));return t}function Gt(e,t){const n=Te(t);return Vt(e,Ht(n))}function Ze(e,t){return t.type==="compound"?ee(t).some(n=>n.type==="final"&&e.has(n)):t.type==="parallel"?ee(t).every(n=>Ze(e,n)):t.type==="final"}const xe=e=>e[0]===In;function $n(e,t){return e.transitions.get(t)||[...e.transitions.keys()].filter(s=>{if(s===Sn)return!0;if(!s.endsWith(".*"))return!1;const r=s.split("."),i=t.split(".");for(let o=0;o<r.length;o++){const a=r[o],c=i[o];if(a==="*")return o===r.length-1;if(a!==c)return!1}return!0}).sort((s,r)=>r.length-s.length).flatMap(s=>e.transitions.get(s))}function Vn(e){const t=e.config.after;if(!t)return[];const n=(r,i)=>{const o=An(r,e.id),a=o.type;return e.entry.push(ys(o,{id:a,delay:r})),e.exit.push(Pn(a)),a};return Object.keys(t).flatMap((r,i)=>{const o=t[r],a=typeof o=="string"?{target:o}:o,c=Number.isNaN(+r)?r:+r,u=n(c);return U(a).map(f=>({...f,event:u,delay:c}))}).map(r=>{const{delay:i}=r;return{...V(e,r.event,r),delay:i}})}function V(e,t,n){const s=jt(n.target),r=n.reenter??!1,i=zn(e,s),o={...n,actions:U(n.actions),guard:n.guard,target:i,source:e,reenter:r,eventType:t,toJSON:()=>({...o,source:`#${e.id}`,target:i?i.map(a=>`#${a.id}`):void 0})};return o}function Hn(e){const t=new Map;if(e.config.on)for(const n of Object.keys(e.config.on)){if(n===Lt)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const s=e.config.on[n];t.set(n,X(s).map(r=>V(e,n,r)))}if(e.config.onDone){const n=`xstate.done.state.${e.id}`;t.set(n,X(e.config.onDone).map(s=>V(e,n,s)))}for(const n of e.invoke){if(n.onDone){const s=`xstate.done.actor.${n.id}`;t.set(s,X(n.onDone).map(r=>V(e,s,r)))}if(n.onError){const s=`xstate.error.actor.${n.id}`;t.set(s,X(n.onError).map(r=>V(e,s,r)))}if(n.onSnapshot){const s=`xstate.snapshot.${n.id}`;t.set(s,X(n.onSnapshot).map(r=>V(e,s,r)))}}for(const n of e.after){let s=t.get(n.eventType);s||(s=[],t.set(n.eventType,s)),s.push(n)}return t}function Gn(e,t){const n=typeof t=="string"?e.states[t]:t?e.states[t.target]:void 0;if(!n&&t)throw new Error(`Initial state node "${t}" not found on parent state node #${e.id}`);const s={source:e,actions:!t||typeof t=="string"?[]:U(t.actions),eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...s,source:`#${e.id}`,target:n?[`#${n.id}`]:[]})};return s}function zn(e,t){if(t!==void 0)return t.map(n=>{if(typeof n!="string")return n;if(xe(n))return e.machine.getStateNodeById(n);const s=n[0]===Rt;if(s&&!e.parent)return _e(e,n.slice(1));const r=s?e.key+n:n;if(e.parent)try{return _e(e.parent,r)}catch(i){throw new Error(`Invalid transition definition for state node '${e.id}':
|
|
2
|
+
${i.message}`)}else throw new Error(`Invalid target: "${n}" is not a valid target from the root node. Did you mean ".${n}"?`)})}function zt(e){const t=jt(e.config.target);return t?{target:t.map(n=>typeof n=="string"?_e(e.parent,n):n)}:e.parent.initial}function H(e){return e.type==="history"}function mt(e){const t=Jt(e);for(const n of t)for(const s of de(n,e))t.add(s);return t}function Jt(e){const t=new Set;function n(s){if(!t.has(s)){if(t.add(s),s.type==="compound")n(s.initial.target[0]);else if(s.type==="parallel")for(const r of ee(s))n(r)}}return n(e),t}function te(e,t){if(xe(t))return e.machine.getStateNodeById(t);if(!e.states)throw new Error(`Unable to retrieve child state '${t}' from '${e.id}'; no child states exist.`);const n=e.states[t];if(!n)throw new Error(`Child state '${t}' does not exist on '${e.id}'`);return n}function _e(e,t){if(typeof t=="string"&&xe(t))try{return e.machine.getStateNodeById(t)}catch{}const n=Ye(t).slice();let s=e;for(;n.length;){const r=n.shift();if(!r.length)break;s=te(s,r)}return s}function Ie(e,t){if(typeof t=="string"){const r=e.states[t];if(!r)throw new Error(`State '${t}' does not exist on '${e.id}'`);return[e,r]}const n=Object.keys(t),s=n.map(r=>te(e,r)).filter(Boolean);return[e.machine.root,e].concat(s,n.reduce((r,i)=>{const o=te(e,i);if(!o)return r;const a=Ie(o,t[i]);return r.concat(a)},[]))}function Jn(e,t,n,s){const i=te(e,t).next(n,s);return!i||!i.length?e.next(n,s):i}function Yn(e,t,n,s){const r=Object.keys(t),i=te(e,r[0]),o=et(i,t[r[0]],n,s);return!o||!o.length?e.next(n,s):o}function Qn(e,t,n,s){const r=[];for(const i of Object.keys(t)){const o=t[i];if(!o)continue;const a=te(e,i),c=et(a,o,n,s);c&&r.push(...c)}return r.length?r:e.next(n,s)}function et(e,t,n,s){return typeof t=="string"?Jn(e,t,n,s):Object.keys(t).length===1?Yn(e,t,n,s):Qn(e,t,n,s)}function Xn(e){return Object.keys(e.states).map(t=>e.states[t]).filter(t=>t.type==="history")}function j(e,t){let n=e;for(;n.parent&&n.parent!==t;)n=n.parent;return n.parent===t}function Wn(e,t){const n=new Set(e),s=new Set(t);for(const r of n)if(s.has(r))return!0;for(const r of s)if(n.has(r))return!0;return!1}function Yt(e,t,n){const s=new Set;for(const r of e){let i=!1;const o=new Set;for(const a of s)if(Wn(Ue([r],t,n),Ue([a],t,n)))if(j(r.source,a.source))o.add(a);else{i=!0;break}if(!i){for(const a of o)s.delete(a);s.add(r)}}return Array.from(s)}function Kn(e){const[t,...n]=e;for(const s of de(t,void 0))if(n.every(r=>j(r,s)))return s}function tt(e,t){if(!e.target)return[];const n=new Set;for(const s of e.target)if(H(s))if(t[s.id])for(const r of t[s.id])n.add(r);else for(const r of tt(zt(s),t))n.add(r);else n.add(s);return[...n]}function Qt(e,t){const n=tt(e,t);if(!n)return;if(!e.reenter&&n.every(r=>r===e.source||j(r,e.source)))return e.source;const s=Kn(n.concat(e.source));if(s)return s;if(!e.reenter)return e.source.machine.root}function Ue(e,t,n){var r;const s=new Set;for(const i of e)if((r=i.target)!=null&&r.length){const o=Qt(i,n);i.reenter&&i.source===o&&s.add(o);for(const a of t)j(a,o)&&s.add(a)}return[...s]}function Zn(e,t){if(e.length!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function Be(e,t,n,s,r,i){if(!e.length)return t;const o=new Set(t._nodes);let a=t.historyValue;const c=Yt(e,o,a);let u=t;r||([u,a]=ss(u,s,n,c,o,a,i)),u=ne(u,s,n,c.flatMap(l=>l.actions),i),u=ts(u,s,n,c,o,i,a,r);const f=[...o];u.status==="done"&&(u=ne(u,s,n,f.sort((l,h)=>h.order-l.order).flatMap(l=>l.exit),i));try{return a===t.historyValue&&Zn(t._nodes,o)?u:G(u,{_nodes:f,historyValue:a})}catch(l){throw l}}function es(e,t,n,s,r){if(s.output===void 0)return;const i=qe(r.id,r.output!==void 0&&r.parent?Fe(r.output,e.context,t,n.self):void 0);return Fe(s.output,e.context,i,n.self)}function ts(e,t,n,s,r,i,o,a){let c=e;const u=new Set,f=new Set;ns(s,o,f,u),a&&f.add(e.machine.root);const l=new Set;for(const h of[...u].sort((m,y)=>m.order-y.order)){r.add(h);const m=[];m.push(...h.entry);for(const y of h.invoke)m.push(Un(y.src,{...y,syncSnapshot:!!y.onSnapshot}));if(f.has(h)){const y=h.initial.actions;m.push(...y)}if(c=ne(c,t,n,m,i,h.invoke.map(y=>y.id)),h.type==="final"){const y=h.parent;let v=(y==null?void 0:y.type)==="parallel"?y:y==null?void 0:y.parent,S=v||h;for((y==null?void 0:y.type)==="compound"&&i.push(qe(y.id,h.output!==void 0?Fe(h.output,c.context,t,n.self):void 0));(v==null?void 0:v.type)==="parallel"&&!l.has(v)&&Ze(r,v);)l.add(v),i.push(qe(v.id)),S=v,v=v.parent;if(v)continue;c=G(c,{status:"done",output:es(c,t,n,c.machine.root,S)})}}return c}function ns(e,t,n,s){for(const r of e){const i=Qt(r,t);for(const a of r.target||[])!H(a)&&(r.source!==a||r.source!==i||r.reenter)&&(s.add(a),n.add(a)),W(a,t,n,s);const o=tt(r,t);for(const a of o){const c=de(a,i);(i==null?void 0:i.type)==="parallel"&&c.push(i),Xt(s,t,n,c,!r.source.parent&&r.reenter?void 0:i)}}}function W(e,t,n,s){var r;if(H(e))if(t[e.id]){const i=t[e.id];for(const o of i)s.add(o),W(o,t,n,s);for(const o of i)ke(o,e.parent,s,t,n)}else{const i=zt(e);for(const o of i.target)s.add(o),i===((r=e.parent)==null?void 0:r.initial)&&n.add(e.parent),W(o,t,n,s);for(const o of i.target)ke(o,e.parent,s,t,n)}else if(e.type==="compound"){const[i]=e.initial.target;H(i)||(s.add(i),n.add(i)),W(i,t,n,s),ke(i,e,s,t,n)}else if(e.type==="parallel")for(const i of ee(e).filter(o=>!H(o)))[...s].some(o=>j(o,i))||(H(i)||(s.add(i),n.add(i)),W(i,t,n,s))}function Xt(e,t,n,s,r){for(const i of s)if((!r||j(i,r))&&e.add(i),i.type==="parallel")for(const o of ee(i).filter(a=>!H(a)))[...e].some(a=>j(a,o))||(e.add(o),W(o,t,n,e))}function ke(e,t,n,s,r){Xt(n,s,r,de(e,t))}function ss(e,t,n,s,r,i,o){let a=e;const c=Ue(s,r,i);c.sort((f,l)=>l.order-f.order);let u;for(const f of c)for(const l of Xn(f)){let h;l.history==="deep"?h=m=>Ke(m)&&j(m,f):h=m=>m.parent===f,u??(u={...i}),u[l.id]=Array.from(r).filter(h)}for(const f of c)a=ne(a,t,n,[...f.exit,...f.invoke.map(l=>$t(l.id))],o),r.delete(f);return[a,u||i]}let gt=!1;function Wt(e,t,n,s,r,i){const{machine:o}=e;let a=e;for(const c of s){let m=function(){n.system._sendInspectionEvent({type:"@xstate.action",actorRef:n.self,action:{type:typeof c=="string"?c:typeof c=="object"?c.type:c.name||"(anonymous)",params:h}});try{gt=f,f(l,h)}finally{gt=!1}};const u=typeof c=="function",f=u?c:o.implementations.actions[typeof c=="string"?c:c.type];if(!f)continue;const l={context:a.context,event:t,self:n.self,system:n.system},h=u||typeof c=="string"?void 0:"params"in c?typeof c.params=="function"?c.params({context:a.context,event:t}):c.params:void 0;if(!("resolve"in f)){n.self._processingStatus===k.Running?m():n.defer(()=>{m()});continue}const y=f,[v,S,A]=y.resolve(n,a,l,h,f,r);a=v,"retryResolve"in y&&(i==null||i.push([y,S])),"execute"in y&&(n.self._processingStatus===k.Running?y.execute(n,S):n.defer(y.execute.bind(null,n,S))),A&&(a=Wt(a,t,n,A,r,i))}return a}function ne(e,t,n,s,r,i){const o=i?[]:void 0,a=Wt(e,t,n,s,{internalQueue:r,deferredActorIds:i},o);return o==null||o.forEach(([c,u])=>{c.retryResolve(n,a,u)}),a}function Ce(e,t,n,s=[]){let r=e;const i=[];function o(u,f,l){n.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:n.self,event:f,snapshot:u,_transitions:l}),i.push(u)}if(t.type===ce)return r=G(Et(r,t,n),{status:"stopped"}),o(r,t,[]),{snapshot:r,microstates:i};let a=t;if(a.type!==Mt){const u=a,f=Cn(u),l=vt(u,r);if(f&&!l.length)return r=G(e,{status:"error",error:u.error}),o(r,u,[]),{snapshot:r,microstates:i};r=Be(l,e,n,a,!1,s),o(r,u,l)}let c=!0;for(;r.status==="active";){let u=c?rs(r,a):[];const f=u.length?r:void 0;if(!u.length){if(!s.length)break;a=s.shift(),u=vt(a,r)}r=Be(u,r,n,a,!1,s),c=r!==f,o(r,a,u)}return r.status!=="active"&&Et(r,a,n),{snapshot:r,microstates:i}}function Et(e,t,n){return ne(e,t,n,Object.values(e.children).map(s=>$t(s)),[])}function vt(e,t){return t.machine.getTransitionData(t,e)}function rs(e,t){const n=new Set,s=e._nodes.filter(Ke);for(const r of s)e:for(const i of[r].concat(de(r,void 0)))if(i.always){for(const o of i.always)if(o.guard===void 0||We(o.guard,e.context,t,e)){n.add(o);break e}}return Yt(Array.from(n),new Set(e._nodes),e.historyValue)}function is(e,t){const n=Te(Ie(e,t));return Gt(e,[...n])}function os(e){return!!e&&typeof e=="object"&&"machine"in e&&"value"in e}const as=function(t){return Ft(t,this.value)},cs=function(t){return this.tags.has(t)},us=function(t){const n=this.machine.getTransitionData(this,t);return!!(n!=null&&n.length)&&n.some(s=>s.target!==void 0||s.actions.length)},ds=function(){const{_nodes:t,tags:n,machine:s,getMeta:r,toJSON:i,can:o,hasTag:a,matches:c,...u}=this;return{...u,tags:Array.from(n)}},ls=function(){return this._nodes.reduce((t,n)=>(n.meta!==void 0&&(t[n.id]=n.meta),t),{})};function me(e,t){return{status:e.status,output:e.output,error:e.error,machine:t,context:e.context,_nodes:e._nodes,value:Gt(t.root,e._nodes),tags:new Set(e._nodes.flatMap(n=>n.tags)),children:e.children,historyValue:e.historyValue||{},matches:as,hasTag:cs,can:us,getMeta:ls,toJSON:ds}}function G(e,t={}){return me({...e,...t},e.machine)}function hs(e,t){const{_nodes:n,tags:s,machine:r,children:i,context:o,can:a,hasTag:c,matches:u,getMeta:f,toJSON:l,...h}=e,m={};for(const v in i){const S=i[v];m[v]={snapshot:S.getPersistedSnapshot(t),src:S.src,systemId:S._systemId,syncSnapshot:S._syncSnapshot}}return{...h,context:Kt(o),children:m}}function Kt(e){let t;for(const n in e){const s=e[n];if(s&&typeof s=="object")if("sessionId"in s&&"send"in s&&"ref"in s)t??(t=Array.isArray(e)?e.slice():{...e}),t[n]={xstate$$type:Xe,id:s.id};else{const r=Kt(s);r!==s&&(t??(t=Array.isArray(e)?e.slice():{...e}),t[n]=r)}}return t??e}function fs(e,t,n,s,{event:r,id:i,delay:o},{internalQueue:a}){const c=t.machine.implementations.delays;if(typeof r=="string")throw new Error(`Only event objects may be used with raise; use raise({ type: "${r}" }) instead`);const u=typeof r=="function"?r(n,s):r;let f;if(typeof o=="string"){const l=c&&c[o];f=typeof l=="function"?l(n,s):l}else f=typeof o=="function"?o(n,s):o;return typeof f!="number"&&a.push(u),[t,{event:u,id:i,delay:f}]}function ps(e,t){const{event:n,delay:s,id:r}=t;if(typeof s=="number"){e.defer(()=>{const i=e.self;e.system.scheduler.schedule(i,i,n,s,r)});return}}function ys(e,t){function n(s,r){}return n.type="xstate.raise",n.event=e,n.id=t==null?void 0:t.id,n.delay=t==null?void 0:t.delay,n.resolve=fs,n.execute=ps,n}const Tt=new WeakMap;function ms(e){return{config:e,start:(n,s)=>{const{self:r,system:i}=s,o={receivers:void 0,dispose:void 0};Tt.set(r,o),o.dispose=e({input:n.input,system:i,self:r,sendBack:a=>{r.getSnapshot().status!=="stopped"&&r._parent&&i._relay(r,r._parent,a)},receive:a=>{o.receivers??(o.receivers=new Set),o.receivers.add(a)}})},transition:(n,s,r)=>{var o,a;const i=Tt.get(r.self);return s.type===ce?(n={...n,status:"stopped",error:void 0},(o=i.dispose)==null||o.call(i),n):((a=i.receivers)==null||a.forEach(c=>c(s)),n)},getInitialSnapshot:(n,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:n=>n,restoreSnapshot:n=>n}}const _t="xstate.promise.resolve",It="xstate.promise.reject",pe=new WeakMap;function Z(e){return{config:e,transition:(n,s,r)=>{var i;if(n.status!=="active")return n;switch(s.type){case _t:{const o=s.data;return{...n,status:"done",output:o,input:void 0}}case It:return{...n,status:"error",error:s.data,input:void 0};case ce:return(i=pe.get(r.self))==null||i.abort(),{...n,status:"stopped",input:void 0};default:return n}},start:(n,{self:s,system:r})=>{if(n.status!=="active")return;const i=new AbortController;pe.set(s,i),Promise.resolve(e({input:n.input,system:r,self:s,signal:i.signal})).then(a=>{s.getSnapshot().status==="active"&&(pe.delete(s),r._relay(s,s,{type:_t,data:a}))},a=>{s.getSnapshot().status==="active"&&(pe.delete(s),r._relay(s,s,{type:It,data:a}))})},getInitialSnapshot:(n,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:n=>n,restoreSnapshot:n=>n}}function gs(e,{machine:t,context:n},s,r){const i=(o,a={})=>{const{systemId:c,input:u}=a;if(typeof o=="string"){const f=Qe(t,o);if(!f)throw new Error(`Actor logic '${o}' not implemented in machine '${t.id}'`);const l=B(f,{id:a.id,parent:e.self,syncSnapshot:a.syncSnapshot,input:typeof u=="function"?u({context:n,event:s,self:e.self}):u,src:o,systemId:c});return r[l.id]=l,l}else return B(o,{id:a.id,parent:e.self,syncSnapshot:a.syncSnapshot,input:a.input,src:o,systemId:c})};return(o,a)=>{const c=i(o,a);return r[c.id]=c,e.defer(()=>{c._processingStatus!==k.Stopped&&c.start()}),c}}function Es(e,t,n,s,{assignment:r}){if(!t.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},o={context:t.context,event:n.event,spawn:gs(e,t,n.event,i),self:e.self,system:e.system};let a={};if(typeof r=="function")a=r(o,s);else for(const u of Object.keys(r)){const f=r[u];a[u]=typeof f=="function"?f(o,s):f}const c=Object.assign({},t.context,a);return[G(t,{context:c,children:Object.keys(i).length?{...t.children,...i}:t.children})]}function C(e){function t(n,s){}return t.type="xstate.assign",t.assignment=e,t.resolve=Es,t}let St=function(e){return e.Parent="#_parent",e.Internal="#_internal",e}({});function vs(e,t,n,s,{to:r,event:i,id:o,delay:a},c){var y;const u=t.machine.implementations.delays;if(typeof i=="string")throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${i}" }) instead`);const f=typeof i=="function"?i(n,s):i;let l;if(typeof a=="string"){const v=u&&u[a];l=typeof v=="function"?v(n,s):v}else l=typeof a=="function"?a(n,s):a;const h=typeof r=="function"?r(n,s):r;let m;if(typeof h=="string"){if(h===St.Parent?m=e.self._parent:h===St.Internal?m=e.self:h.startsWith("#_")?m=t.children[h.slice(2)]:m=(y=c.deferredActorIds)!=null&&y.includes(h)?h:t.children[h],!m)throw new Error(`Unable to send event to actor '${h}' from machine '${t.machine.id}'.`)}else m=h||e.self;return[t,{to:m,event:f,id:o,delay:l}]}function Ts(e,t,n){typeof n.to=="string"&&(n.to=t.children[n.to])}function _s(e,t){e.defer(()=>{const{to:n,event:s,delay:r,id:i}=t;if(typeof r=="number"){e.system.scheduler.schedule(e.self,n,s,r,i);return}e.system._relay(e.self,n,s.type===xn?Pt(e.self.id,s.data):s)})}function xt(e,t,n){function s(r,i){}return s.type="xsnapshot.sendTo",s.to=e,s.event=t,s.id=n==null?void 0:n.id,s.delay=n==null?void 0:n.delay,s.resolve=vs,s.retryResolve=Ts,s.execute=_s,s}const At=new WeakMap;function Y(e,t,n){let s=At.get(e);return s?t in s||(s[t]=n()):(s={[t]:n()},At.set(e,s)),s[t]}const Is={},ie=e=>typeof e=="string"?{type:e}:typeof e=="function"?"resolve"in e?{type:e.type}:{type:e.name}:e;class nt{constructor(t,n){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=n._parent,this.key=n._key,this.machine=n._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(Rt),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?ft(this.config.states,(s,r)=>new nt(s,{_parent:this,_key:r,_machine:this.machine})):Is,this.type==="compound"&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=this.config.history===!0?"shallow":this.config.history||!1,this.entry=U(this.config.entry).slice(),this.exit=U(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type==="final"||!this.parent?this.config.output:void 0,this.tags=U(t.tags).slice()}_initialize(){this.transitions=Hn(this),this.config.always&&(this.always=X(this.config.always).map(t=>V(this,Lt,t))),Object.keys(this.states).forEach(t=>{this.states[t]._initialize()})}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(ie),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(t=>`#${t.id}`),source:`#${this.id}`,actions:this.initial.actions.map(ie),eventType:null})}:void 0,history:this.history,states:ft(this.states,t=>t.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(t=>({...t,actions:t.actions.map(ie)})),entry:this.entry.map(ie),exit:this.exit.map(ie),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return Y(this,"invoke",()=>U(this.config.invoke).map((t,n)=>{const{src:s,systemId:r}=t,i=t.id??yt(this.id,n),o=typeof s=="string"?s:`xstate.invoke.${yt(this.id,n)}`;return{...t,src:o,id:i,systemId:r,toJSON(){const{onDone:a,onError:c,...u}=t;return{...u,type:"xstate.invoke",src:o,id:i}}}}))}get on(){return Y(this,"on",()=>[...this.transitions].flatMap(([n,s])=>s.map(r=>[n,r])).reduce((n,[s,r])=>(n[s]=n[s]||[],n[s].push(r),n),{}))}get after(){return Y(this,"delayedTransitions",()=>Vn(this))}get initial(){return Y(this,"initial",()=>Gn(this,this.config.initial))}next(t,n){const s=n.type,r=[];let i;const o=Y(this,`candidates-${s}`,()=>$n(this,s));for(const a of o){const{guard:c}=a,u=t.context;let f=!1;try{f=!c||We(c,u,n,t)}catch(l){const h=typeof c=="string"?c:typeof c=="object"?c.type:void 0;throw new Error(`Unable to evaluate guard ${h?`'${h}' `:""}in transition for event '${s}' in state node '${this.id}':
|
|
3
|
+
${l.message}`)}if(f){r.push(...a.actions),i=a;break}}return i?[i]:void 0}get events(){return Y(this,"events",()=>{const{states:t}=this,n=new Set(this.ownEvents);if(t)for(const s of Object.keys(t)){const r=t[s];if(r.states)for(const i of r.events)n.add(`${i}`)}return Array.from(n)})}get ownEvents(){const t=new Set([...this.transitions.keys()].filter(n=>this.transitions.get(n).some(s=>!(!s.target&&!s.actions.length&&!s.reenter))));return Array.from(t)}}const Ss="#";class st{constructor(t,n){this.config=t,this.version=void 0,this.schemas=void 0,this.implementations=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.__TResolvedTypesMeta=void 0,this.id=t.id||"(machine)",this.implementations={actors:(n==null?void 0:n.actors)??{},actions:(n==null?void 0:n.actions)??{},delays:(n==null?void 0:n.delays)??{},guards:(n==null?void 0:n.guards)??{}},this.version=this.config.version,this.schemas=this.config.schemas,this.transition=this.transition.bind(this),this.getInitialSnapshot=this.getInitialSnapshot.bind(this),this.getPersistedSnapshot=this.getPersistedSnapshot.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new nt(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:n,guards:s,actors:r,delays:i}=this.implementations;return new st(this.config,{actions:{...n,...t.actions},guards:{...s,...t.guards},actors:{...r,...t.actors},delays:{...i,...t.delays}})}resolveState(t){const n=is(this.root,t.value),s=Te(Ie(this.root,n));return me({_nodes:[...s],context:t.context||{},children:{},status:Ze(s,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,n,s){return Ce(t,n,s).snapshot}microstep(t,n,s){return Ce(t,n,s).microstates}getTransitionData(t,n){return et(this.root,t.value,t,n)||[]}getPreInitialState(t,n,s){const{context:r}=this.config,i=me({context:typeof r!="function"&&r?r:{},_nodes:[this.root],children:{},status:"active"},this);return typeof r=="function"?ne(i,n,t,[C(({spawn:a,event:c,self:u})=>r({spawn:a,input:c.input,self:u}))],s):i}getInitialSnapshot(t,n){const s=qt(n),r=[],i=this.getPreInitialState(t,s,r),o=Be([{target:[...Jt(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],i,t,s,!0,r),{snapshot:a}=Ce(o,s,t,r);return a}start(t){Object.values(t.children).forEach(n=>{n.getSnapshot().status==="active"&&n.start()})}getStateNodeById(t){const n=Ye(t),s=n.slice(1),r=xe(n[0])?n[0].slice(Ss.length):n[0],i=this.idMap.get(r);if(!i)throw new Error(`Child state node '#${r}' does not exist on machine '${this.id}'`);return _e(i,s)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,n){return hs(t,n)}restoreSnapshot(t,n){const s={},r=t.children;Object.keys(r).forEach(c=>{const u=r[c],f=u.snapshot,l=u.src,h=typeof l=="string"?Qe(this,l):l;if(!h)return;const m=B(h,{id:c,parent:n.self,syncSnapshot:u.syncSnapshot,snapshot:f,src:l,systemId:u.systemId});s[c]=m});const i=me({...t,children:s,_nodes:Array.from(Te(Ie(this.root,t.value)))},this);let o=new Set;function a(c,u){if(!o.has(c)){o.add(c);for(let f in c){const l=c[f];if(l&&typeof l=="object"){if("xstate$$type"in l&&l.xstate$$type===Xe){c[f]=u[l.id];continue}a(l,u)}}}}return a(i.context,s),i}}function xs(e,t){return new st(e,t)}function Ae({schemas:e,actors:t,actions:n,guards:s,delays:r}){return{createMachine:i=>xs({...i,schemas:e},{actors:t,actions:n,guards:s,delays:r})}}async function De(e,t){const n=await fetch(e,t);return n.status===200?n.json():Promise.resolve({message:n.statusText,success:!1})}const je=Ae({types:{context:{},events:{},input:{}},actions:{setUserContext:C(({context:e,event:t})=>{if(!t.type.includes("xstate.done.actor"))return e;const n=t;return n.output.type!=="AUTHENTICATE_SUCCESS"?e:{accessToken:n.output.accessToken,ignoreRefreshToken:!1}}),unsetUserContext:C(()=>({user:null,accessToken:"",refreshToken:"",ignoreRefreshToken:!1})),setAccessToken:C(({context:e,event:t})=>{if(!t.type.includes("xstate.done.actor"))return e;const n=t;return n.output.type!=="REFRESH_TOKEN_SUCCESS"?e:{accessToken:n.output.accessToken,ignoreRefreshToken:!1}}),unsetRefreshToken:C(()=>({refreshToken:""})),setIgnoreRefreshToken:C(()=>({ignoreRefreshToken:!0})),addError:C(({context:e,event:t})=>{if(!t.type.includes("xstate.error.actor"))return e;const n=t;return{errors:[...e.errors,String(n.error).replace("Error: ","")]}}),clearErrors:C(()=>({errors:[]}))},actors:{refreshAccessToken:Z(async({input:e})=>{let t;if(typeof window>"u"){if(e.context.refreshToken==="")throw new Error("Unauthorized.");try{const s=await De(e.context.endpoints.ssrRefresh,{method:"POST",mode:"cors",credentials:"include",headers:{Cookie:`refresh_token=${e.context.refreshToken}`,"Content-Type":"application/json","clicktap-scope":"view","clicktap-scope-id":"default"}});if(typeof s.accessToken>"u")throw new Error("Unauthorized.");return{type:"REFRESH_TOKEN_SUCCESS",accessToken:s.accessToken}}catch(n){throw console.log(n),new Error("Could not complete refresh request (server)")}}else{t=await De(e.context.endpoints.refresh,{method:"POST",mode:"cors",credentials:"include",headers:{"Content-Type":"application/json","clicktap-scope":"view","clicktap-scope-id":"default"},body:JSON.stringify({grant_type:"refresh_token"}).toString()});const n=t;if(typeof n.accessToken>"u")throw new Error("Unauthorized.");return{type:"REFRESH_TOKEN_SUCCESS",accessToken:n.accessToken}}}),authenticate:Z(async({input:e})=>{var s;const n=await De(e.context.endpoints.login,{method:"POST",mode:"cors",credentials:"include",headers:{"Content-Type":"application/json","clicktap-scope":"view","clicktap-scope-id":"default"},body:JSON.stringify({username:e.username,password:e.password}).toString()});if(!n.success)throw new Error(((s=n.message)==null?void 0:s.toString())??"Sign in failed. Please try again.");return{type:"AUTHENTICATE_SUCCESS",accessToken:n.accessToken}}),unauthenticate:Z(async({input:e})=>(await fetch(e.context.endpoints.logout,{method:"POST",mode:"cors",credentials:"include",headers:{"clicktap-scope":"view","clicktap-scope-id":"default"}}),{type:"UNAUTHENTICATE"}))}}).createMachine({id:"auth",context:({input:e})=>{var t,n;return{user:null,accessToken:"",refreshToken:((t=e==null?void 0:e.initialContext)==null?void 0:t.refreshToken)??"",ignoreRefreshToken:!1,endpoints:((n=e==null?void 0:e.initialContext)==null?void 0:n.endpoints)??{login:"",logout:"",refresh:"",ssrRefresh:""},errors:[]}},initial:"refreshing",states:{authenticating:{invoke:{src:"authenticate",input:({context:e,event:t})=>t.type!=="LOGIN"?{context:e,username:"",password:""}:{context:e,username:t.username,password:t.password},onDone:[{actions:"setUserContext",target:"loggedIn"}],onError:[{actions:"addError",target:"loggedOut"}]}},unauthenticating:{invoke:{src:"unauthenticate",input:({context:e})=>({context:e}),onDone:[{actions:"unsetUserContext",target:"loggedOut"}],onError:[{actions:["unsetUserContext","setIgnoreRefreshToken"],target:"loggedOut"}]}},refreshing:{invoke:{src:"refreshAccessToken",input:({context:e})=>({context:e}),onDone:[{actions:["unsetRefreshToken","setAccessToken"],target:"loggedIn"}],onError:[{actions:"unsetRefreshToken",target:"unauthenticating"}]}},loggedOut:{on:{LOGIN:{target:"authenticating"},CLEAR_ERRORS:{actions:"clearErrors"}}},loggedIn:{after:{84e4:{guard:()=>typeof window<"u",target:"refreshing"}},on:{LOGOUT:{target:"unauthenticating"},CLEAR_ERRORS:{actions:"clearErrors"}}}}}),rt=F.createContext({}),As=()=>{const e=F.useContext(rt),[t,n]=F.useState(typeof window<"u"&&e.getSnapshot().value==="loggedIn");return F.useEffect(()=>{if(typeof window>"u")return;const s=e.subscribe(r=>{(r.value==="loggedIn"||r.value==="loggedOut")&&n(r.value==="loggedIn")});return()=>{s.unsubscribe()}},[e]),{authActor:e,isLoggedIn:t}},ws=async(e="",t={inspect:void 0,endpoints:{login:"",logout:"",refresh:"",ssrRefresh:""}})=>typeof window<"u"?(console.warn("App.getInitialProps::getAuth should not be run on the frontend. You are probably missing getServerSideProps in your page."),B(je,{inspect:t.inspect,input:{initialContext:{endpoints:t.endpoints}}}).start()):B(je,{input:{initialContext:{endpoints:t.endpoints,refreshToken:e}},inspect:t.inspect}).start();function bs({actor:e,children:t}){return Je.jsx(rt.Provider,{value:e,children:t})}let Os=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),"");const Zt=Ae({actors:{tick:ms(({sendBack:e,input:t})=>{const n=setInterval(()=>{e({type:"TICK"})},t.interval);return()=>{clearInterval(n)}})},types:{context:{},events:{},input:{}}}).createMachine({id:"timer",initial:"running",context:({input:e})=>({elapsed:0,duration:e.initialContext.duration??3e3,interval:100,intervalId:null}),states:{paused:{on:{RESUME_TIMER:{target:"running",guard:({context:e})=>e.elapsed<e.duration}}},running:{invoke:{input:({context:e})=>({interval:e.interval}),src:"tick"},always:[{target:"completed",guard:({context:e})=>e.elapsed>=e.duration}],on:{TICK:{actions:C(({context:e,event:t})=>t.type!=="TICK"?e:{elapsed:e.elapsed+e.interval})},PAUSE_TIMER:{target:"paused"}}},completed:{type:"final"}}}),Ns=Ae({actors:{timer:Zt},types:{context:{},events:{},input:{}},actions:{addItem:C(({context:e,event:t})=>{if(t.type!=="ADD_ITEM")return e;const n=`notification-${Os()}`,s=t.duration??e.duration,r=F.cloneElement(t.item,{duration:s,id:n,key:t.item.key??n,...t.item.props}),i={duration:s,id:n,element:r},o=e.items;return e.order==="desc"?o.push(i):o.unshift(i),{items:o,activeItem:n}}),removeItem:C(({context:e,event:t})=>{if(t.type!=="REMOVE_ITEM"&&t.type!=="xstate.done.actor.timer")return e;const n=e.items;return e.order==="desc"?(n.pop(),{items:n,activeItem:n.length>0?n[n.length-1].id:null}):(n.shift(),{items:n,activeItem:n.length>0?n[0].id:null})})},delays:{ITEM_TIMEOUT:({context:e})=>e.items[e.items.length-1].duration??e.duration},guards:{itemHasTimeout:({context:e})=>e.items[e.items.length-1].duration>0||e.duration>0}}).createMachine({id:"toast",context:{items:[],order:"desc",duration:0,activeItem:null},initial:"idle",states:{idle:{on:{ADD_ITEM:{target:"adding"}}},active:{invoke:{id:"timer",src:"timer",input:({context:e})=>({initialContext:{duration:e.items[e.items.length-1].duration??e.duration}}),onDone:{target:"removing",guard:"itemHasTimeout"}},on:{ADD_ITEM:{target:"adding"},REMOVE_ITEM:{target:"removing"},SET_IDLE:{target:"idle"},RESUME_TIMER:{actions:xt("timer",{type:"RESUME_TIMER"})},PAUSE_TIMER:{actions:xt("timer",{type:"PAUSE_TIMER"})}}},adding:{entry:["addItem"],on:{SET_IDLE:{target:"idle"},SET_ACTIVE:{target:"active"}}},removing:{entry:"removeItem",on:{SET_IDLE:{target:"idle"},SET_ACTIVE:{target:"active"}}}}}),it=F.createContext({}),ks=()=>F.useContext(it);function Cs({children:e,actor:t}){return Je.jsx(it.Provider,{value:t,children:e})}function Ds({context:e,event:t}){if(!t.type.includes("xstate.done.actor"))return e;const n=t;return n.output.type!=="ADD_ITEMS_SUCCESS"?e:{...e.quote,...n.output.quote}}function Rs({context:e,event:t}){if(!t.type.includes("xstate.done.actor"))return e;const n=t;return n.output.type!=="REMOVE_ITEMS_SUCCESS"?e:{...e.quote,...n.output.quote}}function Ls({context:e,event:t}){if(!t.type.includes("xstate.done.actor"))return e;const n=t;return n.output.type!=="REFRESH_SUCCESS"?e:{quote:{...e.quote,...n.output.quote}}}const ot=JSON,Ms=e=>e.toUpperCase(),Ps=e=>{const t={};return e.forEach((n,s)=>{t[s]=n}),t},qs=(e,t,n)=>e.document?e:{document:e,variables:t,requestHeaders:n,signal:void 0},Fs=(e,t,n)=>e.query?e:{query:e,variables:t,requestHeaders:n,signal:void 0},Us=(e,t)=>e.documents?e:{documents:e,requestHeaders:t,signal:void 0},Bs=(e,t,...n)=>{const[s,r]=n;return e.document?e:{url:e,document:t,variables:s,requestHeaders:r,signal:void 0}};function ge(e,t){if(!!!e)throw new Error(t)}function js(e){return typeof e=="object"&&e!==null}function $s(e,t){if(!!!e)throw new Error(t??"Unexpected invariant triggered.")}const Vs=/\r\n|[\n\r]/g;function $e(e,t){let n=0,s=1;for(const r of e.body.matchAll(Vs)){if(typeof r.index=="number"||$s(!1),r.index>=t)break;n=r.index+r[0].length,s+=1}return{line:s,column:t+1-n}}function Hs(e){return en(e.source,$e(e.source,e.start))}function en(e,t){const n=e.locationOffset.column-1,s="".padStart(n)+e.body,r=t.line-1,i=e.locationOffset.line-1,o=t.line+i,a=t.line===1?n:0,c=t.column+a,u=`${e.name}:${o}:${c}
|
|
4
|
+
`,f=s.split(/\r\n|[\n\r]/g),l=f[r];if(l.length>120){const h=Math.floor(c/80),m=c%80,y=[];for(let v=0;v<l.length;v+=80)y.push(l.slice(v,v+80));return u+wt([[`${o} |`,y[0]],...y.slice(1,h+1).map(v=>["|",v]),["|","^".padStart(m)],["|",y[h+1]]])}return u+wt([[`${o-1} |`,f[r-1]],[`${o} |`,l],["|","^".padStart(c)],[`${o+1} |`,f[r+1]]])}function wt(e){const t=e.filter(([s,r])=>r!==void 0),n=Math.max(...t.map(([s])=>s.length));return t.map(([s,r])=>s.padStart(n)+(r?" "+r:"")).join(`
|
|
5
|
+
`)}function Gs(e){const t=e[0];return t==null||"kind"in t||"length"in t?{nodes:t,source:e[1],positions:e[2],path:e[3],originalError:e[4],extensions:e[5]}:t}class at extends Error{constructor(t,...n){var s,r,i;const{nodes:o,source:a,positions:c,path:u,originalError:f,extensions:l}=Gs(n);super(t),this.name="GraphQLError",this.path=u??void 0,this.originalError=f??void 0,this.nodes=bt(Array.isArray(o)?o:o?[o]:void 0);const h=bt((s=this.nodes)===null||s===void 0?void 0:s.map(y=>y.loc).filter(y=>y!=null));this.source=a??(h==null||(r=h[0])===null||r===void 0?void 0:r.source),this.positions=c??(h==null?void 0:h.map(y=>y.start)),this.locations=c&&a?c.map(y=>$e(a,y)):h==null?void 0:h.map(y=>$e(y.source,y.start));const m=js(f==null?void 0:f.extensions)?f==null?void 0:f.extensions:void 0;this.extensions=(i=l??m)!==null&&i!==void 0?i:Object.create(null),Object.defineProperties(this,{message:{writable:!0,enumerable:!0},name:{enumerable:!1},nodes:{enumerable:!1},source:{enumerable:!1},positions:{enumerable:!1},originalError:{enumerable:!1}}),f!=null&&f.stack?Object.defineProperty(this,"stack",{value:f.stack,writable:!0,configurable:!0}):Error.captureStackTrace?Error.captureStackTrace(this,at):Object.defineProperty(this,"stack",{value:Error().stack,writable:!0,configurable:!0})}get[Symbol.toStringTag](){return"GraphQLError"}toString(){let t=this.message;if(this.nodes)for(const n of this.nodes)n.loc&&(t+=`
|
|
6
|
+
|
|
7
|
+
`+Hs(n.loc));else if(this.source&&this.locations)for(const n of this.locations)t+=`
|
|
8
|
+
|
|
9
|
+
`+en(this.source,n);return t}toJSON(){const t={message:this.message};return this.locations!=null&&(t.locations=this.locations),this.path!=null&&(t.path=this.path),this.extensions!=null&&Object.keys(this.extensions).length>0&&(t.extensions=this.extensions),t}}function bt(e){return e===void 0||e.length===0?void 0:e}function b(e,t,n){return new at(`Syntax Error: ${n}`,{source:e,positions:[t]})}class zs{constructor(t,n,s){this.start=t.start,this.end=n.end,this.startToken=t,this.endToken=n,this.source=s}get[Symbol.toStringTag](){return"Location"}toJSON(){return{start:this.start,end:this.end}}}class tn{constructor(t,n,s,r,i,o){this.kind=t,this.start=n,this.end=s,this.line=r,this.column=i,this.value=o,this.prev=null,this.next=null}get[Symbol.toStringTag](){return"Token"}toJSON(){return{kind:this.kind,value:this.value,line:this.line,column:this.column}}}const nn={Name:[],Document:["definitions"],OperationDefinition:["name","variableDefinitions","directives","selectionSet"],VariableDefinition:["variable","type","defaultValue","directives"],Variable:["name"],SelectionSet:["selections"],Field:["alias","name","arguments","directives","selectionSet"],Argument:["name","value"],FragmentSpread:["name","directives"],InlineFragment:["typeCondition","directives","selectionSet"],FragmentDefinition:["name","variableDefinitions","typeCondition","directives","selectionSet"],IntValue:[],FloatValue:[],StringValue:[],BooleanValue:[],NullValue:[],EnumValue:[],ListValue:["values"],ObjectValue:["fields"],ObjectField:["name","value"],Directive:["name","arguments"],NamedType:["name"],ListType:["type"],NonNullType:["type"],SchemaDefinition:["description","directives","operationTypes"],OperationTypeDefinition:["type"],ScalarTypeDefinition:["description","name","directives"],ObjectTypeDefinition:["description","name","interfaces","directives","fields"],FieldDefinition:["description","name","arguments","type","directives"],InputValueDefinition:["description","name","type","defaultValue","directives"],InterfaceTypeDefinition:["description","name","interfaces","directives","fields"],UnionTypeDefinition:["description","name","directives","types"],EnumTypeDefinition:["description","name","directives","values"],EnumValueDefinition:["description","name","directives"],InputObjectTypeDefinition:["description","name","directives","fields"],DirectiveDefinition:["description","name","arguments","locations"],SchemaExtension:["directives","operationTypes"],ScalarTypeExtension:["name","directives"],ObjectTypeExtension:["name","interfaces","directives","fields"],InterfaceTypeExtension:["name","interfaces","directives","fields"],UnionTypeExtension:["name","directives","types"],EnumTypeExtension:["name","directives","values"],InputObjectTypeExtension:["name","directives","fields"]},Js=new Set(Object.keys(nn));function Ot(e){const t=e==null?void 0:e.kind;return typeof t=="string"&&Js.has(t)}var K;(function(e){e.QUERY="query",e.MUTATION="mutation",e.SUBSCRIPTION="subscription"})(K||(K={}));var Ve;(function(e){e.QUERY="QUERY",e.MUTATION="MUTATION",e.SUBSCRIPTION="SUBSCRIPTION",e.FIELD="FIELD",e.FRAGMENT_DEFINITION="FRAGMENT_DEFINITION",e.FRAGMENT_SPREAD="FRAGMENT_SPREAD",e.INLINE_FRAGMENT="INLINE_FRAGMENT",e.VARIABLE_DEFINITION="VARIABLE_DEFINITION",e.SCHEMA="SCHEMA",e.SCALAR="SCALAR",e.OBJECT="OBJECT",e.FIELD_DEFINITION="FIELD_DEFINITION",e.ARGUMENT_DEFINITION="ARGUMENT_DEFINITION",e.INTERFACE="INTERFACE",e.UNION="UNION",e.ENUM="ENUM",e.ENUM_VALUE="ENUM_VALUE",e.INPUT_OBJECT="INPUT_OBJECT",e.INPUT_FIELD_DEFINITION="INPUT_FIELD_DEFINITION"})(Ve||(Ve={}));var T;(function(e){e.NAME="Name",e.DOCUMENT="Document",e.OPERATION_DEFINITION="OperationDefinition",e.VARIABLE_DEFINITION="VariableDefinition",e.SELECTION_SET="SelectionSet",e.FIELD="Field",e.ARGUMENT="Argument",e.FRAGMENT_SPREAD="FragmentSpread",e.INLINE_FRAGMENT="InlineFragment",e.FRAGMENT_DEFINITION="FragmentDefinition",e.VARIABLE="Variable",e.INT="IntValue",e.FLOAT="FloatValue",e.STRING="StringValue",e.BOOLEAN="BooleanValue",e.NULL="NullValue",e.ENUM="EnumValue",e.LIST="ListValue",e.OBJECT="ObjectValue",e.OBJECT_FIELD="ObjectField",e.DIRECTIVE="Directive",e.NAMED_TYPE="NamedType",e.LIST_TYPE="ListType",e.NON_NULL_TYPE="NonNullType",e.SCHEMA_DEFINITION="SchemaDefinition",e.OPERATION_TYPE_DEFINITION="OperationTypeDefinition",e.SCALAR_TYPE_DEFINITION="ScalarTypeDefinition",e.OBJECT_TYPE_DEFINITION="ObjectTypeDefinition",e.FIELD_DEFINITION="FieldDefinition",e.INPUT_VALUE_DEFINITION="InputValueDefinition",e.INTERFACE_TYPE_DEFINITION="InterfaceTypeDefinition",e.UNION_TYPE_DEFINITION="UnionTypeDefinition",e.ENUM_TYPE_DEFINITION="EnumTypeDefinition",e.ENUM_VALUE_DEFINITION="EnumValueDefinition",e.INPUT_OBJECT_TYPE_DEFINITION="InputObjectTypeDefinition",e.DIRECTIVE_DEFINITION="DirectiveDefinition",e.SCHEMA_EXTENSION="SchemaExtension",e.SCALAR_TYPE_EXTENSION="ScalarTypeExtension",e.OBJECT_TYPE_EXTENSION="ObjectTypeExtension",e.INTERFACE_TYPE_EXTENSION="InterfaceTypeExtension",e.UNION_TYPE_EXTENSION="UnionTypeExtension",e.ENUM_TYPE_EXTENSION="EnumTypeExtension",e.INPUT_OBJECT_TYPE_EXTENSION="InputObjectTypeExtension"})(T||(T={}));function He(e){return e===9||e===32}function ue(e){return e>=48&&e<=57}function sn(e){return e>=97&&e<=122||e>=65&&e<=90}function rn(e){return sn(e)||e===95}function Ys(e){return sn(e)||ue(e)||e===95}function Qs(e){var t;let n=Number.MAX_SAFE_INTEGER,s=null,r=-1;for(let o=0;o<e.length;++o){var i;const a=e[o],c=Xs(a);c!==a.length&&(s=(i=s)!==null&&i!==void 0?i:o,r=o,o!==0&&c<n&&(n=c))}return e.map((o,a)=>a===0?o:o.slice(n)).slice((t=s)!==null&&t!==void 0?t:0,r+1)}function Xs(e){let t=0;for(;t<e.length&&He(e.charCodeAt(t));)++t;return t}function Ws(e,t){const n=e.replace(/"""/g,'\\"""'),s=n.split(/\r\n|[\n\r]/g),r=s.length===1,i=s.length>1&&s.slice(1).every(m=>m.length===0||He(m.charCodeAt(0))),o=n.endsWith('\\"""'),a=e.endsWith('"')&&!o,c=e.endsWith("\\"),u=a||c,f=!(t!=null&&t.minimize)&&(!r||e.length>70||u||i||o);let l="";const h=r&&He(e.charCodeAt(0));return(f&&!h||i)&&(l+=`
|
|
10
|
+
`),l+=n,(f||u)&&(l+=`
|
|
11
|
+
`),'"""'+l+'"""'}var p;(function(e){e.SOF="<SOF>",e.EOF="<EOF>",e.BANG="!",e.DOLLAR="$",e.AMP="&",e.PAREN_L="(",e.PAREN_R=")",e.SPREAD="...",e.COLON=":",e.EQUALS="=",e.AT="@",e.BRACKET_L="[",e.BRACKET_R="]",e.BRACE_L="{",e.PIPE="|",e.BRACE_R="}",e.NAME="Name",e.INT="Int",e.FLOAT="Float",e.STRING="String",e.BLOCK_STRING="BlockString",e.COMMENT="Comment"})(p||(p={}));class Ks{constructor(t){const n=new tn(p.SOF,0,0,0,0);this.source=t,this.lastToken=n,this.token=n,this.line=1,this.lineStart=0}get[Symbol.toStringTag](){return"Lexer"}advance(){return this.lastToken=this.token,this.token=this.lookahead()}lookahead(){let t=this.token;if(t.kind!==p.EOF)do if(t.next)t=t.next;else{const n=er(this,t.end);t.next=n,n.prev=t,t=n}while(t.kind===p.COMMENT);return t}}function Zs(e){return e===p.BANG||e===p.DOLLAR||e===p.AMP||e===p.PAREN_L||e===p.PAREN_R||e===p.SPREAD||e===p.COLON||e===p.EQUALS||e===p.AT||e===p.BRACKET_L||e===p.BRACKET_R||e===p.BRACE_L||e===p.PIPE||e===p.BRACE_R}function se(e){return e>=0&&e<=55295||e>=57344&&e<=1114111}function we(e,t){return on(e.charCodeAt(t))&&an(e.charCodeAt(t+1))}function on(e){return e>=55296&&e<=56319}function an(e){return e>=56320&&e<=57343}function z(e,t){const n=e.source.body.codePointAt(t);if(n===void 0)return p.EOF;if(n>=32&&n<=126){const s=String.fromCodePoint(n);return s==='"'?`'"'`:`"${s}"`}return"U+"+n.toString(16).toUpperCase().padStart(4,"0")}function w(e,t,n,s,r){const i=e.line,o=1+n-e.lineStart;return new tn(t,n,s,i,o,r)}function er(e,t){const n=e.source.body,s=n.length;let r=t;for(;r<s;){const i=n.charCodeAt(r);switch(i){case 65279:case 9:case 32:case 44:++r;continue;case 10:++r,++e.line,e.lineStart=r;continue;case 13:n.charCodeAt(r+1)===10?r+=2:++r,++e.line,e.lineStart=r;continue;case 35:return tr(e,r);case 33:return w(e,p.BANG,r,r+1);case 36:return w(e,p.DOLLAR,r,r+1);case 38:return w(e,p.AMP,r,r+1);case 40:return w(e,p.PAREN_L,r,r+1);case 41:return w(e,p.PAREN_R,r,r+1);case 46:if(n.charCodeAt(r+1)===46&&n.charCodeAt(r+2)===46)return w(e,p.SPREAD,r,r+3);break;case 58:return w(e,p.COLON,r,r+1);case 61:return w(e,p.EQUALS,r,r+1);case 64:return w(e,p.AT,r,r+1);case 91:return w(e,p.BRACKET_L,r,r+1);case 93:return w(e,p.BRACKET_R,r,r+1);case 123:return w(e,p.BRACE_L,r,r+1);case 124:return w(e,p.PIPE,r,r+1);case 125:return w(e,p.BRACE_R,r,r+1);case 34:return n.charCodeAt(r+1)===34&&n.charCodeAt(r+2)===34?ar(e,r):sr(e,r)}if(ue(i)||i===45)return nr(e,r,i);if(rn(i))return cr(e,r);throw b(e.source,r,i===39?`Unexpected single quote character ('), did you mean to use a double quote (")?`:se(i)||we(n,r)?`Unexpected character: ${z(e,r)}.`:`Invalid character: ${z(e,r)}.`)}return w(e,p.EOF,s,s)}function tr(e,t){const n=e.source.body,s=n.length;let r=t+1;for(;r<s;){const i=n.charCodeAt(r);if(i===10||i===13)break;if(se(i))++r;else if(we(n,r))r+=2;else break}return w(e,p.COMMENT,t,r,n.slice(t+1,r))}function nr(e,t,n){const s=e.source.body;let r=t,i=n,o=!1;if(i===45&&(i=s.charCodeAt(++r)),i===48){if(i=s.charCodeAt(++r),ue(i))throw b(e.source,r,`Invalid number, unexpected digit after 0: ${z(e,r)}.`)}else r=Re(e,r,i),i=s.charCodeAt(r);if(i===46&&(o=!0,i=s.charCodeAt(++r),r=Re(e,r,i),i=s.charCodeAt(r)),(i===69||i===101)&&(o=!0,i=s.charCodeAt(++r),(i===43||i===45)&&(i=s.charCodeAt(++r)),r=Re(e,r,i),i=s.charCodeAt(r)),i===46||rn(i))throw b(e.source,r,`Invalid number, expected digit but got: ${z(e,r)}.`);return w(e,o?p.FLOAT:p.INT,t,r,s.slice(t,r))}function Re(e,t,n){if(!ue(n))throw b(e.source,t,`Invalid number, expected digit but got: ${z(e,t)}.`);const s=e.source.body;let r=t+1;for(;ue(s.charCodeAt(r));)++r;return r}function sr(e,t){const n=e.source.body,s=n.length;let r=t+1,i=r,o="";for(;r<s;){const a=n.charCodeAt(r);if(a===34)return o+=n.slice(i,r),w(e,p.STRING,t,r+1,o);if(a===92){o+=n.slice(i,r);const c=n.charCodeAt(r+1)===117?n.charCodeAt(r+2)===123?rr(e,r):ir(e,r):or(e,r);o+=c.value,r+=c.size,i=r;continue}if(a===10||a===13)break;if(se(a))++r;else if(we(n,r))r+=2;else throw b(e.source,r,`Invalid character within String: ${z(e,r)}.`)}throw b(e.source,r,"Unterminated string.")}function rr(e,t){const n=e.source.body;let s=0,r=3;for(;r<12;){const i=n.charCodeAt(t+r++);if(i===125){if(r<5||!se(s))break;return{value:String.fromCodePoint(s),size:r}}if(s=s<<4|oe(i),s<0)break}throw b(e.source,t,`Invalid Unicode escape sequence: "${n.slice(t,t+r)}".`)}function ir(e,t){const n=e.source.body,s=Nt(n,t+2);if(se(s))return{value:String.fromCodePoint(s),size:6};if(on(s)&&n.charCodeAt(t+6)===92&&n.charCodeAt(t+7)===117){const r=Nt(n,t+8);if(an(r))return{value:String.fromCodePoint(s,r),size:12}}throw b(e.source,t,`Invalid Unicode escape sequence: "${n.slice(t,t+6)}".`)}function Nt(e,t){return oe(e.charCodeAt(t))<<12|oe(e.charCodeAt(t+1))<<8|oe(e.charCodeAt(t+2))<<4|oe(e.charCodeAt(t+3))}function oe(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:-1}function or(e,t){const n=e.source.body;switch(n.charCodeAt(t+1)){case 34:return{value:'"',size:2};case 92:return{value:"\\",size:2};case 47:return{value:"/",size:2};case 98:return{value:"\b",size:2};case 102:return{value:"\f",size:2};case 110:return{value:`
|
|
12
|
+
`,size:2};case 114:return{value:"\r",size:2};case 116:return{value:" ",size:2}}throw b(e.source,t,`Invalid character escape sequence: "${n.slice(t,t+2)}".`)}function ar(e,t){const n=e.source.body,s=n.length;let r=e.lineStart,i=t+3,o=i,a="";const c=[];for(;i<s;){const u=n.charCodeAt(i);if(u===34&&n.charCodeAt(i+1)===34&&n.charCodeAt(i+2)===34){a+=n.slice(o,i),c.push(a);const f=w(e,p.BLOCK_STRING,t,i+3,Qs(c).join(`
|
|
13
|
+
`));return e.line+=c.length-1,e.lineStart=r,f}if(u===92&&n.charCodeAt(i+1)===34&&n.charCodeAt(i+2)===34&&n.charCodeAt(i+3)===34){a+=n.slice(o,i),o=i+1,i+=4;continue}if(u===10||u===13){a+=n.slice(o,i),c.push(a),u===13&&n.charCodeAt(i+1)===10?i+=2:++i,a="",o=i,r=i;continue}if(se(u))++i;else if(we(n,i))i+=2;else throw b(e.source,i,`Invalid character within String: ${z(e,i)}.`)}throw b(e.source,i,"Unterminated string.")}function cr(e,t){const n=e.source.body,s=n.length;let r=t+1;for(;r<s;){const i=n.charCodeAt(r);if(Ys(i))++r;else break}return w(e,p.NAME,t,r,n.slice(t,r))}const ur=10,cn=2;function ct(e){return be(e,[])}function be(e,t){switch(typeof e){case"string":return JSON.stringify(e);case"function":return e.name?`[function ${e.name}]`:"[function]";case"object":return dr(e,t);default:return String(e)}}function dr(e,t){if(e===null)return"null";if(t.includes(e))return"[Circular]";const n=[...t,e];if(lr(e)){const s=e.toJSON();if(s!==e)return typeof s=="string"?s:be(s,n)}else if(Array.isArray(e))return fr(e,n);return hr(e,n)}function lr(e){return typeof e.toJSON=="function"}function hr(e,t){const n=Object.entries(e);return n.length===0?"{}":t.length>cn?"["+pr(e)+"]":"{ "+n.map(([r,i])=>r+": "+be(i,t)).join(", ")+" }"}function fr(e,t){if(e.length===0)return"[]";if(t.length>cn)return"[Array]";const n=Math.min(ur,e.length),s=e.length-n,r=[];for(let i=0;i<n;++i)r.push(be(e[i],t));return s===1?r.push("... 1 more item"):s>1&&r.push(`... ${s} more items`),"["+r.join(", ")+"]"}function pr(e){const t=Object.prototype.toString.call(e).replace(/^\[object /,"").replace(/]$/,"");if(t==="Object"&&typeof e.constructor=="function"){const n=e.constructor.name;if(typeof n=="string"&&n!=="")return n}return t}const yr=globalThis.process&&globalThis.process.env.NODE_ENV==="production"?function(t,n){return t instanceof n}:function(t,n){if(t instanceof n)return!0;if(typeof t=="object"&&t!==null){var s;const r=n.prototype[Symbol.toStringTag],i=Symbol.toStringTag in t?t[Symbol.toStringTag]:(s=t.constructor)===null||s===void 0?void 0:s.name;if(r===i){const o=ct(t);throw new Error(`Cannot use ${r} "${o}" from another module or realm.
|
|
14
|
+
|
|
15
|
+
Ensure that there is only one instance of "graphql" in the node_modules
|
|
16
|
+
directory. If different versions of "graphql" are the dependencies of other
|
|
17
|
+
relied on modules, use "resolutions" to ensure only one version is installed.
|
|
18
|
+
|
|
19
|
+
https://yarnpkg.com/en/docs/selective-version-resolutions
|
|
20
|
+
|
|
21
|
+
Duplicate "graphql" modules cannot be used at the same time since different
|
|
22
|
+
versions may have different capabilities and behavior. The data from one
|
|
23
|
+
version used in the function from another could produce confusing and
|
|
24
|
+
spurious results.`)}}return!1};class un{constructor(t,n="GraphQL request",s={line:1,column:1}){typeof t=="string"||ge(!1,`Body must be a string. Received: ${ct(t)}.`),this.body=t,this.name=n,this.locationOffset=s,this.locationOffset.line>0||ge(!1,"line in locationOffset is 1-indexed and must be positive."),this.locationOffset.column>0||ge(!1,"column in locationOffset is 1-indexed and must be positive.")}get[Symbol.toStringTag](){return"Source"}}function mr(e){return yr(e,un)}function gr(e,t){return new Er(e,t).parseDocument()}class Er{constructor(t,n={}){const s=mr(t)?t:new un(t);this._lexer=new Ks(s),this._options=n,this._tokenCounter=0}parseName(){const t=this.expectToken(p.NAME);return this.node(t,{kind:T.NAME,value:t.value})}parseDocument(){return this.node(this._lexer.token,{kind:T.DOCUMENT,definitions:this.many(p.SOF,this.parseDefinition,p.EOF)})}parseDefinition(){if(this.peek(p.BRACE_L))return this.parseOperationDefinition();const t=this.peekDescription(),n=t?this._lexer.lookahead():this._lexer.token;if(n.kind===p.NAME){switch(n.value){case"schema":return this.parseSchemaDefinition();case"scalar":return this.parseScalarTypeDefinition();case"type":return this.parseObjectTypeDefinition();case"interface":return this.parseInterfaceTypeDefinition();case"union":return this.parseUnionTypeDefinition();case"enum":return this.parseEnumTypeDefinition();case"input":return this.parseInputObjectTypeDefinition();case"directive":return this.parseDirectiveDefinition()}if(t)throw b(this._lexer.source,this._lexer.token.start,"Unexpected description, descriptions are supported only on type definitions.");switch(n.value){case"query":case"mutation":case"subscription":return this.parseOperationDefinition();case"fragment":return this.parseFragmentDefinition();case"extend":return this.parseTypeSystemExtension()}}throw this.unexpected(n)}parseOperationDefinition(){const t=this._lexer.token;if(this.peek(p.BRACE_L))return this.node(t,{kind:T.OPERATION_DEFINITION,operation:K.QUERY,name:void 0,variableDefinitions:[],directives:[],selectionSet:this.parseSelectionSet()});const n=this.parseOperationType();let s;return this.peek(p.NAME)&&(s=this.parseName()),this.node(t,{kind:T.OPERATION_DEFINITION,operation:n,name:s,variableDefinitions:this.parseVariableDefinitions(),directives:this.parseDirectives(!1),selectionSet:this.parseSelectionSet()})}parseOperationType(){const t=this.expectToken(p.NAME);switch(t.value){case"query":return K.QUERY;case"mutation":return K.MUTATION;case"subscription":return K.SUBSCRIPTION}throw this.unexpected(t)}parseVariableDefinitions(){return this.optionalMany(p.PAREN_L,this.parseVariableDefinition,p.PAREN_R)}parseVariableDefinition(){return this.node(this._lexer.token,{kind:T.VARIABLE_DEFINITION,variable:this.parseVariable(),type:(this.expectToken(p.COLON),this.parseTypeReference()),defaultValue:this.expectOptionalToken(p.EQUALS)?this.parseConstValueLiteral():void 0,directives:this.parseConstDirectives()})}parseVariable(){const t=this._lexer.token;return this.expectToken(p.DOLLAR),this.node(t,{kind:T.VARIABLE,name:this.parseName()})}parseSelectionSet(){return this.node(this._lexer.token,{kind:T.SELECTION_SET,selections:this.many(p.BRACE_L,this.parseSelection,p.BRACE_R)})}parseSelection(){return this.peek(p.SPREAD)?this.parseFragment():this.parseField()}parseField(){const t=this._lexer.token,n=this.parseName();let s,r;return this.expectOptionalToken(p.COLON)?(s=n,r=this.parseName()):r=n,this.node(t,{kind:T.FIELD,alias:s,name:r,arguments:this.parseArguments(!1),directives:this.parseDirectives(!1),selectionSet:this.peek(p.BRACE_L)?this.parseSelectionSet():void 0})}parseArguments(t){const n=t?this.parseConstArgument:this.parseArgument;return this.optionalMany(p.PAREN_L,n,p.PAREN_R)}parseArgument(t=!1){const n=this._lexer.token,s=this.parseName();return this.expectToken(p.COLON),this.node(n,{kind:T.ARGUMENT,name:s,value:this.parseValueLiteral(t)})}parseConstArgument(){return this.parseArgument(!0)}parseFragment(){const t=this._lexer.token;this.expectToken(p.SPREAD);const n=this.expectOptionalKeyword("on");return!n&&this.peek(p.NAME)?this.node(t,{kind:T.FRAGMENT_SPREAD,name:this.parseFragmentName(),directives:this.parseDirectives(!1)}):this.node(t,{kind:T.INLINE_FRAGMENT,typeCondition:n?this.parseNamedType():void 0,directives:this.parseDirectives(!1),selectionSet:this.parseSelectionSet()})}parseFragmentDefinition(){const t=this._lexer.token;return this.expectKeyword("fragment"),this._options.allowLegacyFragmentVariables===!0?this.node(t,{kind:T.FRAGMENT_DEFINITION,name:this.parseFragmentName(),variableDefinitions:this.parseVariableDefinitions(),typeCondition:(this.expectKeyword("on"),this.parseNamedType()),directives:this.parseDirectives(!1),selectionSet:this.parseSelectionSet()}):this.node(t,{kind:T.FRAGMENT_DEFINITION,name:this.parseFragmentName(),typeCondition:(this.expectKeyword("on"),this.parseNamedType()),directives:this.parseDirectives(!1),selectionSet:this.parseSelectionSet()})}parseFragmentName(){if(this._lexer.token.value==="on")throw this.unexpected();return this.parseName()}parseValueLiteral(t){const n=this._lexer.token;switch(n.kind){case p.BRACKET_L:return this.parseList(t);case p.BRACE_L:return this.parseObject(t);case p.INT:return this.advanceLexer(),this.node(n,{kind:T.INT,value:n.value});case p.FLOAT:return this.advanceLexer(),this.node(n,{kind:T.FLOAT,value:n.value});case p.STRING:case p.BLOCK_STRING:return this.parseStringLiteral();case p.NAME:switch(this.advanceLexer(),n.value){case"true":return this.node(n,{kind:T.BOOLEAN,value:!0});case"false":return this.node(n,{kind:T.BOOLEAN,value:!1});case"null":return this.node(n,{kind:T.NULL});default:return this.node(n,{kind:T.ENUM,value:n.value})}case p.DOLLAR:if(t)if(this.expectToken(p.DOLLAR),this._lexer.token.kind===p.NAME){const s=this._lexer.token.value;throw b(this._lexer.source,n.start,`Unexpected variable "$${s}" in constant value.`)}else throw this.unexpected(n);return this.parseVariable();default:throw this.unexpected()}}parseConstValueLiteral(){return this.parseValueLiteral(!0)}parseStringLiteral(){const t=this._lexer.token;return this.advanceLexer(),this.node(t,{kind:T.STRING,value:t.value,block:t.kind===p.BLOCK_STRING})}parseList(t){const n=()=>this.parseValueLiteral(t);return this.node(this._lexer.token,{kind:T.LIST,values:this.any(p.BRACKET_L,n,p.BRACKET_R)})}parseObject(t){const n=()=>this.parseObjectField(t);return this.node(this._lexer.token,{kind:T.OBJECT,fields:this.any(p.BRACE_L,n,p.BRACE_R)})}parseObjectField(t){const n=this._lexer.token,s=this.parseName();return this.expectToken(p.COLON),this.node(n,{kind:T.OBJECT_FIELD,name:s,value:this.parseValueLiteral(t)})}parseDirectives(t){const n=[];for(;this.peek(p.AT);)n.push(this.parseDirective(t));return n}parseConstDirectives(){return this.parseDirectives(!0)}parseDirective(t){const n=this._lexer.token;return this.expectToken(p.AT),this.node(n,{kind:T.DIRECTIVE,name:this.parseName(),arguments:this.parseArguments(t)})}parseTypeReference(){const t=this._lexer.token;let n;if(this.expectOptionalToken(p.BRACKET_L)){const s=this.parseTypeReference();this.expectToken(p.BRACKET_R),n=this.node(t,{kind:T.LIST_TYPE,type:s})}else n=this.parseNamedType();return this.expectOptionalToken(p.BANG)?this.node(t,{kind:T.NON_NULL_TYPE,type:n}):n}parseNamedType(){return this.node(this._lexer.token,{kind:T.NAMED_TYPE,name:this.parseName()})}peekDescription(){return this.peek(p.STRING)||this.peek(p.BLOCK_STRING)}parseDescription(){if(this.peekDescription())return this.parseStringLiteral()}parseSchemaDefinition(){const t=this._lexer.token,n=this.parseDescription();this.expectKeyword("schema");const s=this.parseConstDirectives(),r=this.many(p.BRACE_L,this.parseOperationTypeDefinition,p.BRACE_R);return this.node(t,{kind:T.SCHEMA_DEFINITION,description:n,directives:s,operationTypes:r})}parseOperationTypeDefinition(){const t=this._lexer.token,n=this.parseOperationType();this.expectToken(p.COLON);const s=this.parseNamedType();return this.node(t,{kind:T.OPERATION_TYPE_DEFINITION,operation:n,type:s})}parseScalarTypeDefinition(){const t=this._lexer.token,n=this.parseDescription();this.expectKeyword("scalar");const s=this.parseName(),r=this.parseConstDirectives();return this.node(t,{kind:T.SCALAR_TYPE_DEFINITION,description:n,name:s,directives:r})}parseObjectTypeDefinition(){const t=this._lexer.token,n=this.parseDescription();this.expectKeyword("type");const s=this.parseName(),r=this.parseImplementsInterfaces(),i=this.parseConstDirectives(),o=this.parseFieldsDefinition();return this.node(t,{kind:T.OBJECT_TYPE_DEFINITION,description:n,name:s,interfaces:r,directives:i,fields:o})}parseImplementsInterfaces(){return this.expectOptionalKeyword("implements")?this.delimitedMany(p.AMP,this.parseNamedType):[]}parseFieldsDefinition(){return this.optionalMany(p.BRACE_L,this.parseFieldDefinition,p.BRACE_R)}parseFieldDefinition(){const t=this._lexer.token,n=this.parseDescription(),s=this.parseName(),r=this.parseArgumentDefs();this.expectToken(p.COLON);const i=this.parseTypeReference(),o=this.parseConstDirectives();return this.node(t,{kind:T.FIELD_DEFINITION,description:n,name:s,arguments:r,type:i,directives:o})}parseArgumentDefs(){return this.optionalMany(p.PAREN_L,this.parseInputValueDef,p.PAREN_R)}parseInputValueDef(){const t=this._lexer.token,n=this.parseDescription(),s=this.parseName();this.expectToken(p.COLON);const r=this.parseTypeReference();let i;this.expectOptionalToken(p.EQUALS)&&(i=this.parseConstValueLiteral());const o=this.parseConstDirectives();return this.node(t,{kind:T.INPUT_VALUE_DEFINITION,description:n,name:s,type:r,defaultValue:i,directives:o})}parseInterfaceTypeDefinition(){const t=this._lexer.token,n=this.parseDescription();this.expectKeyword("interface");const s=this.parseName(),r=this.parseImplementsInterfaces(),i=this.parseConstDirectives(),o=this.parseFieldsDefinition();return this.node(t,{kind:T.INTERFACE_TYPE_DEFINITION,description:n,name:s,interfaces:r,directives:i,fields:o})}parseUnionTypeDefinition(){const t=this._lexer.token,n=this.parseDescription();this.expectKeyword("union");const s=this.parseName(),r=this.parseConstDirectives(),i=this.parseUnionMemberTypes();return this.node(t,{kind:T.UNION_TYPE_DEFINITION,description:n,name:s,directives:r,types:i})}parseUnionMemberTypes(){return this.expectOptionalToken(p.EQUALS)?this.delimitedMany(p.PIPE,this.parseNamedType):[]}parseEnumTypeDefinition(){const t=this._lexer.token,n=this.parseDescription();this.expectKeyword("enum");const s=this.parseName(),r=this.parseConstDirectives(),i=this.parseEnumValuesDefinition();return this.node(t,{kind:T.ENUM_TYPE_DEFINITION,description:n,name:s,directives:r,values:i})}parseEnumValuesDefinition(){return this.optionalMany(p.BRACE_L,this.parseEnumValueDefinition,p.BRACE_R)}parseEnumValueDefinition(){const t=this._lexer.token,n=this.parseDescription(),s=this.parseEnumValueName(),r=this.parseConstDirectives();return this.node(t,{kind:T.ENUM_VALUE_DEFINITION,description:n,name:s,directives:r})}parseEnumValueName(){if(this._lexer.token.value==="true"||this._lexer.token.value==="false"||this._lexer.token.value==="null")throw b(this._lexer.source,this._lexer.token.start,`${ye(this._lexer.token)} is reserved and cannot be used for an enum value.`);return this.parseName()}parseInputObjectTypeDefinition(){const t=this._lexer.token,n=this.parseDescription();this.expectKeyword("input");const s=this.parseName(),r=this.parseConstDirectives(),i=this.parseInputFieldsDefinition();return this.node(t,{kind:T.INPUT_OBJECT_TYPE_DEFINITION,description:n,name:s,directives:r,fields:i})}parseInputFieldsDefinition(){return this.optionalMany(p.BRACE_L,this.parseInputValueDef,p.BRACE_R)}parseTypeSystemExtension(){const t=this._lexer.lookahead();if(t.kind===p.NAME)switch(t.value){case"schema":return this.parseSchemaExtension();case"scalar":return this.parseScalarTypeExtension();case"type":return this.parseObjectTypeExtension();case"interface":return this.parseInterfaceTypeExtension();case"union":return this.parseUnionTypeExtension();case"enum":return this.parseEnumTypeExtension();case"input":return this.parseInputObjectTypeExtension()}throw this.unexpected(t)}parseSchemaExtension(){const t=this._lexer.token;this.expectKeyword("extend"),this.expectKeyword("schema");const n=this.parseConstDirectives(),s=this.optionalMany(p.BRACE_L,this.parseOperationTypeDefinition,p.BRACE_R);if(n.length===0&&s.length===0)throw this.unexpected();return this.node(t,{kind:T.SCHEMA_EXTENSION,directives:n,operationTypes:s})}parseScalarTypeExtension(){const t=this._lexer.token;this.expectKeyword("extend"),this.expectKeyword("scalar");const n=this.parseName(),s=this.parseConstDirectives();if(s.length===0)throw this.unexpected();return this.node(t,{kind:T.SCALAR_TYPE_EXTENSION,name:n,directives:s})}parseObjectTypeExtension(){const t=this._lexer.token;this.expectKeyword("extend"),this.expectKeyword("type");const n=this.parseName(),s=this.parseImplementsInterfaces(),r=this.parseConstDirectives(),i=this.parseFieldsDefinition();if(s.length===0&&r.length===0&&i.length===0)throw this.unexpected();return this.node(t,{kind:T.OBJECT_TYPE_EXTENSION,name:n,interfaces:s,directives:r,fields:i})}parseInterfaceTypeExtension(){const t=this._lexer.token;this.expectKeyword("extend"),this.expectKeyword("interface");const n=this.parseName(),s=this.parseImplementsInterfaces(),r=this.parseConstDirectives(),i=this.parseFieldsDefinition();if(s.length===0&&r.length===0&&i.length===0)throw this.unexpected();return this.node(t,{kind:T.INTERFACE_TYPE_EXTENSION,name:n,interfaces:s,directives:r,fields:i})}parseUnionTypeExtension(){const t=this._lexer.token;this.expectKeyword("extend"),this.expectKeyword("union");const n=this.parseName(),s=this.parseConstDirectives(),r=this.parseUnionMemberTypes();if(s.length===0&&r.length===0)throw this.unexpected();return this.node(t,{kind:T.UNION_TYPE_EXTENSION,name:n,directives:s,types:r})}parseEnumTypeExtension(){const t=this._lexer.token;this.expectKeyword("extend"),this.expectKeyword("enum");const n=this.parseName(),s=this.parseConstDirectives(),r=this.parseEnumValuesDefinition();if(s.length===0&&r.length===0)throw this.unexpected();return this.node(t,{kind:T.ENUM_TYPE_EXTENSION,name:n,directives:s,values:r})}parseInputObjectTypeExtension(){const t=this._lexer.token;this.expectKeyword("extend"),this.expectKeyword("input");const n=this.parseName(),s=this.parseConstDirectives(),r=this.parseInputFieldsDefinition();if(s.length===0&&r.length===0)throw this.unexpected();return this.node(t,{kind:T.INPUT_OBJECT_TYPE_EXTENSION,name:n,directives:s,fields:r})}parseDirectiveDefinition(){const t=this._lexer.token,n=this.parseDescription();this.expectKeyword("directive"),this.expectToken(p.AT);const s=this.parseName(),r=this.parseArgumentDefs(),i=this.expectOptionalKeyword("repeatable");this.expectKeyword("on");const o=this.parseDirectiveLocations();return this.node(t,{kind:T.DIRECTIVE_DEFINITION,description:n,name:s,arguments:r,repeatable:i,locations:o})}parseDirectiveLocations(){return this.delimitedMany(p.PIPE,this.parseDirectiveLocation)}parseDirectiveLocation(){const t=this._lexer.token,n=this.parseName();if(Object.prototype.hasOwnProperty.call(Ve,n.value))return n;throw this.unexpected(t)}node(t,n){return this._options.noLocation!==!0&&(n.loc=new zs(t,this._lexer.lastToken,this._lexer.source)),n}peek(t){return this._lexer.token.kind===t}expectToken(t){const n=this._lexer.token;if(n.kind===t)return this.advanceLexer(),n;throw b(this._lexer.source,n.start,`Expected ${dn(t)}, found ${ye(n)}.`)}expectOptionalToken(t){return this._lexer.token.kind===t?(this.advanceLexer(),!0):!1}expectKeyword(t){const n=this._lexer.token;if(n.kind===p.NAME&&n.value===t)this.advanceLexer();else throw b(this._lexer.source,n.start,`Expected "${t}", found ${ye(n)}.`)}expectOptionalKeyword(t){const n=this._lexer.token;return n.kind===p.NAME&&n.value===t?(this.advanceLexer(),!0):!1}unexpected(t){const n=t??this._lexer.token;return b(this._lexer.source,n.start,`Unexpected ${ye(n)}.`)}any(t,n,s){this.expectToken(t);const r=[];for(;!this.expectOptionalToken(s);)r.push(n.call(this));return r}optionalMany(t,n,s){if(this.expectOptionalToken(t)){const r=[];do r.push(n.call(this));while(!this.expectOptionalToken(s));return r}return[]}many(t,n,s){this.expectToken(t);const r=[];do r.push(n.call(this));while(!this.expectOptionalToken(s));return r}delimitedMany(t,n){this.expectOptionalToken(t);const s=[];do s.push(n.call(this));while(this.expectOptionalToken(t));return s}advanceLexer(){const{maxTokens:t}=this._options,n=this._lexer.advance();if(t!==void 0&&n.kind!==p.EOF&&(++this._tokenCounter,this._tokenCounter>t))throw b(this._lexer.source,n.start,`Document contains more that ${t} tokens. Parsing aborted.`)}}function ye(e){const t=e.value;return dn(e.kind)+(t!=null?` "${t}"`:"")}function dn(e){return Zs(e)?`"${e}"`:e}function vr(e){return`"${e.replace(Tr,_r)}"`}const Tr=/[\x00-\x1f\x22\x5c\x7f-\x9f]/g;function _r(e){return Ir[e.charCodeAt(0)]}const Ir=["\\u0000","\\u0001","\\u0002","\\u0003","\\u0004","\\u0005","\\u0006","\\u0007","\\b","\\t","\\n","\\u000B","\\f","\\r","\\u000E","\\u000F","\\u0010","\\u0011","\\u0012","\\u0013","\\u0014","\\u0015","\\u0016","\\u0017","\\u0018","\\u0019","\\u001A","\\u001B","\\u001C","\\u001D","\\u001E","\\u001F","","",'\\"',"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","\\\\","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","\\u007F","\\u0080","\\u0081","\\u0082","\\u0083","\\u0084","\\u0085","\\u0086","\\u0087","\\u0088","\\u0089","\\u008A","\\u008B","\\u008C","\\u008D","\\u008E","\\u008F","\\u0090","\\u0091","\\u0092","\\u0093","\\u0094","\\u0095","\\u0096","\\u0097","\\u0098","\\u0099","\\u009A","\\u009B","\\u009C","\\u009D","\\u009E","\\u009F"],Sr=Object.freeze({});function xr(e,t,n=nn){const s=new Map;for(const A of Object.values(T))s.set(A,Ar(t,A));let r,i=Array.isArray(e),o=[e],a=-1,c=[],u=e,f,l;const h=[],m=[];do{a++;const A=a===o.length,R=A&&c.length!==0;if(A){if(f=m.length===0?void 0:h[h.length-1],u=l,l=m.pop(),R)if(i){u=u.slice();let L=0;for(const[J,le]of c){const he=J-L;le===null?(u.splice(he,1),L++):u[he]=le}}else{u=Object.defineProperties({},Object.getOwnPropertyDescriptors(u));for(const[L,J]of c)u[L]=J}a=r.index,o=r.keys,c=r.edits,i=r.inArray,r=r.prev}else if(l){if(f=i?a:o[a],u=l[f],u==null)continue;h.push(f)}let D;if(!Array.isArray(u)){var y,v;Ot(u)||ge(!1,`Invalid AST Node: ${ct(u)}.`);const L=A?(y=s.get(u.kind))===null||y===void 0?void 0:y.leave:(v=s.get(u.kind))===null||v===void 0?void 0:v.enter;if(D=L==null?void 0:L.call(t,u,f,l,h,m),D===Sr)break;if(D===!1){if(!A){h.pop();continue}}else if(D!==void 0&&(c.push([f,D]),!A))if(Ot(D))u=D;else{h.pop();continue}}if(D===void 0&&R&&c.push([f,u]),A)h.pop();else{var S;r={inArray:i,index:a,keys:o,edits:c,prev:r},i=Array.isArray(u),o=i?u:(S=n[u.kind])!==null&&S!==void 0?S:[],a=-1,c=[],l&&m.push(l),l=u}}while(r!==void 0);return c.length!==0?c[c.length-1][1]:e}function Ar(e,t){const n=e[t];return typeof n=="object"?n:typeof n=="function"?{enter:n,leave:void 0}:{enter:e.enter,leave:e.leave}}function ln(e){return xr(e,br)}const wr=80,br={Name:{leave:e=>e.value},Variable:{leave:e=>"$"+e.name},Document:{leave:e=>E(e.definitions,`
|
|
25
|
+
|
|
26
|
+
`)},OperationDefinition:{leave(e){const t=I("(",E(e.variableDefinitions,", "),")"),n=E([e.operation,E([e.name,t]),E(e.directives," ")]," ");return(n==="query"?"":n+" ")+e.selectionSet}},VariableDefinition:{leave:({variable:e,type:t,defaultValue:n,directives:s})=>e+": "+t+I(" = ",n)+I(" ",E(s," "))},SelectionSet:{leave:({selections:e})=>M(e)},Field:{leave({alias:e,name:t,arguments:n,directives:s,selectionSet:r}){const i=I("",e,": ")+t;let o=i+I("(",E(n,", "),")");return o.length>wr&&(o=i+I(`(
|
|
27
|
+
`,Ee(E(n,`
|
|
28
|
+
`)),`
|
|
29
|
+
)`)),E([o,E(s," "),r]," ")}},Argument:{leave:({name:e,value:t})=>e+": "+t},FragmentSpread:{leave:({name:e,directives:t})=>"..."+e+I(" ",E(t," "))},InlineFragment:{leave:({typeCondition:e,directives:t,selectionSet:n})=>E(["...",I("on ",e),E(t," "),n]," ")},FragmentDefinition:{leave:({name:e,typeCondition:t,variableDefinitions:n,directives:s,selectionSet:r})=>`fragment ${e}${I("(",E(n,", "),")")} on ${t} ${I("",E(s," ")," ")}`+r},IntValue:{leave:({value:e})=>e},FloatValue:{leave:({value:e})=>e},StringValue:{leave:({value:e,block:t})=>t?Ws(e):vr(e)},BooleanValue:{leave:({value:e})=>e?"true":"false"},NullValue:{leave:()=>"null"},EnumValue:{leave:({value:e})=>e},ListValue:{leave:({values:e})=>"["+E(e,", ")+"]"},ObjectValue:{leave:({fields:e})=>"{"+E(e,", ")+"}"},ObjectField:{leave:({name:e,value:t})=>e+": "+t},Directive:{leave:({name:e,arguments:t})=>"@"+e+I("(",E(t,", "),")")},NamedType:{leave:({name:e})=>e},ListType:{leave:({type:e})=>"["+e+"]"},NonNullType:{leave:({type:e})=>e+"!"},SchemaDefinition:{leave:({description:e,directives:t,operationTypes:n})=>I("",e,`
|
|
30
|
+
`)+E(["schema",E(t," "),M(n)]," ")},OperationTypeDefinition:{leave:({operation:e,type:t})=>e+": "+t},ScalarTypeDefinition:{leave:({description:e,name:t,directives:n})=>I("",e,`
|
|
31
|
+
`)+E(["scalar",t,E(n," ")]," ")},ObjectTypeDefinition:{leave:({description:e,name:t,interfaces:n,directives:s,fields:r})=>I("",e,`
|
|
32
|
+
`)+E(["type",t,I("implements ",E(n," & ")),E(s," "),M(r)]," ")},FieldDefinition:{leave:({description:e,name:t,arguments:n,type:s,directives:r})=>I("",e,`
|
|
33
|
+
`)+t+(kt(n)?I(`(
|
|
34
|
+
`,Ee(E(n,`
|
|
35
|
+
`)),`
|
|
36
|
+
)`):I("(",E(n,", "),")"))+": "+s+I(" ",E(r," "))},InputValueDefinition:{leave:({description:e,name:t,type:n,defaultValue:s,directives:r})=>I("",e,`
|
|
37
|
+
`)+E([t+": "+n,I("= ",s),E(r," ")]," ")},InterfaceTypeDefinition:{leave:({description:e,name:t,interfaces:n,directives:s,fields:r})=>I("",e,`
|
|
38
|
+
`)+E(["interface",t,I("implements ",E(n," & ")),E(s," "),M(r)]," ")},UnionTypeDefinition:{leave:({description:e,name:t,directives:n,types:s})=>I("",e,`
|
|
39
|
+
`)+E(["union",t,E(n," "),I("= ",E(s," | "))]," ")},EnumTypeDefinition:{leave:({description:e,name:t,directives:n,values:s})=>I("",e,`
|
|
40
|
+
`)+E(["enum",t,E(n," "),M(s)]," ")},EnumValueDefinition:{leave:({description:e,name:t,directives:n})=>I("",e,`
|
|
41
|
+
`)+E([t,E(n," ")]," ")},InputObjectTypeDefinition:{leave:({description:e,name:t,directives:n,fields:s})=>I("",e,`
|
|
42
|
+
`)+E(["input",t,E(n," "),M(s)]," ")},DirectiveDefinition:{leave:({description:e,name:t,arguments:n,repeatable:s,locations:r})=>I("",e,`
|
|
43
|
+
`)+"directive @"+t+(kt(n)?I(`(
|
|
44
|
+
`,Ee(E(n,`
|
|
45
|
+
`)),`
|
|
46
|
+
)`):I("(",E(n,", "),")"))+(s?" repeatable":"")+" on "+E(r," | ")},SchemaExtension:{leave:({directives:e,operationTypes:t})=>E(["extend schema",E(e," "),M(t)]," ")},ScalarTypeExtension:{leave:({name:e,directives:t})=>E(["extend scalar",e,E(t," ")]," ")},ObjectTypeExtension:{leave:({name:e,interfaces:t,directives:n,fields:s})=>E(["extend type",e,I("implements ",E(t," & ")),E(n," "),M(s)]," ")},InterfaceTypeExtension:{leave:({name:e,interfaces:t,directives:n,fields:s})=>E(["extend interface",e,I("implements ",E(t," & ")),E(n," "),M(s)]," ")},UnionTypeExtension:{leave:({name:e,directives:t,types:n})=>E(["extend union",e,E(t," "),I("= ",E(n," | "))]," ")},EnumTypeExtension:{leave:({name:e,directives:t,values:n})=>E(["extend enum",e,E(t," "),M(n)]," ")},InputObjectTypeExtension:{leave:({name:e,directives:t,fields:n})=>E(["extend input",e,E(t," "),M(n)]," ")}};function E(e,t=""){var n;return(n=e==null?void 0:e.filter(s=>s).join(t))!==null&&n!==void 0?n:""}function M(e){return I(`{
|
|
47
|
+
`,Ee(E(e,`
|
|
48
|
+
`)),`
|
|
49
|
+
}`)}function I(e,t,n=""){return t!=null&&t!==""?e+t+n:""}function Ee(e){return I(" ",e.replace(/\n/g,`
|
|
50
|
+
`))}function kt(e){var t;return(t=e==null?void 0:e.some(n=>n.includes(`
|
|
51
|
+
`)))!==null&&t!==void 0?t:!1}const Ct=e=>{var s,r;let t;const n=e.definitions.filter(i=>i.kind==="OperationDefinition");return n.length===1&&(t=(r=(s=n[0])==null?void 0:s.name)==null?void 0:r.value),t},Le=e=>{if(typeof e=="string"){let n;try{const s=gr(e);n=Ct(s)}catch{}return{query:e,operationName:n}}const t=Ct(e);return{query:ln(e),operationName:t}};class ae extends Error{constructor(t,n){const s=`${ae.extractMessage(t)}: ${JSON.stringify({response:t,request:n})}`;super(s),Object.setPrototypeOf(this,ae.prototype),this.response=t,this.request=n,typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,ae)}static extractMessage(t){var n,s;return((s=(n=t.errors)==null?void 0:n[0])==null?void 0:s.message)??`GraphQL Error (Code: ${t.status})`}}var Or=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Nr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Ge={exports:{}};(function(e,t){var n=typeof self<"u"?self:Or,s=function(){function i(){this.fetch=!1,this.DOMException=n.DOMException}return i.prototype=n,new i}();(function(i){(function(o){var a={searchParams:"URLSearchParams"in i,iterable:"Symbol"in i&&"iterator"in Symbol,blob:"FileReader"in i&&"Blob"in i&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in i,arrayBuffer:"ArrayBuffer"in i};function c(d){return d&&DataView.prototype.isPrototypeOf(d)}if(a.arrayBuffer)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],f=ArrayBuffer.isView||function(d){return d&&u.indexOf(Object.prototype.toString.call(d))>-1};function l(d){if(typeof d!="string"&&(d=String(d)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(d))throw new TypeError("Invalid character in header field name");return d.toLowerCase()}function h(d){return typeof d!="string"&&(d=String(d)),d}function m(d){var g={next:function(){var _=d.shift();return{done:_===void 0,value:_}}};return a.iterable&&(g[Symbol.iterator]=function(){return g}),g}function y(d){this.map={},d instanceof y?d.forEach(function(g,_){this.append(_,g)},this):Array.isArray(d)?d.forEach(function(g){this.append(g[0],g[1])},this):d&&Object.getOwnPropertyNames(d).forEach(function(g){this.append(g,d[g])},this)}y.prototype.append=function(d,g){d=l(d),g=h(g);var _=this.map[d];this.map[d]=_?_+", "+g:g},y.prototype.delete=function(d){delete this.map[l(d)]},y.prototype.get=function(d){return d=l(d),this.has(d)?this.map[d]:null},y.prototype.has=function(d){return this.map.hasOwnProperty(l(d))},y.prototype.set=function(d,g){this.map[l(d)]=h(g)},y.prototype.forEach=function(d,g){for(var _ in this.map)this.map.hasOwnProperty(_)&&d.call(g,this.map[_],_,this)},y.prototype.keys=function(){var d=[];return this.forEach(function(g,_){d.push(_)}),m(d)},y.prototype.values=function(){var d=[];return this.forEach(function(g){d.push(g)}),m(d)},y.prototype.entries=function(){var d=[];return this.forEach(function(g,_){d.push([_,g])}),m(d)},a.iterable&&(y.prototype[Symbol.iterator]=y.prototype.entries);function v(d){if(d.bodyUsed)return Promise.reject(new TypeError("Already read"));d.bodyUsed=!0}function S(d){return new Promise(function(g,_){d.onload=function(){g(d.result)},d.onerror=function(){_(d.error)}})}function A(d){var g=new FileReader,_=S(g);return g.readAsArrayBuffer(d),_}function R(d){var g=new FileReader,_=S(g);return g.readAsText(d),_}function D(d){for(var g=new Uint8Array(d),_=new Array(g.length),N=0;N<g.length;N++)_[N]=String.fromCharCode(g[N]);return _.join("")}function L(d){if(d.slice)return d.slice(0);var g=new Uint8Array(d.byteLength);return g.set(new Uint8Array(d)),g.buffer}function J(){return this.bodyUsed=!1,this._initBody=function(d){this._bodyInit=d,d?typeof d=="string"?this._bodyText=d:a.blob&&Blob.prototype.isPrototypeOf(d)?this._bodyBlob=d:a.formData&&FormData.prototype.isPrototypeOf(d)?this._bodyFormData=d:a.searchParams&&URLSearchParams.prototype.isPrototypeOf(d)?this._bodyText=d.toString():a.arrayBuffer&&a.blob&&c(d)?(this._bodyArrayBuffer=L(d.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(d)||f(d))?this._bodyArrayBuffer=L(d):this._bodyText=d=Object.prototype.toString.call(d):this._bodyText="",this.headers.get("content-type")||(typeof d=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):a.searchParams&&URLSearchParams.prototype.isPrototypeOf(d)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},a.blob&&(this.blob=function(){var d=v(this);if(d)return d;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?v(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(A)}),this.text=function(){var d=v(this);if(d)return d;if(this._bodyBlob)return R(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(D(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},a.formData&&(this.formData=function(){return this.text().then(pn)}),this.json=function(){return this.text().then(JSON.parse)},this}var le=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function he(d){var g=d.toUpperCase();return le.indexOf(g)>-1?g:d}function $(d,g){g=g||{};var _=g.body;if(d instanceof $){if(d.bodyUsed)throw new TypeError("Already read");this.url=d.url,this.credentials=d.credentials,g.headers||(this.headers=new y(d.headers)),this.method=d.method,this.mode=d.mode,this.signal=d.signal,!_&&d._bodyInit!=null&&(_=d._bodyInit,d.bodyUsed=!0)}else this.url=String(d);if(this.credentials=g.credentials||this.credentials||"same-origin",(g.headers||!this.headers)&&(this.headers=new y(g.headers)),this.method=he(g.method||this.method||"GET"),this.mode=g.mode||this.mode||null,this.signal=g.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&_)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(_)}$.prototype.clone=function(){return new $(this,{body:this._bodyInit})};function pn(d){var g=new FormData;return d.trim().split("&").forEach(function(_){if(_){var N=_.split("="),O=N.shift().replace(/\+/g," "),x=N.join("=").replace(/\+/g," ");g.append(decodeURIComponent(O),decodeURIComponent(x))}}),g}function yn(d){var g=new y,_=d.replace(/\r?\n[\t ]+/g," ");return _.split(/\r?\n/).forEach(function(N){var O=N.split(":"),x=O.shift().trim();if(x){var fe=O.join(":").trim();g.append(x,fe)}}),g}J.call($.prototype);function P(d,g){g||(g={}),this.type="default",this.status=g.status===void 0?200:g.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in g?g.statusText:"OK",this.headers=new y(g.headers),this.url=g.url||"",this._initBody(d)}J.call(P.prototype),P.prototype.clone=function(){return new P(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new y(this.headers),url:this.url})},P.error=function(){var d=new P(null,{status:0,statusText:""});return d.type="error",d};var mn=[301,302,303,307,308];P.redirect=function(d,g){if(mn.indexOf(g)===-1)throw new RangeError("Invalid status code");return new P(null,{status:g,headers:{location:d}})},o.DOMException=i.DOMException;try{new o.DOMException}catch{o.DOMException=function(g,_){this.message=g,this.name=_;var N=Error(g);this.stack=N.stack},o.DOMException.prototype=Object.create(Error.prototype),o.DOMException.prototype.constructor=o.DOMException}function Oe(d,g){return new Promise(function(_,N){var O=new $(d,g);if(O.signal&&O.signal.aborted)return N(new o.DOMException("Aborted","AbortError"));var x=new XMLHttpRequest;function fe(){x.abort()}x.onload=function(){var re={status:x.status,statusText:x.statusText,headers:yn(x.getAllResponseHeaders()||"")};re.url="responseURL"in x?x.responseURL:re.headers.get("X-Request-URL");var Ne="response"in x?x.response:x.responseText;_(new P(Ne,re))},x.onerror=function(){N(new TypeError("Network request failed"))},x.ontimeout=function(){N(new TypeError("Network request failed"))},x.onabort=function(){N(new o.DOMException("Aborted","AbortError"))},x.open(O.method,O.url,!0),O.credentials==="include"?x.withCredentials=!0:O.credentials==="omit"&&(x.withCredentials=!1),"responseType"in x&&a.blob&&(x.responseType="blob"),O.headers.forEach(function(re,Ne){x.setRequestHeader(Ne,re)}),O.signal&&(O.signal.addEventListener("abort",fe),x.onreadystatechange=function(){x.readyState===4&&O.signal.removeEventListener("abort",fe)}),x.send(typeof O._bodyInit>"u"?null:O._bodyInit)})}return Oe.polyfill=!0,i.fetch||(i.fetch=Oe,i.Headers=y,i.Request=$,i.Response=P),o.Headers=y,o.Request=$,o.Response=P,o.fetch=Oe,Object.defineProperty(o,"__esModule",{value:!0}),o})({})})(s),s.fetch.ponyfill=!0,delete s.fetch.polyfill;var r=s;t=r.fetch,t.default=r.fetch,t.fetch=r.fetch,t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response,e.exports=t})(Ge,Ge.exports);var Se=Ge.exports;const ve=Nr(Se),kr=gn({__proto__:null,default:ve},[Se]),Q=e=>{let t={};return e&&(typeof Headers<"u"&&e instanceof Headers||kr&&Se.Headers&&e instanceof Se.Headers?t=Ps(e):Array.isArray(e)?e.forEach(([n,s])=>{n&&s!==void 0&&(t[n]=s)}):t=e),t},Dt=e=>e.replace(/([\s,]|#[^\n\r]+)+/g," ").trim(),Cr=e=>{if(!Array.isArray(e.query)){const s=e,r=[`query=${encodeURIComponent(Dt(s.query))}`];return e.variables&&r.push(`variables=${encodeURIComponent(s.jsonSerializer.stringify(s.variables))}`),s.operationName&&r.push(`operationName=${encodeURIComponent(s.operationName)}`),r.join("&")}if(typeof e.variables<"u"&&!Array.isArray(e.variables))throw new Error("Cannot create query with given variable type, array expected");const t=e,n=e.query.reduce((s,r,i)=>(s.push({query:Dt(r),variables:t.variables?t.jsonSerializer.stringify(t.variables[i]):void 0}),s),[]);return`query=${encodeURIComponent(t.jsonSerializer.stringify(n))}`},Dr=e=>async t=>{const{url:n,query:s,variables:r,operationName:i,fetch:o,fetchOptions:a,middleware:c}=t,u={...t.headers};let f="",l;e==="POST"?(l=Rr(s,r,i,a.jsonSerializer),typeof l=="string"&&(u["Content-Type"]="application/json")):f=Cr({query:s,variables:r,operationName:i,jsonSerializer:a.jsonSerializer??ot});const h={method:e,headers:u,body:l,...a};let m=n,y=h;if(c){const v=await Promise.resolve(c({...h,url:n,operationName:i,variables:r})),{url:S,...A}=v;m=S,y=A}return f&&(m=`${m}?${f}`),await o(m,y)};class hn{constructor(t,n={}){this.url=t,this.requestConfig=n,this.rawRequest=async(...s)=>{const[r,i,o]=s,a=Fs(r,i,o),{headers:c,fetch:u=ve,method:f="POST",requestMiddleware:l,responseMiddleware:h,...m}=this.requestConfig,{url:y}=this;a.signal!==void 0&&(m.signal=a.signal);const{operationName:v}=Le(a.query);return Me({url:y,query:a.query,variables:a.variables,headers:{...Q(Pe(c)),...Q(a.requestHeaders)},operationName:v,fetch:u,method:f,fetchOptions:m,middleware:l}).then(S=>(h&&h(S),S)).catch(S=>{throw h&&h(S),S})}}async request(t,...n){const[s,r]=n,i=qs(t,s,r),{headers:o,fetch:a=ve,method:c="POST",requestMiddleware:u,responseMiddleware:f,...l}=this.requestConfig,{url:h}=this;i.signal!==void 0&&(l.signal=i.signal);const{query:m,operationName:y}=Le(i.document);return Me({url:h,query:m,variables:i.variables,headers:{...Q(Pe(o)),...Q(i.requestHeaders)},operationName:y,fetch:a,method:c,fetchOptions:l,middleware:u}).then(v=>(f&&f(v),v.data)).catch(v=>{throw f&&f(v),v})}batchRequests(t,n){const s=Us(t,n),{headers:r,...i}=this.requestConfig;s.signal!==void 0&&(i.signal=s.signal);const o=s.documents.map(({document:c})=>Le(c).query),a=s.documents.map(({variables:c})=>c);return Me({url:this.url,query:o,variables:a,headers:{...Q(Pe(r)),...Q(s.requestHeaders)},operationName:void 0,fetch:this.requestConfig.fetch??ve,method:this.requestConfig.method||"POST",fetchOptions:i,middleware:this.requestConfig.requestMiddleware}).then(c=>(this.requestConfig.responseMiddleware&&this.requestConfig.responseMiddleware(c),c.data)).catch(c=>{throw this.requestConfig.responseMiddleware&&this.requestConfig.responseMiddleware(c),c})}setHeaders(t){return this.requestConfig.headers=t,this}setHeader(t,n){const{headers:s}=this.requestConfig;return s?s[t]=n:this.requestConfig.headers={[t]:n},this}setEndpoint(t){return this.url=t,this}}const Me=async e=>{const{query:t,variables:n,fetchOptions:s}=e,r=Dr(Ms(e.method??"post")),i=Array.isArray(e.query),o=await r(e),a=await Lr(o,s.jsonSerializer??ot),c=Array.isArray(a)?!a.some(({data:f})=>!f):!!a.data,u=Array.isArray(a)||!a.errors||Array.isArray(a.errors)&&!a.errors.length||s.errorPolicy==="all"||s.errorPolicy==="ignore";if(o.ok&&u&&c){const{errors:f,...l}=(Array.isArray(a),a),h=s.errorPolicy==="ignore"?l:a;return{...i?{data:h}:h,headers:o.headers,status:o.status}}else{const f=typeof a=="string"?{error:a}:a;throw new ae({...f,status:o.status,headers:o.headers},{query:t,variables:n})}};async function fn(e,t,...n){const s=Bs(e,t,...n);return new hn(s.url).request({...s})}const Rr=(e,t,n,s)=>{const r=s??ot;if(!Array.isArray(e))return r.stringify({query:e,variables:t,operationName:n});if(typeof t<"u"&&!Array.isArray(t))throw new Error("Cannot create request body with given variable type, array expected");const i=e.reduce((o,a,c)=>(o.push({query:a,variables:t?t[c]:void 0}),o),[]);return r.stringify(i)},Lr=async(e,t)=>{let n;return e.headers.forEach((s,r)=>{r.toLowerCase()==="content-type"&&(n=s)}),n&&(n.toLowerCase().startsWith("application/json")||n.toLowerCase().startsWith("application/graphql+json")||n.toLowerCase().startsWith("application/graphql-response+json"))?t.parse(await e.text()):e.text()},Pe=e=>typeof e=="function"?e():e,Mr=Z(async({input:e})=>{var t;if(!e.endpoint||e.endpoint==="")throw new Error("No endpoint provided.");if(e.items.length<1)throw new Error("No items provided.");if(!e.document)throw new Error("No request document provided.");if(!e.requestHeaders)throw new Error("No request headers provided.");try{const n=await fn(e.endpoint,e.document,{items:e.items},e.requestHeaders);if(!((t=n.quoteAddItem)!=null&&t.quote))throw new Error("Could not add items to quote.");return{type:"ADD_ITEMS_SUCCESS",quote:n.quoteAddItem.quote}}catch{throw new Error("Request to add item(s) failed.")}}),Pr=Z(async({input:e})=>{var t;if(!e.endpoint||e.endpoint==="")throw new Error("No endpoint provided.");if(e.items.length<1)throw new Error("No items provided.");try{const n=await fn(e.endpoint,"");if(!((t=n.quoteRemoveItem)!=null&&t.quote))throw new Error("Could not remove items from quote.");return{type:"REMOVE_ITEMS_SUCCESS",quote:n.quoteRemoveItem.quote}}catch{throw new Error("Request to remove item(s) failed.")}}),qr=typeof window>"u",Fr=Z(async({input:e})=>{var n,s,r,i;if(!e.endpoint)throw console.log("no endpoint"),new Error("No endpoint provided.");if(!e.endpointSsr)throw console.log("no endpoint ssr"),new Error("No SSR endpoint provided.");if(!e.locale)throw console.log("no locale"),new Error("No locale provided.");if(!e.document)throw console.log("no request document"),new Error("No request document provided.");if(!e.requestHeaders)throw console.log("no headers"),new Error("No request headers provided.");const t=new hn(qr?e.endpointSsr:e.endpoint,{credentials:"include",mode:"cors",method:"POST"});try{const{data:o,headers:a,status:c,errors:u,extensions:f}=await t.rawRequest(ln(e.document),{},typeof window>"u"?{...e.requestHeaders,Cookie:`quote_${e.locale}=${e.quoteId??""}`}:e.requestHeaders),l=o;if(!((n=l.refreshQuote)!=null&&n.quote))throw console.log("userError: ",(s=l.refreshQuote)==null?void 0:s.userErrors[0].code,(r=l.refreshQuote)==null?void 0:r.userErrors[0].field,(i=l.refreshQuote)==null?void 0:i.userErrors[0].message),new Error("Could not add items to quote.");return{type:"REFRESH_SUCCESS",quote:l.refreshQuote.quote}}catch(o){throw console.log("refresh error",o),new Error("Request to add item(s) failed.")}}),Ur=({context:e})=>!!e.quote.items&&e.quote.items.length>0,Br=({context:e})=>typeof window>"u"&&e.quote.id!==""||typeof window<"u",ze=Ae({types:{context:{},events:{},input:{}},actions:{addItems:C(Ds),removeItems:C(Rs),refresh:C(Ls)},actors:{addItems:Mr,removeItems:Pr,refresh:Fr},guards:{canRefresh:Br,hasItems:Ur}}).createMachine({id:"quote",initial:"initializing",context:({input:e})=>{var t,n,s,r,i,o,a,c,u,f,l,h,m,y;return{quote:{id:"",locale:"",baseCurrency:"USD",currencyConversionRate:1,dateCreated:null,dateLastUpdated:null,currency:"USD",items:[],promotions:[],shippingAddresses:{available:[],selected:null},totals:{discount:0,tax:0,shipping:0,shippingTax:0,subtotal:0,grandTotal:0},appliedPriceRules:[],appliedPromotions:[],shippingMethods:[],paymentMethods:[],storeCredit:[],rewards:[],giftCards:[],...(t=e==null?void 0:e.initialContext)==null?void 0:t.quote},endpoints:{client:"",server:"",...(n=e==null?void 0:e.initialContext)==null?void 0:n.endpoints},graphql:{refresh:{document:((i=(r=(s=e==null?void 0:e.initialContext)==null?void 0:s.graphql)==null?void 0:r.refresh)==null?void 0:i.document)??"",requestHeaders:((c=(a=(o=e==null?void 0:e.initialContext)==null?void 0:o.graphql)==null?void 0:a.refresh)==null?void 0:c.requestHeaders)??void 0},addItems:{document:((l=(f=(u=e==null?void 0:e.initialContext)==null?void 0:u.graphql)==null?void 0:f.addItems)==null?void 0:l.document)??"",requestHeaders:((y=(m=(h=e==null?void 0:e.initialContext)==null?void 0:h.graphql)==null?void 0:m.addItems)==null?void 0:y.requestHeaders)??void 0}},errors:[]}},states:{uninitialized:{on:{REFRESH:"refreshing"}},empty:{on:{ADD_ITEMS:"addingItems"}},active:{on:{ADD_ITEMS:"addingItems",REMOVE_ITEMS:"removingItems",REFRESH:"refreshing"}},initializing:{always:[{target:"refreshing",guard:"canRefresh"},{target:"uninitialized"}]},refreshing:{invoke:{input:({context:e})=>({endpoint:e.endpoints.client,endpointSsr:e.endpoints.server,quoteId:e.quote.id,locale:e.quote.locale,document:e.graphql.refresh.document,requestHeaders:e.graphql.refresh.requestHeaders}),src:"refresh",onDone:[{actions:["refresh"],guard:"hasItems",target:"active"},{actions:["refresh"],target:"empty"}],onError:{target:"empty"}}},addingItems:{invoke:{input:({context:e,event:t})=>{var n,s;return{endpoint:e.endpoints.client,items:t.type==="ADD_ITEMS"?t.items:[],document:(n=e.graphql.addItems)==null?void 0:n.document,requestHeaders:(s=e.graphql.addItems)==null?void 0:s.requestHeaders}},src:"addItems",onDone:[{actions:["addItems"],target:"active"}],onError:[{guard:"hasItems",target:"active"},{target:"empty"}]}},removingItems:{}}}),ut=F.createContext({}),jr=()=>({quoteActor:F.useContext(ut)}),$r=async(e={inspect:void 0,quote:{id:"",locale:""},endpoints:{client:"",server:""},graphql:{}})=>typeof window<"u"?(console.warn("App.getInitialProps::getAuth should not be run on the frontend. You are probably missing getServerSideProps in your page."),B(ze,{inspect:e.inspect,input:{initialContext:{endpoints:e.endpoints}}}).start()):B(ze,{input:{initialContext:{endpoints:e.endpoints,graphql:e.graphql,quote:{id:e.quote.id??"",locale:e.quote.locale??""}}},inspect:e.inspect}).start();function Vr({actor:e,children:t}){return Je.jsx(ut.Provider,{value:e,children:t})}exports.AuthContext=rt;exports.AuthProvider=bs;exports.QuoteContext=ut;exports.QuoteProvider=Vr;exports.ToastContext=it;exports.ToastProvider=Cs;exports.authMachine=je;exports.getAuth=ws;exports.getQuote=$r;exports.quoteMachine=ze;exports.timerMachine=Zt;exports.toastMachine=Ns;exports.useAuth=As;exports.useQuote=jr;exports.useToast=ks;
|