@nhost/nhost-js 1.1.9 → 1.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts CHANGED
@@ -17,3 +17,4 @@ export interface GraphqlResponse<T = object> {
17
17
  errors?: object[];
18
18
  data?: T;
19
19
  }
20
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAE1C,oBAAY,sBAAsB,CAAC,CAAC,GAAG,OAAO,IAC1C;IACE,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;CACjC,GACD;IACE,IAAI,EAAE,CAAC,CAAA;IACP,KAAK,EAAE,IAAI,CAAA;CACZ,CAAA;AAEL,oBAAY,oBAAoB,CAAC,CAAC,GAAG,OAAO,IACxC;IACE,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;IACrB,KAAK,EAAE,IAAI,CAAA;CACZ,GACD;IACE,GAAG,EAAE,IAAI,CAAA;IACT,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAEL,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,MAAM;IACzC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,IAAI,CAAC,EAAE,CAAC,CAAA;CACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nhost/nhost-js",
3
- "version": "1.1.9",
3
+ "version": "1.1.12",
4
4
  "description": "Nhost JavaScript SDK",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -21,51 +21,52 @@
21
21
  "url": "git+https://github.com/nhost/nhost.git"
22
22
  },
23
23
  "main": "dist/index.cjs.js",
24
+ "module": "dist/index.es.js",
25
+ "types": "dist/index.d.ts",
26
+ "source": "src/index.ts",
27
+ "files": [
28
+ "dist",
29
+ "umd",
30
+ "README.md"
31
+ ],
32
+ "exports": {
33
+ ".": {
34
+ "import": "./dist/index.es.js",
35
+ "require": "./dist/index.cjs.js"
36
+ }
37
+ },
24
38
  "publishConfig": {
25
39
  "access": "public"
26
40
  },
27
- "files": [
28
- "dist"
29
- ],
30
41
  "dependencies": {
31
- "@nhost/hasura-auth-js": "^1.1.4",
32
- "@nhost/hasura-storage-js": "^0.2.0",
33
- "axios": "^0.23.0",
42
+ "@nhost/hasura-auth-js": "1.1.7",
43
+ "@nhost/hasura-storage-js": "0.2.2",
44
+ "axios": "^0.27.2",
34
45
  "jwt-decode": "^3.1.2",
35
46
  "query-string": "^7.0.1"
36
47
  },
37
48
  "devDependencies": {
38
- "@nhost/core": "^0.5.2",
39
- "@nhost/docgen": "*",
49
+ "@nhost/docgen": "0.1.1",
40
50
  "graphql": "16"
41
51
  },
42
52
  "peerDependencies": {
43
53
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
44
54
  },
45
55
  "scripts": {
46
- "build": "run-s build:esbuild build:types",
47
- "build:esbuild": "node ../../esbuild.lib.js",
48
- "build:types": "tsc --build tsconfig.types.json",
49
- "test": "pnpm jest --runInBand --config ../../jest.config.base.js",
56
+ "dev": "vite build --config ../../config/vite.lib.dev.config.js",
57
+ "build": "run-p build:lib build:umd",
58
+ "build:lib": "vite build --config ../../config/vite.lib.config.js",
59
+ "build:umd": "vite build --config ../../config/vite.lib.umd.config.js",
60
+ "test": "vitest run --config ../../config/vite.lib.config.js",
61
+ "test:watch": "vitest --config ../../config/vite.lib.config.js",
50
62
  "prettier": "prettier --check src/",
51
63
  "prettier:fix": "prettier --write src/",
52
64
  "lint": "eslint . --ext .ts,.tsx",
53
65
  "lint:fix": "eslint . --ext .ts,.tsx --fix",
54
66
  "verify": "run-p prettier lint",
55
67
  "verify:fix": "run-p prettier:fix lint:fix",
56
- "typedoc": "typedoc --options ./nhost-js.typedoc.json",
68
+ "typedoc": "typedoc --options ./nhost-js.typedoc.json --tsconfig ./typedoc.tsconfig.json",
57
69
  "docgen": "pnpm typedoc && docgen --config ./nhost-js.docgen.json"
58
70
  },
59
- "exports": {
60
- ".": {
61
- "import": {
62
- "node": "./dist/index.cjs.js",
63
- "default": "./dist/index.es.js"
64
- },
65
- "require": "./dist/index.cjs.js"
66
- }
67
- },
68
- "module": "dist/index.es.js",
69
- "typings": "./dist/index.d.ts",
70
71
  "readme": "<h1 align=\"center\">@nhost/nhost-js</h1>\n<h2 align=\"center\">Nhost JavaScript SDK</h2>\n\n<p align=\"center\">\n <img alt=\"npm\" src=\"https://img.shields.io/npm/v/@nhost/nhost-js\">\n <img alt=\"npm\" src=\"https://img.shields.io/npm/dm/@nhost/nhost-js\">\n <a href=\"LICENSE\">\n <img src=\"https://img.shields.io/badge/license-MIT-yellow.svg\" alt=\"license: MIT\" />\n </a>\n <a href=\"https://prettier.io\">\n <img src=\"https://img.shields.io/badge/code_style-prettier-ff69b4.svg\" alt=\"code style: prettier\" />\n </a>\n</p>\n\n## Get Started\n\n### Install\n\n```\nnpm install @nhost/nhost-js\n# or yarn\nyarn add @nhost/nhost-js\n```\n\n### Initialize\n\n```js\nimport { NhostClient } from '@nhost/nhost-js'\n\nconst nhost = new NhostClient({\n backendUrl: 'https://xxx.nhost.run'\n})\n```\n\n## Features\n\n### GraphQL\n\nAccess Nhost GraphQL methods using `nhost.graphql`.\n\n### Authentication\n\nAccess Nhost Auth methods using `nhost.auth`.\n\n### Storage\n\nAccess Nhost Storage methods using `nhost.storage`.\n\n### Functions\n\nAccess Nhost Functions methods via `nhost.functions`.\n\n## Documentation\n\n[https://docs.nhost.io/reference/javascript](https://docs.nhost.io/reference/javascript)\n"
71
72
  }
@@ -0,0 +1,37 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { FunctionCallResponse } from '../types';
3
+ export interface NhostFunctionsConstructorParams {
4
+ url: string;
5
+ }
6
+ /**
7
+ * @alias Functions
8
+ */
9
+ export declare class NhostFunctionsClient {
10
+ private instance;
11
+ private accessToken;
12
+ constructor(params: NhostFunctionsConstructorParams);
13
+ /**
14
+ * Use `nhost.functions.call` to call (sending a POST request to) a serverless function.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })
19
+ * ```
20
+ *
21
+ * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call
22
+ */
23
+ call<T = unknown, D = any>(url: string, data: D, config?: AxiosRequestConfig): Promise<FunctionCallResponse<T>>;
24
+ /**
25
+ * Use `nhost.functions.setAccessToken` to a set an access token to be used in subsequent functions requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * nhost.functions.setAccessToken('some-access-token')
30
+ * ```
31
+ *
32
+ * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-access-token
33
+ */
34
+ setAccessToken(accessToken: string | undefined): void;
35
+ private generateAccessTokenHeaders;
36
+ }
37
+ //# sourceMappingURL=functions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["functions.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,kBAAkB,EAAiB,MAAM,OAAO,CAAA;AAE/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAC/C,MAAM,WAAW,+BAA+B;IAC9C,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,WAAW,CAAe;gBAEtB,MAAM,EAAE,+BAA+B;IASnD;;;;;;;;;OASG;IACG,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,GAAG,EAC7B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,CAAC,EACP,MAAM,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAyBnC;;;;;;;;;OASG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS;IAS9C,OAAO,CAAC,0BAA0B;CAUnC"}
@@ -0,0 +1,58 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import type { DocumentNode } from 'graphql';
3
+ import { GraphqlRequestResponse } from '../types';
4
+ export interface NhostGraphqlConstructorParams {
5
+ url: string;
6
+ }
7
+ /**
8
+ * @alias GraphQL
9
+ */
10
+ export declare class NhostGraphqlClient {
11
+ private url;
12
+ private instance;
13
+ private accessToken;
14
+ constructor(params: NhostGraphqlConstructorParams);
15
+ /**
16
+ * Use `nhost.graphql.request` to send a GraphQL request. For more serious GraphQL usage in your app we recommend using a GraphQL client such as Apollo Client (https://www.apollographql.com/docs/react).
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const CUSTOMERS = gql`
21
+ * query {
22
+ * customers {
23
+ * id
24
+ * name
25
+ * }
26
+ * }
27
+ * `
28
+ * const { data, error } = await nhost.graphql.request(CUSTOMERS)
29
+ * ```
30
+ *
31
+ * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/request
32
+ */
33
+ request<T = any, V = any>(document: string | DocumentNode, variables?: V, config?: AxiosRequestConfig): Promise<GraphqlRequestResponse<T>>;
34
+ /**
35
+ * Use `nhost.graphql.getUrl` to get the GraphQL URL.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const url = nhost.graphql.getUrl();
40
+ * ```
41
+ *
42
+ * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/get-url
43
+ */
44
+ getUrl(): string;
45
+ /**
46
+ * Use `nhost.graphql.setAccessToken` to a set an access token to be used in subsequent graphql requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * nhost.graphql.setAccessToken('some-access-token')
51
+ * ```
52
+ *
53
+ * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/set-access-token
54
+ */
55
+ setAccessToken(accessToken: string | undefined): void;
56
+ private generateAccessTokenHeaders;
57
+ }
58
+ //# sourceMappingURL=graphql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["graphql.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAG3C,OAAO,EAAE,sBAAsB,EAAmB,MAAM,UAAU,CAAA;AAElE,MAAM,WAAW,6BAA6B;IAC5C,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,GAAG,CAAQ;IACnB,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,WAAW,CAAe;gBAEtB,MAAM,EAAE,6BAA6B;IAUjD;;;;;;;;;;;;;;;;;OAiBG;IACG,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAC5B,QAAQ,EAAE,MAAM,GAAG,YAAY,EAC/B,SAAS,CAAC,EAAE,CAAC,EACb,MAAM,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;IAiDrC;;;;;;;;;OASG;IACH,MAAM,IAAI,MAAM;IAIhB;;;;;;;;;OASG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS;IAS9C,OAAO,CAAC,0BAA0B;CAUnC"}
@@ -0,0 +1,3 @@
1
+ export * from './functions';
2
+ export * from './graphql';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './nhost-client';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { HasuraAuthClient, NhostAuthConstructorParams } from '@nhost/hasura-auth-js';
2
+ import { HasuraStorageClient } from '@nhost/hasura-storage-js';
3
+ import { NhostFunctionsClient } from '../clients/functions';
4
+ import { NhostGraphqlClient } from '../clients/graphql';
5
+ export interface NhostClientConstructorParams extends Omit<NhostAuthConstructorParams, 'url'> {
6
+ /**
7
+ * Nhost backend URL.
8
+ */
9
+ backendUrl: string;
10
+ }
11
+ export declare class NhostClient {
12
+ auth: HasuraAuthClient;
13
+ storage: HasuraStorageClient;
14
+ functions: NhostFunctionsClient;
15
+ graphql: NhostGraphqlClient;
16
+ /**
17
+ * Nhost Client
18
+ *
19
+ * @example
20
+ * const nhost = new NhostClient({ url });
21
+ *
22
+ * @docs https://docs.nhost.io/reference/javascript
23
+ */
24
+ constructor({ backendUrl, refreshIntervalTime, clientStorageGetter, clientStorageSetter, clientStorage, clientStorageType, autoRefreshToken, autoSignIn, start }: NhostClientConstructorParams);
25
+ }
26
+ //# sourceMappingURL=nhost-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nhost-client.d.ts","sourceRoot":"","sources":["nhost-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAA;AACpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAE9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAEvD,MAAM,WAAW,4BAA6B,SAAQ,IAAI,CAAC,0BAA0B,EAAE,KAAK,CAAC;IAC3F;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,qBAAa,WAAW;IACtB,IAAI,EAAE,gBAAgB,CAAA;IACtB,OAAO,EAAE,mBAAmB,CAAA;IAC5B,SAAS,EAAE,oBAAoB,CAAA;IAC/B,OAAO,EAAE,kBAAkB,CAAA;IAE3B;;;;;;;OAOG;gBACS,EACV,UAAU,EACV,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,KAAY,EACb,EAAE,4BAA4B;CAiDhC"}
package/umd/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { NhostClient, NhostClientConstructorParams } from './core';
2
+ declare const createClient: (config: NhostClientConstructorParams) => NhostClient;
3
+ export * from './clients';
4
+ export * from './core';
5
+ export { createClient };
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,4BAA4B,EAAE,MAAM,QAAQ,CAAA;AAElE,QAAA,MAAM,YAAY,WAAY,4BAA4B,gBAA4B,CAAA;AAEtF,cAAc,WAAW,CAAA;AACzB,cAAc,QAAQ,CAAA;AACtB,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -0,0 +1,19 @@
1
+ (function(U,$){typeof exports=="object"&&typeof module!="undefined"?$(exports,require("graphql/language/printer")):typeof define=="function"&&define.amd?define(["exports","graphql/language/printer"],$):(U=typeof globalThis!="undefined"?globalThis:U||self,$(U["@nhost/nhost-js"]={},U["graphql/language/printer"]))})(this,function(U,$){"use strict";var Oa=Object.defineProperty,_a=Object.defineProperties;var xa=Object.getOwnPropertyDescriptors;var mn=Object.getOwnPropertySymbols;var Ra=Object.prototype.hasOwnProperty,Aa=Object.prototype.propertyIsEnumerable;var gn=(U,$,H)=>$ in U?Oa(U,$,{enumerable:!0,configurable:!0,writable:!0,value:H}):U[$]=H,le=(U,$)=>{for(var H in $||($={}))Ra.call($,H)&&gn(U,H,$[H]);if(mn)for(var H of mn($))Aa.call($,H)&&gn(U,H,$[H]);return U},ir=(U,$)=>_a(U,xa($));function H(t){this.message=t}H.prototype=new Error,H.prototype.name="InvalidCharacterError";var sr=typeof window!="undefined"&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new H("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,n,i=0,s=0,a="";n=e.charAt(s++);~n&&(r=i%4?64*r+n:n,i++%4)?a+=String.fromCharCode(255&r>>(-2*i&6)):0)n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return a};function En(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(r){return decodeURIComponent(sr(r).replace(/(.)/g,function(n,i){var s=i.charCodeAt(0).toString(16).toUpperCase();return s.length<2&&(s="0"+s),"%"+s}))}(e)}catch{return sr(e)}}function He(t){this.message=t}function wn(t,e){if(typeof t!="string")throw new He("Invalid token specified");var r=(e=e||{}).header===!0?0:1;try{return JSON.parse(En(t.split(".")[r]))}catch(n){throw new He("Invalid token specified: "+n.message)}}He.prototype=new Error,He.prototype.name="InvalidTokenError";/*! *****************************************************************************
2
+ Copyright (c) Microsoft Corporation.
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
14
+ ***************************************************************************** */var m=function(){return m=Object.assign||function(e){for(var r,n=1,i=arguments.length;n<i;n++){r=arguments[n];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e},m.apply(this,arguments)};function St(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r}function O(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function R(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(a)throw a.error}}return s}function D(t,e,r){if(r||arguments.length===2)for(var n=0,i=e.length,s;n<i;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return t.concat(s||Array.prototype.slice.call(e))}var A;(function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"})(A||(A={}));var xe;(function(t){t.Parent="#_parent",t.Internal="#_internal"})(xe||(xe={}));var Tt=A.Start,bt=A.Stop,Ve=A.Raise,Ge=A.Send,ar=A.Cancel,Sn=A.NullEvent,Ot=A.Assign;A.After,A.DoneState;var or=A.Log,Tn=A.Init,_t=A.Invoke;A.ErrorExecution;var ur=A.ErrorPlatform,bn=A.ErrorCustom,cr=A.Update,On=A.Choose,_n=A.Pure,lr=".",fr={},xt="xstate.guard",xn="",Re=!0,ze;function Rt(t,e,r){r===void 0&&(r=lr);var n=Ae(t,r),i=Ae(e,r);return x(i)?x(n)?i===n:!1:x(n)?n in i:Object.keys(n).every(function(s){return s in i?Rt(n[s],i[s]):!1})}function dr(t){try{return x(t)||typeof t=="number"?"".concat(t):t.type}catch{throw new Error("Events must be strings or objects with a string event.type property.")}}function At(t,e){try{return fe(t)?t:t.toString().split(e)}catch{throw new Error("'".concat(t,"' is not a valid state path."))}}function Rn(t){return typeof t=="object"&&"value"in t&&"context"in t&&"event"in t&&"_event"in t}function Ae(t,e){if(Rn(t))return t.value;if(fe(t))return We(t);if(typeof t!="string")return t;var r=At(t,e);return We(r)}function We(t){if(t.length===1)return t[0];for(var e={},r=e,n=0;n<t.length-1;n++)n===t.length-2?r[t[n]]=t[n+1]:(r[t[n]]={},r=r[t[n]]);return e}function Ie(t,e){for(var r={},n=Object.keys(t),i=0;i<n.length;i++){var s=n[i];r[s]=e(t[s],s,t,i)}return r}function hr(t,e,r){var n,i,s={};try{for(var a=O(Object.keys(t)),o=a.next();!o.done;o=a.next()){var u=o.value,f=t[u];!r(f)||(s[u]=e(f,u,t))}}catch(c){n={error:c}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return s}var An=function(t){return function(e){var r,n,i=e;try{for(var s=O(t),a=s.next();!a.done;a=s.next()){var o=a.value;i=i[o]}}catch(u){r={error:u}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}return i}};function In(t,e){return function(r){var n,i,s=r;try{for(var a=O(t),o=a.next();!o.done;o=a.next()){var u=o.value;s=s[e][u]}}catch(f){n={error:f}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return s}}function Je(t){if(!t)return[[]];if(x(t))return[[t]];var e=P(Object.keys(t).map(function(r){var n=t[r];return typeof n!="string"&&(!n||!Object.keys(n).length)?[[r]]:Je(t[r]).map(function(i){return[r].concat(i)})}));return e}function P(t){var e;return(e=[]).concat.apply(e,D([],R(t),!1))}function vr(t){return fe(t)?t:[t]}function Q(t){return t===void 0?[]:vr(t)}function Ye(t,e,r){var n,i;if(I(t))return t(e,r.data);var s={};try{for(var a=O(Object.keys(t)),o=a.next();!o.done;o=a.next()){var u=o.value,f=t[u];I(f)?s[u]=f(e,r.data):s[u]=f}}catch(c){n={error:c}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return s}function Nn(t){return/^(done|error)\./.test(t)}function pr(t){return!!(t instanceof Promise||t!==null&&(I(t)||typeof t=="object")&&I(t.then))}function Pn(t){return t!==null&&typeof t=="object"&&"transition"in t&&typeof t.transition=="function"}function yr(t,e){var r,n,i=R([[],[]],2),s=i[0],a=i[1];try{for(var o=O(t),u=o.next();!u.done;u=o.next()){var f=u.value;e(f)?s.push(f):a.push(f)}}catch(c){r={error:c}}finally{try{u&&!u.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return[s,a]}function mr(t,e){return Ie(t.states,function(r,n){if(!!r){var i=(x(e)?void 0:e[n])||(r?r.current:void 0);if(!!i)return{current:i,states:mr(r,i)}}})}function kn(t,e){return{current:e,states:mr(t,e)}}function gr(t,e,r,n){var i=t&&r.reduce(function(s,a){var o,u,f=a.assignment,c={state:n,action:a,_event:e},h={};if(I(f))h=f(s,e.data,c);else try{for(var d=O(Object.keys(f)),l=d.next();!l.done;l=d.next()){var v=l.value,p=f[v];h[v]=I(p)?p(s,e.data,c):p}}catch(y){o={error:y}}finally{try{l&&!l.done&&(u=d.return)&&u.call(d)}finally{if(o)throw o.error}}return Object.assign({},s,h)},t);return i}var Ne=function(){};function fe(t){return Array.isArray(t)}function I(t){return typeof t=="function"}function x(t){return typeof t=="string"}function Er(t,e){if(!!t)return x(t)?{type:xt,name:t,predicate:e?e[t]:void 0}:I(t)?{type:xt,name:t.name,predicate:t}:t}function Cn(t){try{return"subscribe"in t&&I(t.subscribe)}catch{return!1}}var ne=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();ze={},ze[ne]=function(){return this},ze[Symbol.observable]=function(){return this};function oe(t){return!!t&&"__xstatenode"in t}function Dn(t){return!!t&&typeof t.send=="function"}function It(t,e){return x(t)||typeof t=="number"?m({type:t},e):t}function F(t,e){if(!x(t)&&"$$type"in t&&t.$$type==="scxml")return t;var r=It(t);return m({name:r.type,data:r,$$type:"scxml",type:"external"},e)}function de(t,e){var r=vr(e).map(function(n){return typeof n=="undefined"||typeof n=="string"||oe(n)?{target:n,event:t}:m(m({},n),{event:t})});return r}function Un(t){if(!(t===void 0||t===xn))return Q(t)}function wr(t,e,r,n,i){var s=t.options.guards,a={state:i,cond:e,_event:n};if(e.type===xt)return((s==null?void 0:s[e.name])||e.predicate)(r,n.data,a);var o=s==null?void 0:s[e.type];if(!o)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return o(r,n.data,a)}function Sr(t){return typeof t=="string"?{type:t}:t}function Nt(t,e,r){if(typeof t=="object")return t;var n=function(){};return{next:t,error:e||n,complete:r||n}}function Ke(t,e){return"".concat(t,":invocation[").concat(e,"]")}var Qe=F({type:Tn});function Pt(t,e){return e&&e[t]||void 0}function Pe(t,e){var r;if(x(t)||typeof t=="number"){var n=Pt(t,e);I(n)?r={type:t,exec:n}:n?r=n:r={type:t,exec:void 0}}else if(I(t))r={type:t.name||t.toString(),exec:t};else{var n=Pt(t.type,e);if(I(n))r=m(m({},t),{exec:n});else if(n){var i=n.type||t.type;r=m(m(m({},n),t),{type:i})}else r=t}return r}var Xe=function(t,e){if(!t)return[];var r=fe(t)?t:[t];return r.map(function(n){return Pe(n,e)})};function kt(t){var e=Pe(t);return m(m({id:x(t)?t:e.id},e),{type:e.type})}function Ln(t){return x(t)?{type:Ve,event:t}:Ct(t,{to:xe.Internal})}function $n(t){return{type:Ve,_event:F(t.event)}}function Ct(t,e){return{to:e?e.to:void 0,type:Ge,event:I(t)?t:It(t),delay:e?e.delay:void 0,id:e&&e.id!==void 0?e.id:I(t)?t.name:dr(t)}}function jn(t,e,r,n){var i={_event:r},s=F(I(t.event)?t.event(e,r.data,i):t.event),a;if(x(t.delay)){var o=n&&n[t.delay];a=I(o)?o(e,r.data,i):o}else a=I(t.delay)?t.delay(e,r.data,i):t.delay;var u=I(t.to)?t.to(e,r.data,i):t.to;return m(m({},t),{to:u,_event:s,event:s.data,delay:a})}var Mn=function(t,e,r){return m(m({},t),{value:x(t.expr)?t.expr:t.expr(e,r.data,{_event:r})})},Bn=function(t){return{type:ar,sendId:t}};function Fn(t){var e=kt(t);return{type:A.Start,activity:e,exec:void 0}}function qn(t){var e=I(t)?t:kt(t);return{type:A.Stop,activity:e,exec:void 0}}function Hn(t,e,r){var n=I(t.activity)?t.activity(e,r.data):t.activity,i=typeof n=="string"?{id:n}:n,s={type:A.Stop,activity:i};return s}var Vn=function(t){return{type:Ot,assignment:t}};function Gn(t,e){var r=e?"#".concat(e):"";return"".concat(A.After,"(").concat(t,")").concat(r)}function Ze(t,e){var r="".concat(A.DoneState,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function et(t,e){var r="".concat(A.DoneInvoke,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function ke(t,e){var r="".concat(A.ErrorPlatform,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Dt(t,e,r,n,i,s){s===void 0&&(s=!1);var a=R(s?[[],i]:yr(i,function(d){return d.type===Ot}),2),o=a[0],u=a[1],f=o.length?gr(r,n,o,e):r,c=s?[r]:void 0,h=P(u.map(function(d){var l;switch(d.type){case Ve:return $n(d);case Ge:var v=jn(d,f,n,t.options.delays);return v;case or:return Mn(d,f,n);case On:{var p=d,y=(l=p.conds.find(function(C){var B=Er(C.cond,t.options.guards);return!B||wr(t,B,f,n,e)}))===null||l===void 0?void 0:l.actions;if(!y)return[];var S=R(Dt(t,e,f,n,Xe(Q(y),t.options.actions),s),2),g=S[0],w=S[1];return f=w,c==null||c.push(f),g}case _n:{var y=d.get(f,n.data);if(!y)return[];var N=R(Dt(t,e,f,n,Xe(Q(y),t.options.actions),s),2),_=N[0],L=N[1];return f=L,c==null||c.push(f),_}case bt:return Hn(d,f,n);case Ot:{f=gr(f,n,[d],e),c==null||c.push(f);break}default:var T=Pe(d,t.options.actions),E=T.exec;if(E&&c){var b=c.length-1;T=m(m({},T),{exec:function(C){for(var B=[],W=1;W<arguments.length;W++)B[W-1]=arguments[W];E.apply(void 0,D([c[b]],R(B),!1))}})}return T}}).filter(function(d){return!!d}));return[h,f]}var Ce=function(t,e){var r=e(t);return r};function Tr(t){var e;return e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},e[ne]=function(){return this},e}function zn(t,e,r,n){var i,s=Sr(t.src),a=(i=e==null?void 0:e.options.services)===null||i===void 0?void 0:i[s.type],o=t.data?Ye(t.data,r,n):void 0,u=a?Wn(a,t.id,o):Tr(t.id);return u.meta=t,u}function Wn(t,e,r){var n=Tr(e);if(n.deferred=!0,oe(t)){var i=n.state=Ce(void 0,function(){return(r?t.withContext(r):t).initialState});n.getSnapshot=function(){return i}}return n}function Jn(t){try{return typeof t.send=="function"}catch{return!1}}function Yn(t){return Jn(t)&&"id"in t}function Kn(t){var e;return m((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},e[ne]=function(){return this},e),t)}var tt=function(t){return t.type==="atomic"||t.type==="final"};function he(t){return Object.keys(t.states).map(function(e){return t.states[e]}).filter(function(e){return e.type!=="history"})}function br(t){var e=[t];return tt(t)?e:e.concat(P(he(t).map(br)))}function ve(t,e){var r,n,i,s,a,o,u,f,c=new Set(t),h=Ut(c),d=new Set(e);try{for(var l=O(d),v=l.next();!v.done;v=l.next())for(var p=v.value,y=p.parent;y&&!d.has(y);)d.add(y),y=y.parent}catch(b){r={error:b}}finally{try{v&&!v.done&&(n=l.return)&&n.call(l)}finally{if(r)throw r.error}}var S=Ut(d);try{for(var g=O(d),w=g.next();!w.done;w=g.next()){var p=w.value;if(p.type==="compound"&&(!S.get(p)||!S.get(p).length))h.get(p)?h.get(p).forEach(function(C){return d.add(C)}):p.initialStateNodes.forEach(function(C){return d.add(C)});else if(p.type==="parallel")try{for(var N=(a=void 0,O(he(p))),_=N.next();!_.done;_=N.next()){var L=_.value;d.has(L)||(d.add(L),h.get(L)?h.get(L).forEach(function(C){return d.add(C)}):L.initialStateNodes.forEach(function(C){return d.add(C)}))}}catch(C){a={error:C}}finally{try{_&&!_.done&&(o=N.return)&&o.call(N)}finally{if(a)throw a.error}}}}catch(b){i={error:b}}finally{try{w&&!w.done&&(s=g.return)&&s.call(g)}finally{if(i)throw i.error}}try{for(var T=O(d),E=T.next();!E.done;E=T.next())for(var p=E.value,y=p.parent;y&&!d.has(y);)d.add(y),y=y.parent}catch(b){u={error:b}}finally{try{E&&!E.done&&(f=T.return)&&f.call(T)}finally{if(u)throw u.error}}return d}function Or(t,e){var r=e.get(t);if(!r)return{};if(t.type==="compound"){var n=r[0];if(n){if(tt(n))return n.key}else return{}}var i={};return r.forEach(function(s){i[s.key]=Or(s,e)}),i}function Ut(t){var e,r,n=new Map;try{for(var i=O(t),s=i.next();!s.done;s=i.next()){var a=s.value;n.has(a)||n.set(a,[]),a.parent&&(n.has(a.parent)||n.set(a.parent,[]),n.get(a.parent).push(a))}}catch(o){e={error:o}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return n}function Qn(t,e){var r=ve([t],e);return Or(t,Ut(r))}function rt(t,e){return Array.isArray(t)?t.some(function(r){return r===e}):t instanceof Set?t.has(e):!1}function Xn(t){return D([],R(new Set(P(D([],R(t.map(function(e){return e.ownEvents})),!1)))),!1)}function De(t,e){return e.type==="compound"?he(e).some(function(r){return r.type==="final"&&rt(t,r)}):e.type==="parallel"?he(e).every(function(r){return De(t,r)}):!1}function Zn(t){return t===void 0&&(t=[]),t.reduce(function(e,r){return r.meta!==void 0&&(e[r.id]=r.meta),e},{})}function _r(t){return new Set(P(t.map(function(e){return e.tags})))}function xr(t,e){if(t===e)return!0;if(t===void 0||e===void 0)return!1;if(x(t)||x(e))return t===e;var r=Object.keys(t),n=Object.keys(e);return r.length===n.length&&r.every(function(i){return xr(t[i],e[i])})}function ei(t){return typeof t!="object"||t===null?!1:"value"in t&&"_event"in t}function ti(t,e){var r=t.exec,n=m(m({},t),{exec:r!==void 0?function(){return r(e.context,e.event,{action:t,state:e,_event:e._event})}:void 0});return n}var ee=function(){function t(e){var r=this,n;this.actions=[],this.activities=fr,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||fr,this.meta=Zn(e.configuration),this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,this.tags=(n=Array.isArray(e.tags)?new Set(e.tags):e.tags)!==null&&n!==void 0?n:new Set,this.machine=e.machine,Object.defineProperty(this,"nextEvents",{get:function(){return Xn(r.configuration)}})}return t.from=function(e,r){if(e instanceof t)return e.context!==r?new t({value:e.value,context:r,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e;var n=Qe;return new t({value:e,context:r,_event:n,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,r){if(e instanceof t){if(!e.actions.length)return e;var n=Qe;return new t({value:e.value,context:r,_event:n,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,r)},t.prototype.toStrings=function(e,r){var n=this;if(e===void 0&&(e=this.value),r===void 0&&(r="."),x(e))return[e];var i=Object.keys(e);return i.concat.apply(i,D([],R(i.map(function(s){return n.toStrings(e[s],r).map(function(a){return s+r+a})})),!1))},t.prototype.toJSON=function(){var e=this;e.configuration,e.transitions;var r=e.tags;e.machine;var n=St(e,["configuration","transitions","tags","machine"]);return m(m({},n),{tags:Array.from(r)})},t.prototype.matches=function(e){return Rt(e,this.value)},t.prototype.hasTag=function(e){return this.tags.has(e)},t.prototype.can=function(e){var r;Ne(!!this.machine);var n=(r=this.machine)===null||r===void 0?void 0:r.getTransitionData(this,e);return!!(n!=null&&n.transitions.length)&&n.transitions.some(function(i){return i.target!==void 0||i.actions.length})},t}(),ri={deferEvents:!1},Rr=function(){function t(e){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=m(m({},ri),e)}return t.prototype.initialize=function(e){if(this.initialized=!0,e){if(!this.options.deferEvents){this.schedule(e);return}this.process(e)}this.flushEvents()},t.prototype.schedule=function(e){if(!this.initialized||this.processingEvent){this.queue.push(e);return}if(this.queue.length!==0)throw new Error("Event queue should be empty when it is not processing events");this.process(e),this.flushEvents()},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var e=this.queue.shift();e;)this.process(e),e=this.queue.shift()},t.prototype.process=function(e){this.processingEvent=!0;try{e()}catch(r){throw this.clear(),r}finally{this.processingEvent=!1}},t}(),Lt=new Map,ni=0,nt={bookId:function(){return"x:".concat(ni++)},register:function(t,e){return Lt.set(t,e),t},get:function(t){return Lt.get(t)},free:function(t){Lt.delete(t)}};function $t(){if(typeof globalThis!="undefined")return globalThis;if(typeof self!="undefined")return self;if(typeof window!="undefined")return window;if(typeof global!="undefined")return global}function ii(){var t=$t();if(t&&"__xstate__"in t)return t.__xstate__}function si(t){if(!!$t()){var e=ii();e&&e.register(t)}}function ai(t,e){e===void 0&&(e={});var r=t.initialState,n=new Set,i=[],s=!1,a=function(){if(!s){for(s=!0;i.length>0;){var f=i.shift();r=t.transition(r,f,u),n.forEach(function(c){return c.next(r)})}s=!1}},o=Kn({id:e.id,send:function(f){i.push(f),a()},getSnapshot:function(){return r},subscribe:function(f,c,h){var d=Nt(f,c,h);return n.add(d),d.next(r),{unsubscribe:function(){n.delete(d)}}}}),u={parent:e.parent,self:o,id:e.id||"anonymous",observers:n};return r=t.start?t.start(u):r,o}var oi={sync:!1,autoForward:!1},q;(function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"})(q||(q={}));var ui=function(){function t(e,r){var n=this;r===void 0&&(r=t.defaultOptions),this.machine=e,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=q.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(c,h){if(fe(c))return n.batch(c),n.state;var d=F(It(c,h));if(n.status===q.Stopped)return n.state;if(n.status!==q.Running&&!n.options.deferEvents)throw new Error('Event "'.concat(d.name,'" was sent to uninitialized service "').concat(n.machine.id,`". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.
15
+ Event: `).concat(JSON.stringify(d.data)));return n.scheduler.schedule(function(){n.forward(d);var l=n.nextState(d);n.update(l,d)}),n._state},this.sendTo=function(c,h){var d=n.parent&&(h===xe.Parent||n.parent.id===h),l=d?n.parent:x(h)?n.children.get(h)||nt.get(h):Dn(h)?h:void 0;if(!l){if(!d)throw new Error("Unable to send event to child '".concat(h,"' from service '").concat(n.id,"'."));return}"machine"in l?l.send(m(m({},c),{name:c.name===bn?"".concat(ke(n.id)):c.name,origin:n.sessionId})):l.send(c.data)};var i=m(m({},t.defaultOptions),r),s=i.clock,a=i.logger,o=i.parent,u=i.id,f=u!==void 0?u:e.id;this.id=f,this.logger=a,this.clock=s,this.parent=o,this.options=i,this.scheduler=new Rr({deferEvents:this.options.deferEvents}),this.sessionId=nt.bookId()}return Object.defineProperty(t.prototype,"initialState",{get:function(){var e=this;return this._initialState?this._initialState:Ce(this,function(){return e._initialState=e.machine.initialState,e._initialState})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),t.prototype.execute=function(e,r){var n,i;try{for(var s=O(e.actions),a=s.next();!a.done;a=s.next()){var o=a.value;this.exec(o,e,r)}}catch(u){n={error:u}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}},t.prototype.update=function(e,r){var n,i,s,a,o,u,f,c,h=this;if(e._sessionid=this.sessionId,this._state=e,this.options.execute&&this.execute(this.state),this.children.forEach(function(b){h.state.children[b.id]=b}),this.devTools&&this.devTools.send(r.data,e),e.event)try{for(var d=O(this.eventListeners),l=d.next();!l.done;l=d.next()){var v=l.value;v(e.event)}}catch(b){n={error:b}}finally{try{l&&!l.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}try{for(var p=O(this.listeners),y=p.next();!y.done;y=p.next()){var v=y.value;v(e,e.event)}}catch(b){s={error:b}}finally{try{y&&!y.done&&(a=p.return)&&a.call(p)}finally{if(s)throw s.error}}try{for(var S=O(this.contextListeners),g=S.next();!g.done;g=S.next()){var w=g.value;w(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(b){o={error:b}}finally{try{g&&!g.done&&(u=S.return)&&u.call(S)}finally{if(o)throw o.error}}var N=De(e.configuration||[],this.machine);if(this.state.configuration&&N){var _=e.configuration.find(function(b){return b.type==="final"&&b.parent===h.machine}),L=_&&_.doneData?Ye(_.doneData,e.context,r):void 0;try{for(var T=O(this.doneListeners),E=T.next();!E.done;E=T.next()){var v=E.value;v(et(this.id,L))}}catch(b){f={error:b}}finally{try{E&&!E.done&&(c=T.return)&&c.call(T)}finally{if(f)throw f.error}}this.stop()}},t.prototype.onTransition=function(e){return this.listeners.add(e),this.status===q.Running&&e(this.state,this.state.event),this},t.prototype.subscribe=function(e,r,n){var i=this;if(!e)return{unsubscribe:function(){}};var s,a=n;return typeof e=="function"?s=e:(s=e.next.bind(e),a=e.complete.bind(e)),this.listeners.add(s),this.status!==q.NotStarted&&s(this.state),a&&(this.status===q.Stopped?a():this.onDone(a)),{unsubscribe:function(){s&&i.listeners.delete(s),a&&i.doneListeners.delete(a)}}},t.prototype.onEvent=function(e){return this.eventListeners.add(e),this},t.prototype.onSend=function(e){return this.sendListeners.add(e),this},t.prototype.onChange=function(e){return this.contextListeners.add(e),this},t.prototype.onStop=function(e){return this.stopListeners.add(e),this},t.prototype.onDone=function(e){return this.doneListeners.add(e),this},t.prototype.off=function(e){return this.listeners.delete(e),this.eventListeners.delete(e),this.sendListeners.delete(e),this.stopListeners.delete(e),this.doneListeners.delete(e),this.contextListeners.delete(e),this},t.prototype.start=function(e){var r=this;if(this.status===q.Running)return this;this.machine._init(),nt.register(this.sessionId,this),this.initialized=!0,this.status=q.Running;var n=e===void 0?this.initialState:Ce(this,function(){return ei(e)?r.machine.resolveState(e):r.machine.resolveState(ee.from(e,r.machine.context))});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(function(){r.update(n,Qe)}),this},t.prototype.stop=function(){var e,r,n,i,s,a,o,u,f,c,h=this;try{for(var d=O(this.listeners),l=d.next();!l.done;l=d.next()){var v=l.value;this.listeners.delete(v)}}catch(E){e={error:E}}finally{try{l&&!l.done&&(r=d.return)&&r.call(d)}finally{if(e)throw e.error}}try{for(var p=O(this.stopListeners),y=p.next();!y.done;y=p.next()){var v=y.value;v(),this.stopListeners.delete(v)}}catch(E){n={error:E}}finally{try{y&&!y.done&&(i=p.return)&&i.call(p)}finally{if(n)throw n.error}}try{for(var S=O(this.contextListeners),g=S.next();!g.done;g=S.next()){var v=g.value;this.contextListeners.delete(v)}}catch(E){s={error:E}}finally{try{g&&!g.done&&(a=S.return)&&a.call(S)}finally{if(s)throw s.error}}try{for(var w=O(this.doneListeners),N=w.next();!N.done;N=w.next()){var v=N.value;this.doneListeners.delete(v)}}catch(E){o={error:E}}finally{try{N&&!N.done&&(u=w.return)&&u.call(w)}finally{if(o)throw o.error}}if(!this.initialized)return this;D([],R(this.state.configuration),!1).sort(function(E,b){return b.order-E.order}).forEach(function(E){var b,C;try{for(var B=O(E.definition.exit),W=B.next();!W.done;W=B.next()){var ae=W.value;h.exec(ae,h.state)}}catch(wt){b={error:wt}}finally{try{W&&!W.done&&(C=B.return)&&C.call(B)}finally{if(b)throw b.error}}}),this.children.forEach(function(E){I(E.stop)&&E.stop()}),this.children.clear();try{for(var _=O(Object.keys(this.delayedEventsMap)),L=_.next();!L.done;L=_.next()){var T=L.value;this.clock.clearTimeout(this.delayedEventsMap[T])}}catch(E){f={error:E}}finally{try{L&&!L.done&&(c=_.return)&&c.call(_)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.scheduler=new Rr({deferEvents:this.options.deferEvents}),this.initialized=!1,this.status=q.Stopped,this._initialState=void 0,nt.free(this.sessionId),this},t.prototype.batch=function(e){var r=this;if(!(this.status===q.NotStarted&&this.options.deferEvents)){if(this.status!==q.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'))}this.scheduler.schedule(function(){var n,i,s=r.state,a=!1,o=[],u=function(d){var l=F(d);r.forward(l),s=Ce(r,function(){return r.machine.transition(s,l)}),o.push.apply(o,D([],R(s.actions.map(function(v){return ti(v,s)})),!1)),a=a||!!s.changed};try{for(var f=O(e),c=f.next();!c.done;c=f.next()){var h=c.value;u(h)}}catch(d){n={error:d}}finally{try{c&&!c.done&&(i=f.return)&&i.call(f)}finally{if(n)throw n.error}}s.changed=a,s.actions=o,r.update(s,F(e[e.length-1]))})},t.prototype.sender=function(e){return this.send.bind(this,e)},t.prototype.nextState=function(e){var r=this,n=F(e);if(n.name.indexOf(ur)===0&&!this.state.nextEvents.some(function(s){return s.indexOf(ur)===0}))throw n.data.data;var i=Ce(this,function(){return r.machine.transition(r.state,n)});return i},t.prototype.forward=function(e){var r,n;try{for(var i=O(this.forwardTo),s=i.next();!s.done;s=i.next()){var a=s.value,o=this.children.get(a);if(!o)throw new Error("Unable to forward event '".concat(e,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(a,"'."));o.send(e)}}catch(u){r={error:u}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}},t.prototype.defer=function(e){var r=this;this.delayedEventsMap[e.id]=this.clock.setTimeout(function(){e.to?r.sendTo(e._event,e.to):r.send(e._event)},e.delay)},t.prototype.cancel=function(e){this.clock.clearTimeout(this.delayedEventsMap[e]),delete this.delayedEventsMap[e]},t.prototype.exec=function(e,r,n){n===void 0&&(n=this.machine.options.actions);var i=r.context,s=r._event,a=e.exec||Pt(e.type,n),o=I(a)?a:a?a.exec:e.exec;if(o)try{return o(i,s.data,{action:e,state:this.state,_event:s})}catch(N){throw this.parent&&this.parent.send({type:"xstate.error",data:N}),N}switch(e.type){case Ge:var u=e;if(typeof u.delay=="number"){this.defer(u);return}else u.to?this.sendTo(u._event,u.to):this.send(u._event);break;case ar:this.cancel(e.sendId);break;case Tt:{if(this.status!==q.Running)return;var f=e.activity;if(!this.state.activities[f.id||f.type])break;if(f.type===A.Invoke){var c=Sr(f.src),h=this.machine.options.services?this.machine.options.services[c.type]:void 0,d=f.id,l=f.data,v="autoForward"in f?f.autoForward:!!f.forward;if(!h)return;var p=l?Ye(l,i,s):void 0;if(typeof h=="string")return;var y=I(h)?h(i,s.data,{data:p,src:c,meta:f.meta}):h;if(!y)return;var S=void 0;oe(y)&&(y=p?y.withContext(p):y,S={autoForward:v}),this.spawn(y,d,S)}else this.spawnActivity(f);break}case bt:{this.stopChild(e.activity.id);break}case or:var g=e.label,w=e.value;g?this.logger(g,w):this.logger(w);break}},t.prototype.removeChild=function(e){var r;this.children.delete(e),this.forwardTo.delete(e),(r=this.state)===null||r===void 0||delete r.children[e]},t.prototype.stopChild=function(e){var r=this.children.get(e);!r||(this.removeChild(e),I(r.stop)&&r.stop())},t.prototype.spawn=function(e,r,n){if(pr(e))return this.spawnPromise(Promise.resolve(e),r);if(I(e))return this.spawnCallback(e,r);if(Yn(e))return this.spawnActor(e,r);if(Cn(e))return this.spawnObservable(e,r);if(oe(e))return this.spawnMachine(e,m(m({},n),{id:r}));if(Pn(e))return this.spawnBehavior(e,r);throw new Error('Unable to spawn entity "'.concat(r,'" of type "').concat(typeof e,'".'))},t.prototype.spawnMachine=function(e,r){var n=this;r===void 0&&(r={});var i=new t(e,m(m({},this.options),{parent:this,id:r.id||e.id})),s=m(m({},oi),r);s.sync&&i.onTransition(function(o){n.send(cr,{state:o,id:i.id})});var a=i;return this.children.set(i.id,a),s.autoForward&&this.forwardTo.add(i.id),i.onDone(function(o){n.removeChild(i.id),n.send(F(o,{origin:i.id}))}).start(),a},t.prototype.spawnBehavior=function(e,r){var n=ai(e,{id:r,parent:this});return this.children.set(r,n),n},t.prototype.spawnPromise=function(e,r){var n,i=this,s=!1,a;e.then(function(u){s||(a=u,i.removeChild(r),i.send(F(et(r,u),{origin:r})))},function(u){if(!s){i.removeChild(r);var f=ke(r,u);try{i.send(F(f,{origin:r}))}catch{i.devTools&&i.devTools.send(f,i.state),i.machine.strict&&i.stop()}}});var o=(n={id:r,send:function(){},subscribe:function(u,f,c){var h=Nt(u,f,c),d=!1;return e.then(function(l){d||(h.next(l),!d&&h.complete())},function(l){d||h.error(l)}),{unsubscribe:function(){return d=!0}}},stop:function(){s=!0},toJSON:function(){return{id:r}},getSnapshot:function(){return a}},n[ne]=function(){return this},n);return this.children.set(r,o),o},t.prototype.spawnCallback=function(e,r){var n,i=this,s=!1,a=new Set,o=new Set,u,f=function(d){u=d,o.forEach(function(l){return l(d)}),!s&&i.send(F(d,{origin:r}))},c;try{c=e(f,function(d){a.add(d)})}catch(d){this.send(ke(r,d))}if(pr(c))return this.spawnPromise(c,r);var h=(n={id:r,send:function(d){return a.forEach(function(l){return l(d)})},subscribe:function(d){var l=Nt(d);return o.add(l.next),{unsubscribe:function(){o.delete(l.next)}}},stop:function(){s=!0,I(c)&&c()},toJSON:function(){return{id:r}},getSnapshot:function(){return u}},n[ne]=function(){return this},n);return this.children.set(r,h),h},t.prototype.spawnObservable=function(e,r){var n,i=this,s,a=e.subscribe(function(u){s=u,i.send(F(u,{origin:r}))},function(u){i.removeChild(r),i.send(F(ke(r,u),{origin:r}))},function(){i.removeChild(r),i.send(F(et(r),{origin:r}))}),o=(n={id:r,send:function(){},subscribe:function(u,f,c){return e.subscribe(u,f,c)},stop:function(){return a.unsubscribe()},getSnapshot:function(){return s},toJSON:function(){return{id:r}}},n[ne]=function(){return this},n);return this.children.set(r,o),o},t.prototype.spawnActor=function(e,r){return this.children.set(r,e),e},t.prototype.spawnActivity=function(e){var r=this.machine.options&&this.machine.options.activities?this.machine.options.activities[e.type]:void 0;if(!!r){var n=r(this.state.context,e);this.spawnEffect(e.id,n)}},t.prototype.spawnEffect=function(e,r){var n;this.children.set(e,(n={id:e,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:r||void 0,getSnapshot:function(){},toJSON:function(){return{id:e}}},n[ne]=function(){return this},n))},t.prototype.attachDev=function(){var e=$t();if(this.options.devTools&&e){if(e.__REDUX_DEVTOOLS_EXTENSION__){var r=typeof this.options.devTools=="object"?this.options.devTools:void 0;this.devTools=e.__REDUX_DEVTOOLS_EXTENSION__.connect(m(m({name:this.id,autoPause:!0,stateSanitizer:function(n){return{value:n.value,context:n.context,actions:n.actions}}},r),{features:m({jump:!1,skip:!1},r?r.features:void 0)}),this.machine),this.devTools.init(this.state)}si(this)}},t.prototype.toJSON=function(){return{id:this.id}},t.prototype[ne]=function(){return this},t.prototype.getSnapshot=function(){return this.status===q.NotStarted?this.initialState:this._state},t.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:function(e,r){return setTimeout(e,r)},clearTimeout:function(e){return clearTimeout(e)}},logger:console.log.bind(console),devTools:!1},t.interpret=pe,t}();function pe(t,e){var r=new ui(t,e);return r}function ci(t){if(typeof t=="string"){var e={type:t};return e.toString=function(){return t},e}return t}function it(t){return m(m({type:_t},t),{toJSON:function(){t.onDone,t.onError;var e=St(t,["onDone","onError"]);return m(m({},e),{type:_t,src:ci(t.src)})}})}var ye="",jt="#",Ue="*",me={},ge=function(t){return t[0]===jt},li=function(){return{actions:{},guards:{},services:{},activities:{},delays:{}}},fi=function(t,e,r){var n=r.slice(0,-1).some(function(s){return!("cond"in s)&&!("in"in s)&&(x(s.target)||oe(s.target))}),i=e===ye?"the transient event":"event '".concat(e,"'");Ne(!n,"One or more transitions for ".concat(i," on state '").concat(t.id,"' are unreachable. ")+"Make sure that the default transition is the last one defined.")},di=function(){function t(e,r,n,i){var s=this;n===void 0&&(n="context"in e?e.context:void 0);var a;this.config=e,this._context=n,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign(li(),r),this.parent=i==null?void 0:i.parent,this.key=this.config.key||(i==null?void 0:i.key)||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:lr),this.id=this.config.id||D([this.machine.key],R(this.path),!1).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:(a=this.config.schema)!==null&&a!==void 0?a:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?Ie(this.config.states,function(f,c){var h,d=new t(f,{},void 0,{parent:s,key:c});return Object.assign(s.idMap,m((h={},h[d.id]=d,h),d.idMap)),d}):me;var o=0;function u(f){var c,h;f.order=o++;try{for(var d=O(he(f)),l=d.next();!l.done;l=d.next()){var v=l.value;u(v)}}catch(p){c={error:p}}finally{try{l&&!l.done&&(h=d.return)&&h.call(d)}finally{if(c)throw c.error}}}u(this),this.history=this.config.history===!0?"shallow":this.config.history||!1,this._transient=!!this.config.always||(this.config.on?Array.isArray(this.config.on)?this.config.on.some(function(f){var c=f.event;return c===ye}):ye in this.config.on:!1),this.strict=!!this.config.strict,this.onEntry=Q(this.config.entry||this.config.onEntry).map(function(f){return Pe(f)}),this.onExit=Q(this.config.exit||this.config.onExit).map(function(f){return Pe(f)}),this.meta=this.config.meta,this.doneData=this.type==="final"?this.config.data:void 0,this.invoke=Q(this.config.invoke).map(function(f,c){var h,d;if(oe(f)){var l=Ke(s.id,c);return s.machine.options.services=m((h={},h[l]=f,h),s.machine.options.services),it({src:l,id:l})}else if(x(f.src)){var l=f.id||Ke(s.id,c);return it(m(m({},f),{id:l,src:f.src}))}else if(oe(f.src)||I(f.src)){var l=f.id||Ke(s.id,c);return s.machine.options.services=m((d={},d[l]=f.src,d),s.machine.options.services),it(m(m({id:l},f),{src:l}))}else{var v=f.src;return it(m(m({id:Ke(s.id,c)},f),{src:v}))}}),this.activities=Q(this.config.activities).concat(this.invoke).map(function(f){return kt(f)}),this.transition=this.transition.bind(this),this.tags=Q(this.config.tags)}return t.prototype._init=function(){this.__cache.transitions||br(this).forEach(function(e){return e.on})},t.prototype.withConfig=function(e,r){var n=this.options,i=n.actions,s=n.activities,a=n.guards,o=n.services,u=n.delays;return new t(this.config,{actions:m(m({},i),e.actions),activities:m(m({},s),e.activities),guards:m(m({},a),e.guards),services:m(m({},o),e.services),delays:m(m({},u),e.delays)},r!=null?r:this.context)},t.prototype.withContext=function(e){return new t(this.config,this.options,e)},Object.defineProperty(t.prototype,"context",{get:function(){return I(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:Ie(this.states,function(e){return e.definition}),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke,description:this.description,tags:this.tags}},enumerable:!1,configurable:!0}),t.prototype.toJSON=function(){return this.definition},Object.defineProperty(t.prototype,"on",{get:function(){if(this.__cache.on)return this.__cache.on;var e=this.transitions;return this.__cache.on=e.reduce(function(r,n){return r[n.eventType]=r[n.eventType]||[],r[n.eventType].push(n),r},{})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),t.prototype.getCandidates=function(e){if(this.__cache.candidates[e])return this.__cache.candidates[e];var r=e===ye,n=this.transitions.filter(function(i){var s=i.eventType===e;return r?s:s||i.eventType===Ue});return this.__cache.candidates[e]=n,n},t.prototype.getDelayedTransitions=function(){var e=this,r=this.config.after;if(!r)return[];var n=function(s,a){var o=I(s)?"".concat(e.id,":delay[").concat(a,"]"):s,u=Gn(o,e.id);return e.onEntry.push(Ct(u,{delay:s})),e.onExit.push(Bn(u)),u},i=fe(r)?r.map(function(s,a){var o=n(s.delay,a);return m(m({},s),{event:o})}):P(Object.keys(r).map(function(s,a){var o=r[s],u=x(o)?{target:o}:o,f=isNaN(+s)?s:+s,c=n(f,a);return Q(u).map(function(h){return m(m({},h),{event:c,delay:f})})}));return i.map(function(s){var a=s.delay;return m(m({},e.formatTransition(s)),{delay:a})})},t.prototype.getStateNodes=function(e){var r,n=this;if(!e)return[];var i=e instanceof ee?e.value:Ae(e,this.delimiter);if(x(i)){var s=this.getStateNode(i).initial;return s!==void 0?this.getStateNodes((r={},r[i]=s,r)):[this,this.states[i]]}var a=Object.keys(i),o=[this];return o.push.apply(o,D([],R(P(a.map(function(u){return n.getStateNode(u).getStateNodes(i[u])}))),!1)),o},t.prototype.handles=function(e){var r=dr(e);return this.events.includes(r)},t.prototype.resolveState=function(e){var r=e instanceof ee?e:ee.create(e),n=Array.from(ve([],this.getStateNodes(r.value)));return new ee(m(m({},r),{value:this.resolve(r.value),configuration:n,done:De(n,this),tags:_r(n),machine:this.machine}))},t.prototype.transitionLeafNode=function(e,r,n){var i=this.getStateNode(e),s=i.next(r,n);return!s||!s.transitions.length?this.next(r,n):s},t.prototype.transitionCompoundNode=function(e,r,n){var i=Object.keys(e),s=this.getStateNode(i[0]),a=s._transition(e[i[0]],r,n);return!a||!a.transitions.length?this.next(r,n):a},t.prototype.transitionParallelNode=function(e,r,n){var i,s,a={};try{for(var o=O(Object.keys(e)),u=o.next();!u.done;u=o.next()){var f=u.value,c=e[f];if(!!c){var h=this.getStateNode(f),d=h._transition(c,r,n);d&&(a[f]=d)}}}catch(g){i={error:g}}finally{try{u&&!u.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}var l=Object.keys(a).map(function(g){return a[g]}),v=P(l.map(function(g){return g.transitions})),p=l.some(function(g){return g.transitions.length>0});if(!p)return this.next(r,n);var y=P(l.map(function(g){return g.entrySet})),S=P(Object.keys(a).map(function(g){return a[g].configuration}));return{transitions:v,entrySet:y,exitSet:P(l.map(function(g){return g.exitSet})),configuration:S,source:r,actions:P(Object.keys(a).map(function(g){return a[g].actions}))}},t.prototype._transition=function(e,r,n){return x(e)?this.transitionLeafNode(e,r,n):Object.keys(e).length===1?this.transitionCompoundNode(e,r,n):this.transitionParallelNode(e,r,n)},t.prototype.getTransitionData=function(e,r){return this._transition(e.value,e,F(r))},t.prototype.next=function(e,r){var n,i,s=this,a=r.name,o=[],u=[],f;try{for(var c=O(this.getCandidates(a)),h=c.next();!h.done;h=c.next()){var d=h.value,l=d.cond,v=d.in,p=e.context,y=v?x(v)&&ge(v)?e.matches(Ae(this.getStateNodeById(v).path,this.delimiter)):Rt(Ae(v,this.delimiter),An(this.path.slice(0,-2))(e.value)):!0,S=!1;try{S=!l||wr(this.machine,l,p,r,e)}catch(_){throw new Error("Unable to evaluate guard '".concat(l.name||l.type,"' in transition for event '").concat(a,"' in state node '").concat(this.id,`':
16
+ `).concat(_.message))}if(S&&y){d.target!==void 0&&(u=d.target),o.push.apply(o,D([],R(d.actions),!1)),f=d;break}}}catch(_){n={error:_}}finally{try{h&&!h.done&&(i=c.return)&&i.call(c)}finally{if(n)throw n.error}}if(!!f){if(!u.length)return{transitions:[f],entrySet:[],exitSet:[],configuration:e.value?[this]:[],source:e,actions:o};var g=P(u.map(function(_){return s.getRelativeStateNodes(_,e.historyValue)})),w=!!f.internal,N=w?[]:P(g.map(function(_){return s.nodesFromChild(_)}));return{transitions:[f],entrySet:N,exitSet:w?[]:[this],configuration:g,source:e,actions:o}}},t.prototype.nodesFromChild=function(e){if(e.escapes(this))return[];for(var r=[],n=e;n&&n!==this;)r.push(n),n=n.parent;return r.push(this),r},t.prototype.escapes=function(e){if(this===e)return!1;for(var r=this.parent;r;){if(r===e)return!1;r=r.parent}return!0},t.prototype.getActions=function(e,r,n,i){var s,a,o,u,f=ve([],i?this.getStateNodes(i.value):[this]),c=e.configuration.length?ve(f,e.configuration):f;try{for(var h=O(c),d=h.next();!d.done;d=h.next()){var l=d.value;rt(f,l)||e.entrySet.push(l)}}catch(T){s={error:T}}finally{try{d&&!d.done&&(a=h.return)&&a.call(h)}finally{if(s)throw s.error}}try{for(var v=O(f),p=v.next();!p.done;p=v.next()){var l=p.value;(!rt(c,l)||rt(e.exitSet,l.parent))&&e.exitSet.push(l)}}catch(T){o={error:T}}finally{try{p&&!p.done&&(u=v.return)&&u.call(v)}finally{if(o)throw o.error}}var y=P(e.entrySet.map(function(T){var E=[];if(T.type!=="final")return E;var b=T.parent;if(!b.parent)return E;E.push(Ze(T.id,T.doneData),Ze(b.id,T.doneData?Ye(T.doneData,r,n):void 0));var C=b.parent;return C.type==="parallel"&&he(C).every(function(B){return De(e.configuration,B)})&&E.push(Ze(C.id)),E}));e.exitSet.sort(function(T,E){return E.order-T.order}),e.entrySet.sort(function(T,E){return T.order-E.order});var S=new Set(e.entrySet),g=new Set(e.exitSet),w=R([P(Array.from(S).map(function(T){return D(D([],R(T.activities.map(function(E){return Fn(E)})),!1),R(T.onEntry),!1)})).concat(y.map(Ln)),P(Array.from(g).map(function(T){return D(D([],R(T.onExit),!1),R(T.activities.map(function(E){return qn(E)})),!1)}))],2),N=w[0],_=w[1],L=Xe(_.concat(e.actions).concat(N),this.machine.options.actions);return L},t.prototype.transition=function(e,r,n){e===void 0&&(e=this.initialState);var i=F(r),s;if(e instanceof ee)s=n===void 0?e:this.resolveState(ee.from(e,n));else{var a=x(e)?this.resolve(We(this.getResolvedPath(e))):this.resolve(e),o=n!=null?n:this.machine.context;s=this.resolveState(ee.from(a,o))}if(!Re&&i.name===Ue)throw new Error("An event cannot have the wildcard type ('".concat(Ue,"')"));if(this.strict&&!this.events.includes(i.name)&&!Nn(i.name))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(i.name,"'"));var u=this._transition(s.value,s,i)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:s,actions:[]},f=ve([],this.getStateNodes(s.value)),c=u.configuration.length?ve(f,u.configuration):f;return u.configuration=D([],R(c),!1),this.resolveTransition(u,s,s.context,i)},t.prototype.resolveRaisedTransition=function(e,r,n){var i,s=e.actions;return e=this.transition(e,r),e._event=n,e.event=n.data,(i=e.actions).unshift.apply(i,D([],R(s),!1)),e},t.prototype.resolveTransition=function(e,r,n,i){var s,a,o=this;i===void 0&&(i=Qe);var u=e.configuration,f=!r||e.transitions.length>0,c=f?Qn(this.machine,u):void 0,h=r?r.historyValue?r.historyValue:e.source?this.machine.historyValue(r.value):void 0:void 0,d=this.getActions(e,n,i,r),l=r?m({},r.activities):{};try{for(var v=O(d),p=v.next();!p.done;p=v.next()){var y=p.value;y.type===Tt?l[y.activity.id||y.activity.type]=y:y.type===bt&&(l[y.activity.id||y.activity.type]=!1)}}catch(J){s={error:J}}finally{try{p&&!p.done&&(a=v.return)&&a.call(v)}finally{if(s)throw s.error}}var S=R(Dt(this,r,n,i,d,this.machine.config.preserveActionOrder),2),g=S[0],w=S[1],N=R(yr(g,function(J){return J.type===Ve||J.type===Ge&&J.to===xe.Internal}),2),_=N[0],L=N[1],T=g.filter(function(J){var _e;return J.type===Tt&&((_e=J.activity)===null||_e===void 0?void 0:_e.type)===_t}),E=T.reduce(function(J,_e){return J[_e.activity.id]=zn(_e.activity,o.machine,w,i),J},r?m({},r.children):{}),b=f?e.configuration:r?r.configuration:[],C=De(b,this),B=new ee({value:c||r.value,context:w,_event:i,_sessionid:r?r._sessionid:null,historyValue:c?h?kn(h,c):void 0:r?r.historyValue:void 0,history:!c||e.source?r:void 0,actions:c?L:[],activities:c?l:r?r.activities:{},events:[],configuration:b,transitions:e.transitions,children:E,done:C,tags:_r(b),machine:this}),W=n!==w;B.changed=i.name===cr||W;var ae=B.history;ae&&delete ae.history;var wt=!C&&(this._transient||u.some(function(J){return J._transient}));if(!f&&(!wt||i.name===ye))return B;var Z=B;if(!C)for(wt&&(Z=this.resolveRaisedTransition(Z,{type:Sn},i));_.length;){var Ta=_.shift();Z=this.resolveRaisedTransition(Z,Ta._event,i)}var ba=Z.changed||(ae?!!Z.actions.length||W||typeof ae.value!=typeof Z.value||!xr(Z.value,ae.value):void 0);return Z.changed=ba,Z.history=ae,Z},t.prototype.getStateNode=function(e){if(ge(e))return this.machine.getStateNodeById(e);if(!this.states)throw new Error("Unable to retrieve child state '".concat(e,"' from '").concat(this.id,"'; no child states exist."));var r=this.states[e];if(!r)throw new Error("Child state '".concat(e,"' does not exist on '").concat(this.id,"'"));return r},t.prototype.getStateNodeById=function(e){var r=ge(e)?e.slice(jt.length):e;if(r===this.id)return this;var n=this.machine.idMap[r];if(!n)throw new Error("Child state node '#".concat(r,"' does not exist on machine '").concat(this.id,"'"));return n},t.prototype.getStateNodeByPath=function(e){if(typeof e=="string"&&ge(e))try{return this.getStateNodeById(e.slice(1))}catch{}for(var r=At(e,this.delimiter).slice(),n=this;r.length;){var i=r.shift();if(!i.length)break;n=n.getStateNode(i)}return n},t.prototype.resolve=function(e){var r,n=this;if(!e)return this.initialStateValue||me;switch(this.type){case"parallel":return Ie(this.initialStateValue,function(s,a){return s?n.getStateNode(a).resolve(e[a]||s):me});case"compound":if(x(e)){var i=this.getStateNode(e);return i.type==="parallel"||i.type==="compound"?(r={},r[e]=i.initialStateValue,r):e}return Object.keys(e).length?Ie(e,function(s,a){return s?n.getStateNode(a).resolve(s):me}):this.initialStateValue||{};default:return e||me}},t.prototype.getResolvedPath=function(e){if(ge(e)){var r=this.machine.idMap[e.slice(jt.length)];if(!r)throw new Error("Unable to find state node '".concat(e,"'"));return r.path}return At(e,this.delimiter)},Object.defineProperty(t.prototype,"initialStateValue",{get:function(){var e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;var r;if(this.type==="parallel")r=hr(this.states,function(n){return n.initialStateValue||me},function(n){return n.type!=="history"});else if(this.initial!==void 0){if(!this.states[this.initial])throw new Error("Initial state '".concat(this.initial,"' not found on '").concat(this.key,"'"));r=tt(this.states[this.initial])?this.initial:(e={},e[this.initial]=this.states[this.initial].initialStateValue,e)}else r={};return this.__cache.initialStateValue=r,this.__cache.initialStateValue},enumerable:!1,configurable:!0}),t.prototype.getInitialState=function(e,r){this._init();var n=this.getStateNodes(e);return this.resolveTransition({configuration:n,entrySet:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,r!=null?r:this.machine.context,void 0)},Object.defineProperty(t.prototype,"initialState",{get:function(){var e=this.initialStateValue;if(!e)throw new Error("Cannot retrieve initial state from simple state '".concat(this.id,"'."));return this.getInitialState(e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"target",{get:function(){var e;if(this.type==="history"){var r=this.config;x(r.target)?e=ge(r.target)?We(this.machine.getStateNodeById(r.target).path.slice(this.path.length-1)):r.target:e=r.target}return e},enumerable:!1,configurable:!0}),t.prototype.getRelativeStateNodes=function(e,r,n){return n===void 0&&(n=!0),n?e.type==="history"?e.resolveHistory(r):e.initialStateNodes:[e]},Object.defineProperty(t.prototype,"initialStateNodes",{get:function(){var e=this;if(tt(this))return[this];if(this.type==="compound"&&!this.initial)return Re||Ne(!1,"Compound state node '".concat(this.id,"' has no initial state.")),[this];var r=Je(this.initialStateValue);return P(r.map(function(n){return e.getFromRelativePath(n)}))},enumerable:!1,configurable:!0}),t.prototype.getFromRelativePath=function(e){if(!e.length)return[this];var r=R(e),n=r[0],i=r.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '".concat(n,"' from node with no states"));var s=this.getStateNode(n);if(s.type==="history")return s.resolveHistory();if(!this.states[n])throw new Error("Child state '".concat(n,"' does not exist on '").concat(this.id,"'"));return this.states[n].getFromRelativePath(i)},t.prototype.historyValue=function(e){if(!!Object.keys(this.states).length)return{current:e||this.initialStateValue,states:hr(this.states,function(r,n){if(!e)return r.historyValue();var i=x(e)?void 0:e[n];return r.historyValue(i||r.initialStateValue)},function(r){return!r.history})}},t.prototype.resolveHistory=function(e){var r=this;if(this.type!=="history")return[this];var n=this.parent;if(!e){var i=this.target;return i?P(Je(i).map(function(a){return n.getFromRelativePath(a)})):n.initialStateNodes}var s=In(n.path,"states")(e).current;return x(s)?[n.getStateNode(s)]:P(Je(s).map(function(a){return r.history==="deep"?n.getFromRelativePath(a):[n.states[a[0]]]}))},Object.defineProperty(t.prototype,"stateIds",{get:function(){var e=this,r=P(Object.keys(this.states).map(function(n){return e.states[n].stateIds}));return[this.id].concat(r)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"events",{get:function(){var e,r,n,i;if(this.__cache.events)return this.__cache.events;var s=this.states,a=new Set(this.ownEvents);if(s)try{for(var o=O(Object.keys(s)),u=o.next();!u.done;u=o.next()){var f=u.value,c=s[f];if(c.states)try{for(var h=(n=void 0,O(c.events)),d=h.next();!d.done;d=h.next()){var l=d.value;a.add("".concat(l))}}catch(v){n={error:v}}finally{try{d&&!d.done&&(i=h.return)&&i.call(h)}finally{if(n)throw n.error}}}}catch(v){e={error:v}}finally{try{u&&!u.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return this.__cache.events=Array.from(a)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ownEvents",{get:function(){var e=new Set(this.transitions.filter(function(r){return!(!r.target&&!r.actions.length&&r.internal)}).map(function(r){return r.eventType}));return Array.from(e)},enumerable:!1,configurable:!0}),t.prototype.resolveTarget=function(e){var r=this;if(e!==void 0)return e.map(function(n){if(!x(n))return n;var i=n[0]===r.delimiter;if(i&&!r.parent)return r.getStateNodeByPath(n.slice(1));var s=i?r.key+n:n;if(r.parent)try{var a=r.parent.getStateNodeByPath(s);return a}catch(o){throw new Error("Invalid transition definition for state node '".concat(r.id,`':
17
+ `).concat(o.message))}else return r.getStateNodeByPath(s)})},t.prototype.formatTransition=function(e){var r=this,n=Un(e.target),i="internal"in e?e.internal:n?n.some(function(u){return x(u)&&u[0]===r.delimiter}):!0,s=this.machine.options.guards,a=this.resolveTarget(n),o=m(m({},e),{actions:Xe(Q(e.actions)),cond:Er(e.cond,s),target:a,source:this,internal:i,eventType:e.event,toJSON:function(){return m(m({},o),{target:o.target?o.target.map(function(u){return"#".concat(u.id)}):void 0,source:"#".concat(r.id)})}});return o},t.prototype.formatTransitions=function(){var e,r,n=this,i;if(!this.config.on)i=[];else if(Array.isArray(this.config.on))i=this.config.on;else{var s=this.config.on,a=Ue,o=s[a],u=o===void 0?[]:o,f=St(s,[typeof a=="symbol"?a:a+""]);i=P(Object.keys(f).map(function(g){!Re&&g===ye&&Ne(!1,"Empty string transition configs (e.g., `{ on: { '': ... }}`) for transient transitions are deprecated. Specify the transition in the `{ always: ... }` property instead. "+'Please check the `on` configuration for "#'.concat(n.id,'".'));var w=de(g,f[g]);return Re||fi(n,g,w),w}).concat(de(Ue,u)))}var c=this.config.always?de("",this.config.always):[],h=this.config.onDone?de(String(Ze(this.id)),this.config.onDone):[];Re||Ne(!(this.config.onDone&&!this.parent),'Root nodes cannot have an ".onDone" transition. Please check the config of "'.concat(this.id,'".'));var d=P(this.invoke.map(function(g){var w=[];return g.onDone&&w.push.apply(w,D([],R(de(String(et(g.id)),g.onDone)),!1)),g.onError&&w.push.apply(w,D([],R(de(String(ke(g.id)),g.onError)),!1)),w})),l=this.after,v=P(D(D(D(D([],R(h),!1),R(d),!1),R(i),!1),R(c),!1).map(function(g){return Q(g).map(function(w){return n.formatTransition(w)})}));try{for(var p=O(l),y=p.next();!y.done;y=p.next()){var S=y.value;v.push(S)}}catch(g){e={error:g}}finally{try{y&&!y.done&&(r=p.return)&&r.call(p)}finally{if(e)throw e.error}}return v},t}();function Le(t,e){return new di(t,e)}var k=Vn,Y=Ct,Mt={exports:{}},Ar=function(e,r){return function(){for(var i=new Array(arguments.length),s=0;s<i.length;s++)i[s]=arguments[s];return e.apply(r,i)}},hi=Ar,Bt=Object.prototype.toString,Ft=function(t){return function(e){var r=Bt.call(e);return t[r]||(t[r]=r.slice(8,-1).toLowerCase())}}(Object.create(null));function ue(t){return t=t.toLowerCase(),function(r){return Ft(r)===t}}function qt(t){return Array.isArray(t)}function st(t){return typeof t=="undefined"}function vi(t){return t!==null&&!st(t)&&t.constructor!==null&&!st(t.constructor)&&typeof t.constructor.isBuffer=="function"&&t.constructor.isBuffer(t)}var Ir=ue("ArrayBuffer");function pi(t){var e;return typeof ArrayBuffer!="undefined"&&ArrayBuffer.isView?e=ArrayBuffer.isView(t):e=t&&t.buffer&&Ir(t.buffer),e}function yi(t){return typeof t=="string"}function mi(t){return typeof t=="number"}function Nr(t){return t!==null&&typeof t=="object"}function at(t){if(Ft(t)!=="object")return!1;var e=Object.getPrototypeOf(t);return e===null||e===Object.prototype}var gi=ue("Date"),Ei=ue("File"),wi=ue("Blob"),Si=ue("FileList");function Ht(t){return Bt.call(t)==="[object Function]"}function Ti(t){return Nr(t)&&Ht(t.pipe)}function bi(t){var e="[object FormData]";return t&&(typeof FormData=="function"&&t instanceof FormData||Bt.call(t)===e||Ht(t.toString)&&t.toString()===e)}var Oi=ue("URLSearchParams");function _i(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function xi(){return typeof navigator!="undefined"&&(navigator.product==="ReactNative"||navigator.product==="NativeScript"||navigator.product==="NS")?!1:typeof window!="undefined"&&typeof document!="undefined"}function Vt(t,e){if(!(t===null||typeof t=="undefined"))if(typeof t!="object"&&(t=[t]),qt(t))for(var r=0,n=t.length;r<n;r++)e.call(null,t[r],r,t);else for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.call(null,t[i],i,t)}function Gt(){var t={};function e(i,s){at(t[s])&&at(i)?t[s]=Gt(t[s],i):at(i)?t[s]=Gt({},i):qt(i)?t[s]=i.slice():t[s]=i}for(var r=0,n=arguments.length;r<n;r++)Vt(arguments[r],e);return t}function Ri(t,e,r){return Vt(e,function(i,s){r&&typeof i=="function"?t[s]=hi(i,r):t[s]=i}),t}function Ai(t){return t.charCodeAt(0)===65279&&(t=t.slice(1)),t}function Ii(t,e,r,n){t.prototype=Object.create(e.prototype,n),t.prototype.constructor=t,r&&Object.assign(t.prototype,r)}function Ni(t,e,r){var n,i,s,a={};e=e||{};do{for(n=Object.getOwnPropertyNames(t),i=n.length;i-- >0;)s=n[i],a[s]||(e[s]=t[s],a[s]=!0);t=Object.getPrototypeOf(t)}while(t&&(!r||r(t,e))&&t!==Object.prototype);return e}function Pi(t,e,r){t=String(t),(r===void 0||r>t.length)&&(r=t.length),r-=e.length;var n=t.indexOf(e,r);return n!==-1&&n===r}function ki(t){if(!t)return null;var e=t.length;if(st(e))return null;for(var r=new Array(e);e-- >0;)r[e]=t[e];return r}var Ci=function(t){return function(e){return t&&e instanceof t}}(typeof Uint8Array!="undefined"&&Object.getPrototypeOf(Uint8Array)),M={isArray:qt,isArrayBuffer:Ir,isBuffer:vi,isFormData:bi,isArrayBufferView:pi,isString:yi,isNumber:mi,isObject:Nr,isPlainObject:at,isUndefined:st,isDate:gi,isFile:Ei,isBlob:wi,isFunction:Ht,isStream:Ti,isURLSearchParams:Oi,isStandardBrowserEnv:xi,forEach:Vt,merge:Gt,extend:Ri,trim:_i,stripBOM:Ai,inherits:Ii,toFlatObject:Ni,kindOf:Ft,kindOfTest:ue,endsWith:Pi,toArray:ki,isTypedArray:Ci,isFileList:Si},Ee=M;function Pr(t){return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var kr=function(e,r,n){if(!r)return e;var i;if(n)i=n(r);else if(Ee.isURLSearchParams(r))i=r.toString();else{var s=[];Ee.forEach(r,function(u,f){u===null||typeof u=="undefined"||(Ee.isArray(u)?f=f+"[]":u=[u],Ee.forEach(u,function(h){Ee.isDate(h)?h=h.toISOString():Ee.isObject(h)&&(h=JSON.stringify(h)),s.push(Pr(f)+"="+Pr(h))}))}),i=s.join("&")}if(i){var a=e.indexOf("#");a!==-1&&(e=e.slice(0,a)),e+=(e.indexOf("?")===-1?"?":"&")+i}return e},Di=M;function ot(){this.handlers=[]}ot.prototype.use=function(e,r,n){return this.handlers.push({fulfilled:e,rejected:r,synchronous:n?n.synchronous:!1,runWhen:n?n.runWhen:null}),this.handlers.length-1},ot.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},ot.prototype.forEach=function(e){Di.forEach(this.handlers,function(n){n!==null&&e(n)})};var Ui=ot,Li=M,$i=function(e,r){Li.forEach(e,function(i,s){s!==r&&s.toUpperCase()===r.toUpperCase()&&(e[r]=i,delete e[s])})},Cr=M;function we(t,e,r,n,i){Error.call(this),this.message=t,this.name="AxiosError",e&&(this.code=e),r&&(this.config=r),n&&(this.request=n),i&&(this.response=i)}Cr.inherits(we,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code,status:this.response&&this.response.status?this.response.status:null}}});var Dr=we.prototype,Ur={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED"].forEach(function(t){Ur[t]={value:t}}),Object.defineProperties(we,Ur),Object.defineProperty(Dr,"isAxiosError",{value:!0}),we.from=function(t,e,r,n,i,s){var a=Object.create(Dr);return Cr.toFlatObject(t,a,function(u){return u!==Error.prototype}),we.call(a,t.message,e,r,n,i),a.name=t.name,s&&Object.assign(a,s),a};var Se=we,Lr={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},X=M;function ji(t,e){e=e||new FormData;var r=[];function n(s){return s===null?"":X.isDate(s)?s.toISOString():X.isArrayBuffer(s)||X.isTypedArray(s)?typeof Blob=="function"?new Blob([s]):Buffer.from(s):s}function i(s,a){if(X.isPlainObject(s)||X.isArray(s)){if(r.indexOf(s)!==-1)throw Error("Circular reference detected in "+a);r.push(s),X.forEach(s,function(u,f){if(!X.isUndefined(u)){var c=a?a+"."+f:f,h;if(u&&!a&&typeof u=="object"){if(X.endsWith(f,"{}"))u=JSON.stringify(u);else if(X.endsWith(f,"[]")&&(h=X.toArray(u))){h.forEach(function(d){!X.isUndefined(d)&&e.append(c,n(d))});return}}i(u,c)}}),r.pop()}else e.append(a,n(s))}return i(t),e}var $r=ji,zt=Se,Mi=function(e,r,n){var i=n.config.validateStatus;!n.status||!i||i(n.status)?e(n):r(new zt("Request failed with status code "+n.status,[zt.ERR_BAD_REQUEST,zt.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))},ut=M,Bi=ut.isStandardBrowserEnv()?function(){return{write:function(r,n,i,s,a,o){var u=[];u.push(r+"="+encodeURIComponent(n)),ut.isNumber(i)&&u.push("expires="+new Date(i).toGMTString()),ut.isString(s)&&u.push("path="+s),ut.isString(a)&&u.push("domain="+a),o===!0&&u.push("secure"),document.cookie=u.join("; ")},read:function(r){var n=document.cookie.match(new RegExp("(^|;\\s*)("+r+")=([^;]*)"));return n?decodeURIComponent(n[3]):null},remove:function(r){this.write(r,"",Date.now()-864e5)}}}():function(){return{write:function(){},read:function(){return null},remove:function(){}}}(),Fi=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},qi=function(e,r){return r?e.replace(/\/+$/,"")+"/"+r.replace(/^\/+/,""):e},Hi=Fi,Vi=qi,jr=function(e,r){return e&&!Hi(r)?Vi(e,r):r},Wt=M,Gi=["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"],zi=function(e){var r={},n,i,s;return e&&Wt.forEach(e.split(`
18
+ `),function(o){if(s=o.indexOf(":"),n=Wt.trim(o.substr(0,s)).toLowerCase(),i=Wt.trim(o.substr(s+1)),n){if(r[n]&&Gi.indexOf(n)>=0)return;n==="set-cookie"?r[n]=(r[n]?r[n]:[]).concat([i]):r[n]=r[n]?r[n]+", "+i:i}}),r},Mr=M,Wi=Mr.isStandardBrowserEnv()?function(){var e=/(msie|trident)/i.test(navigator.userAgent),r=document.createElement("a"),n;function i(s){var a=s;return e&&(r.setAttribute("href",a),a=r.href),r.setAttribute("href",a),{href:r.href,protocol:r.protocol?r.protocol.replace(/:$/,""):"",host:r.host,search:r.search?r.search.replace(/^\?/,""):"",hash:r.hash?r.hash.replace(/^#/,""):"",hostname:r.hostname,port:r.port,pathname:r.pathname.charAt(0)==="/"?r.pathname:"/"+r.pathname}}return n=i(window.location.href),function(a){var o=Mr.isString(a)?i(a):a;return o.protocol===n.protocol&&o.host===n.host}}():function(){return function(){return!0}}(),Jt=Se,Ji=M;function Br(t){Jt.call(this,t==null?"canceled":t,Jt.ERR_CANCELED),this.name="CanceledError"}Ji.inherits(Br,Jt,{__CANCEL__:!0});var ct=Br,Yi=function(e){var r=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return r&&r[1]||""},$e=M,Ki=Mi,Qi=Bi,Xi=kr,Zi=jr,es=zi,ts=Wi,rs=Lr,te=Se,ns=ct,is=Yi,Fr=function(e){return new Promise(function(n,i){var s=e.data,a=e.headers,o=e.responseType,u;function f(){e.cancelToken&&e.cancelToken.unsubscribe(u),e.signal&&e.signal.removeEventListener("abort",u)}$e.isFormData(s)&&$e.isStandardBrowserEnv()&&delete a["Content-Type"];var c=new XMLHttpRequest;if(e.auth){var h=e.auth.username||"",d=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";a.Authorization="Basic "+btoa(h+":"+d)}var l=Zi(e.baseURL,e.url);c.open(e.method.toUpperCase(),Xi(l,e.params,e.paramsSerializer),!0),c.timeout=e.timeout;function v(){if(!!c){var S="getAllResponseHeaders"in c?es(c.getAllResponseHeaders()):null,g=!o||o==="text"||o==="json"?c.responseText:c.response,w={data:g,status:c.status,statusText:c.statusText,headers:S,config:e,request:c};Ki(function(_){n(_),f()},function(_){i(_),f()},w),c=null}}if("onloadend"in c?c.onloadend=v:c.onreadystatechange=function(){!c||c.readyState!==4||c.status===0&&!(c.responseURL&&c.responseURL.indexOf("file:")===0)||setTimeout(v)},c.onabort=function(){!c||(i(new te("Request aborted",te.ECONNABORTED,e,c)),c=null)},c.onerror=function(){i(new te("Network Error",te.ERR_NETWORK,e,c,c)),c=null},c.ontimeout=function(){var g=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded",w=e.transitional||rs;e.timeoutErrorMessage&&(g=e.timeoutErrorMessage),i(new te(g,w.clarifyTimeoutError?te.ETIMEDOUT:te.ECONNABORTED,e,c)),c=null},$e.isStandardBrowserEnv()){var p=(e.withCredentials||ts(l))&&e.xsrfCookieName?Qi.read(e.xsrfCookieName):void 0;p&&(a[e.xsrfHeaderName]=p)}"setRequestHeader"in c&&$e.forEach(a,function(g,w){typeof s=="undefined"&&w.toLowerCase()==="content-type"?delete a[w]:c.setRequestHeader(w,g)}),$e.isUndefined(e.withCredentials)||(c.withCredentials=!!e.withCredentials),o&&o!=="json"&&(c.responseType=e.responseType),typeof e.onDownloadProgress=="function"&&c.addEventListener("progress",e.onDownloadProgress),typeof e.onUploadProgress=="function"&&c.upload&&c.upload.addEventListener("progress",e.onUploadProgress),(e.cancelToken||e.signal)&&(u=function(S){!c||(i(!S||S&&S.type?new ns:S),c.abort(),c=null)},e.cancelToken&&e.cancelToken.subscribe(u),e.signal&&(e.signal.aborted?u():e.signal.addEventListener("abort",u))),s||(s=null);var y=is(l);if(y&&["http","https","file"].indexOf(y)===-1){i(new te("Unsupported protocol "+y+":",te.ERR_BAD_REQUEST,e));return}c.send(s)})},ss=null,j=M,qr=$i,Hr=Se,as=Lr,os=$r,us={"Content-Type":"application/x-www-form-urlencoded"};function Vr(t,e){!j.isUndefined(t)&&j.isUndefined(t["Content-Type"])&&(t["Content-Type"]=e)}function cs(){var t;return(typeof XMLHttpRequest!="undefined"||typeof process!="undefined"&&Object.prototype.toString.call(process)==="[object process]")&&(t=Fr),t}function ls(t,e,r){if(j.isString(t))try{return(e||JSON.parse)(t),j.trim(t)}catch(n){if(n.name!=="SyntaxError")throw n}return(r||JSON.stringify)(t)}var lt={transitional:as,adapter:cs(),transformRequest:[function(e,r){if(qr(r,"Accept"),qr(r,"Content-Type"),j.isFormData(e)||j.isArrayBuffer(e)||j.isBuffer(e)||j.isStream(e)||j.isFile(e)||j.isBlob(e))return e;if(j.isArrayBufferView(e))return e.buffer;if(j.isURLSearchParams(e))return Vr(r,"application/x-www-form-urlencoded;charset=utf-8"),e.toString();var n=j.isObject(e),i=r&&r["Content-Type"],s;if((s=j.isFileList(e))||n&&i==="multipart/form-data"){var a=this.env&&this.env.FormData;return os(s?{"files[]":e}:e,a&&new a)}else if(n||i==="application/json")return Vr(r,"application/json"),ls(e);return e}],transformResponse:[function(e){var r=this.transitional||lt.transitional,n=r&&r.silentJSONParsing,i=r&&r.forcedJSONParsing,s=!n&&this.responseType==="json";if(s||i&&j.isString(e)&&e.length)try{return JSON.parse(e)}catch(a){if(s)throw a.name==="SyntaxError"?Hr.from(a,Hr.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:ss},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};j.forEach(["delete","get","head"],function(e){lt.headers[e]={}}),j.forEach(["post","put","patch"],function(e){lt.headers[e]=j.merge(us)});var Yt=lt,fs=M,ds=Yt,hs=function(e,r,n){var i=this||ds;return fs.forEach(n,function(a){e=a.call(i,e,r)}),e},Gr=function(e){return!!(e&&e.__CANCEL__)},zr=M,Kt=hs,vs=Gr,ps=Yt,ys=ct;function Qt(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new ys}var ms=function(e){Qt(e),e.headers=e.headers||{},e.data=Kt.call(e,e.data,e.headers,e.transformRequest),e.headers=zr.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),zr.forEach(["delete","get","head","post","put","patch","common"],function(i){delete e.headers[i]});var r=e.adapter||ps.adapter;return r(e).then(function(i){return Qt(e),i.data=Kt.call(e,i.data,i.headers,e.transformResponse),i},function(i){return vs(i)||(Qt(e),i&&i.response&&(i.response.data=Kt.call(e,i.response.data,i.response.headers,e.transformResponse))),Promise.reject(i)})},z=M,Wr=function(e,r){r=r||{};var n={};function i(c,h){return z.isPlainObject(c)&&z.isPlainObject(h)?z.merge(c,h):z.isPlainObject(h)?z.merge({},h):z.isArray(h)?h.slice():h}function s(c){if(z.isUndefined(r[c])){if(!z.isUndefined(e[c]))return i(void 0,e[c])}else return i(e[c],r[c])}function a(c){if(!z.isUndefined(r[c]))return i(void 0,r[c])}function o(c){if(z.isUndefined(r[c])){if(!z.isUndefined(e[c]))return i(void 0,e[c])}else return i(void 0,r[c])}function u(c){if(c in r)return i(e[c],r[c]);if(c in e)return i(void 0,e[c])}var f={url:a,method:a,data:a,baseURL:o,transformRequest:o,transformResponse:o,paramsSerializer:o,timeout:o,timeoutMessage:o,withCredentials:o,adapter:o,responseType:o,xsrfCookieName:o,xsrfHeaderName:o,onUploadProgress:o,onDownloadProgress:o,decompress:o,maxContentLength:o,maxBodyLength:o,beforeRedirect:o,transport:o,httpAgent:o,httpsAgent:o,cancelToken:o,socketPath:o,responseEncoding:o,validateStatus:u};return z.forEach(Object.keys(e).concat(Object.keys(r)),function(h){var d=f[h]||s,l=d(h);z.isUndefined(l)&&d!==u||(n[h]=l)}),n},Jr={version:"0.27.2"},gs=Jr.version,ie=Se,Xt={};["object","boolean","number","function","string","symbol"].forEach(function(t,e){Xt[t]=function(n){return typeof n===t||"a"+(e<1?"n ":" ")+t}});var Yr={};Xt.transitional=function(e,r,n){function i(s,a){return"[Axios v"+gs+"] Transitional option '"+s+"'"+a+(n?". "+n:"")}return function(s,a,o){if(e===!1)throw new ie(i(a," has been removed"+(r?" in "+r:"")),ie.ERR_DEPRECATED);return r&&!Yr[a]&&(Yr[a]=!0,console.warn(i(a," has been deprecated since v"+r+" and will be removed in the near future"))),e?e(s,a,o):!0}};function Es(t,e,r){if(typeof t!="object")throw new ie("options must be an object",ie.ERR_BAD_OPTION_VALUE);for(var n=Object.keys(t),i=n.length;i-- >0;){var s=n[i],a=e[s];if(a){var o=t[s],u=o===void 0||a(o,s,t);if(u!==!0)throw new ie("option "+s+" must be "+u,ie.ERR_BAD_OPTION_VALUE);continue}if(r!==!0)throw new ie("Unknown option "+s,ie.ERR_BAD_OPTION)}}var ws={assertOptions:Es,validators:Xt},Kr=M,Ss=kr,Qr=Ui,Xr=ms,ft=Wr,Ts=jr,Zr=ws,Te=Zr.validators;function be(t){this.defaults=t,this.interceptors={request:new Qr,response:new Qr}}be.prototype.request=function(e,r){typeof e=="string"?(r=r||{},r.url=e):r=e||{},r=ft(this.defaults,r),r.method?r.method=r.method.toLowerCase():this.defaults.method?r.method=this.defaults.method.toLowerCase():r.method="get";var n=r.transitional;n!==void 0&&Zr.assertOptions(n,{silentJSONParsing:Te.transitional(Te.boolean),forcedJSONParsing:Te.transitional(Te.boolean),clarifyTimeoutError:Te.transitional(Te.boolean)},!1);var i=[],s=!0;this.interceptors.request.forEach(function(l){typeof l.runWhen=="function"&&l.runWhen(r)===!1||(s=s&&l.synchronous,i.unshift(l.fulfilled,l.rejected))});var a=[];this.interceptors.response.forEach(function(l){a.push(l.fulfilled,l.rejected)});var o;if(!s){var u=[Xr,void 0];for(Array.prototype.unshift.apply(u,i),u=u.concat(a),o=Promise.resolve(r);u.length;)o=o.then(u.shift(),u.shift());return o}for(var f=r;i.length;){var c=i.shift(),h=i.shift();try{f=c(f)}catch(d){h(d);break}}try{o=Xr(f)}catch(d){return Promise.reject(d)}for(;a.length;)o=o.then(a.shift(),a.shift());return o},be.prototype.getUri=function(e){e=ft(this.defaults,e);var r=Ts(e.baseURL,e.url);return Ss(r,e.params,e.paramsSerializer)},Kr.forEach(["delete","get","head","options"],function(e){be.prototype[e]=function(r,n){return this.request(ft(n||{},{method:e,url:r,data:(n||{}).data}))}}),Kr.forEach(["post","put","patch"],function(e){function r(n){return function(s,a,o){return this.request(ft(o||{},{method:e,headers:n?{"Content-Type":"multipart/form-data"}:{},url:s,data:a}))}}be.prototype[e]=r(),be.prototype[e+"Form"]=r(!0)});var bs=be,Os=ct;function Oe(t){if(typeof t!="function")throw new TypeError("executor must be a function.");var e;this.promise=new Promise(function(i){e=i});var r=this;this.promise.then(function(n){if(!!r._listeners){var i,s=r._listeners.length;for(i=0;i<s;i++)r._listeners[i](n);r._listeners=null}}),this.promise.then=function(n){var i,s=new Promise(function(a){r.subscribe(a),i=a}).then(n);return s.cancel=function(){r.unsubscribe(i)},s},t(function(i){r.reason||(r.reason=new Os(i),e(r.reason))})}Oe.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},Oe.prototype.subscribe=function(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]},Oe.prototype.unsubscribe=function(e){if(!!this._listeners){var r=this._listeners.indexOf(e);r!==-1&&this._listeners.splice(r,1)}},Oe.source=function(){var e,r=new Oe(function(i){e=i});return{token:r,cancel:e}};var _s=Oe,xs=function(e){return function(n){return e.apply(null,n)}},Rs=M,As=function(e){return Rs.isObject(e)&&e.isAxiosError===!0},en=M,Is=Ar,dt=bs,Ns=Wr,Ps=Yt;function tn(t){var e=new dt(t),r=Is(dt.prototype.request,e);return en.extend(r,dt.prototype,e),en.extend(r,e),r.create=function(i){return tn(Ns(t,i))},r}var V=tn(Ps);V.Axios=dt,V.CanceledError=ct,V.CancelToken=_s,V.isCancel=Gr,V.VERSION=Jr.version,V.toFormData=$r,V.AxiosError=Se,V.Cancel=V.CanceledError,V.all=function(e){return Promise.all(e)},V.spread=xs,V.isAxiosError=As,Mt.exports=V,Mt.exports.default=V;var ht=Mt.exports;/*! js-cookie v3.0.1 | MIT */function vt(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)t[n]=r[n]}return t}var ks={read:function(t){return t[0]==='"'&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function Zt(t,e){function r(i,s,a){if(typeof document!="undefined"){a=vt({},e,a),typeof a.expires=="number"&&(a.expires=new Date(Date.now()+a.expires*864e5)),a.expires&&(a.expires=a.expires.toUTCString()),i=encodeURIComponent(i).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var o="";for(var u in a)!a[u]||(o+="; "+u,a[u]!==!0&&(o+="="+a[u].split(";")[0]));return document.cookie=i+"="+t.write(s,i)+o}}function n(i){if(!(typeof document=="undefined"||arguments.length&&!i)){for(var s=document.cookie?document.cookie.split("; "):[],a={},o=0;o<s.length;o++){var u=s[o].split("="),f=u.slice(1).join("=");try{var c=decodeURIComponent(u[0]);if(a[c]=t.read(f,c),i===c)break}catch{}}return i?a[i]:a}}return Object.create({set:r,get:n,remove:function(i,s){r(i,"",vt({},s,{expires:-1}))},withAttributes:function(i){return Zt(this.converter,vt({},this.attributes,i))},withConverter:function(i){return Zt(vt({},this.converter,i),this.attributes)}},{attributes:{value:Object.freeze(e)},converter:{value:Object.freeze(t)}})}var er=Zt(ks,{path:"/"}),Cs=Object.defineProperty,Ds=Object.defineProperties,Us=Object.getOwnPropertyDescriptors,pt=Object.getOwnPropertySymbols,rn=Object.prototype.hasOwnProperty,nn=Object.prototype.propertyIsEnumerable,sn=(t,e,r)=>e in t?Cs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,G=(t,e)=>{for(var r in e||(e={}))rn.call(e,r)&&sn(t,r,e[r]);if(pt)for(var r of pt(e))nn.call(e,r)&&sn(t,r,e[r]);return t},K=(t,e)=>Ds(t,Us(e)),Ls=(t,e)=>{var r={};for(var n in t)rn.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&pt)for(var n of pt(t))e.indexOf(n)<0&&nn.call(t,n)&&(r[n]=t[n]);return r};const tr="nhostRefreshToken",rr="nhostRefreshTokenExpiresAt",$s=3,js=300,Ms=5,Bs=0,re=10,je=20,Me={status:re,error:"invalid-email",message:"Email is incorrectly formatted"},nr={status:re,error:"invalid-password",message:"Password is incorrectly formatted"},Fs={status:re,error:"invalid-phone-number",message:"Phone number is incorrectly formatted"},qs={status:re,error:"invalid-mfa-ticket",message:"MFA ticket is invalid"},Hs={status:re,error:"no-mfa-ticket",message:"No MFA ticket has been provided"},Vs={status:re,error:"no-refresh-token",message:"No refresh token has been provided"},Gs={status:je,error:"refresher-already-running",message:"The token refresher is already running. You must wait until is has finished before submitting a new token."},Be={status:je,error:"already-signed-in",message:"User is already signed in"},zs={status:je,error:"unauthenticated-user",message:"User is not authenticated"},Ws={status:je,error:"user-not-anonymous",message:"User is not anonymous"},Js={status:je,error:"unverified-user",message:"Email needs verification"},Ys={status:re,error:"invalid-authentication-method",message:"Incorrect parameters"},Ks={status:re,error:"invalid-refresh-token",message:"Invalid or expired refresh token"},Fe=t=>{const e=ht.create({baseURL:t});return e.interceptors.response.use(r=>r,r=>{var n,i,s,a,o,u,f,c,h,d;return Promise.reject({error:{message:(o=(a=(s=(i=(n=r.response)==null?void 0:n.data)==null?void 0:i.message)!=null?s:r.message)!=null?a:r.request.responseText)!=null?o:JSON.stringify(r),status:(h=(c=(u=r.response)==null?void 0:u.status)!=null?c:(f=r.response)==null?void 0:f.data.statusCode)!=null?h:Bs,error:((d=r.response)==null?void 0:d.data.error)||r.request.statusText||"network"}})}),e},yt=typeof window!="undefined",mt=new Map,Qs=t=>{var e;return yt&&typeof localStorage!="undefined"?localStorage.getItem(t):(e=mt.get(t))!=null?e:null},Xs=(t,e)=>{yt&&typeof localStorage!="undefined"?e?localStorage.setItem(t,e):localStorage.removeItem(t):e?mt.set(t,e):mt.has(t)&&mt.delete(t)},Zs=(t,e)=>{if(t==="localStorage"||t==="web")return Qs;if(t==="cookie")return r=>{var n;return yt&&(n=er.get(r))!=null?n:null};if(!e)throw Error(`clientStorageType is set to '${t}' but no clientStorage has been given`);if(t==="react-native")return r=>{var n;return(n=e.getItem)==null?void 0:n.call(e,r)};if(t==="capacitor")return r=>{var n;return(n=e.get)==null?void 0:n.call(e,{key:r})};if(t==="expo-secure-storage")return r=>{var n;return(n=e.getItemAsync)==null?void 0:n.call(e,r)};if(t==="custom"){if(e.getItem&&e.removeItem)return e.getItem;if(e.getItemAsync)return e.getItemAsync;throw Error(`clientStorageType is set to 'custom' but clientStorage is missing either "getItem" and "removeItem" properties or "getItemAsync" property`)}throw Error(`Unknown storage type: ${t}`)},ea=(t,e)=>{if(t==="localStorage"||t==="web")return Xs;if(t==="cookie")return(r,n)=>{yt&&(n?er.set(r,n):er.remove(r))};if(!e)throw Error(`clientStorageType is set to '${t}' but no clienStorage has been given`);if(t==="react-native")return(r,n)=>{var i,s;return n?(i=e.setItem)==null?void 0:i.call(e,r,n):(s=e.removeItem)==null?void 0:s.call(e,r)};if(t==="capacitor")return(r,n)=>{var i,s;return n?(i=e.set)==null?void 0:i.call(e,{key:r,value:n}):(s=e.remove)==null?void 0:s.call(e,{key:r})};if(t==="expo-secure-storage")return async(r,n)=>{var i,s;return n?(i=e.setItemAsync)==null?void 0:i.call(e,r,n):(s=e.deleteItemAsync)==null?void 0:s.call(e,r)};if(t==="custom"){if(!e.removeItem)throw Error("clientStorageType is set to 'custom' but clientStorage is missing a removeItem property");if(e.setItem)return(r,n)=>{var i,s;return n?(i=e.setItem)==null?void 0:i.call(e,r,n):(s=e.removeItem)==null?void 0:s.call(e,r)};if(e.setItemAsync)return async(r,n)=>{var i,s;return n?(i=e.setItemAsync)==null?void 0:i.call(e,r,n):(s=e.removeItem)==null?void 0:s.call(e,r)};throw Error("clientStorageType is set to 'custom' but clientStorage is missing setItem or setItemAsync property")}throw Error(`Unknown storage type: ${t}`)},an=(t,e)=>{const r=e&&Object.entries(e).map(([n,i])=>{const s=Array.isArray(i)?i.join(","):typeof i=="object"?JSON.stringify(i):i;return`${n}=${encodeURIComponent(s)}`}).join("&");return r?`${t}?${r}`:t},ce=(t,e)=>{if(!(e!=null&&e.redirectTo))return e;const r=new URL(t),n=Object.fromEntries(new URLSearchParams(r.search)),i=new URL(e.redirectTo.startsWith("/")?r.origin+e.redirectTo:e.redirectTo),s=new URLSearchParams(i.search);let a=Object.fromEntries(s);e.redirectTo.startsWith("/")&&(a=G(G({},n),a));let o=r.pathname;return i.pathname.length>1&&(o+=i.pathname.slice(1)),K(G({},e),{redirectTo:an(i.origin+o,a)})};function gt(t,e){var r;if(!e){if(typeof window=="undefined")return;e=((r=window.location)==null?void 0:r.href)||""}t=t.replace(/[\[\]]/g,"\\$&");const n=new RegExp("[?&#]"+t+"(=([^&#]*)|&|#|$)"),i=n.exec(e);return i?i[2]?decodeURIComponent(i[2].replace(/\+/g," ")):"":null}function on(t){var e;if(typeof window=="undefined")return;const r=window==null?void 0:window.location;if(!!r&&r){const n=new URLSearchParams(r.search),i=new URLSearchParams((e=r.hash)==null?void 0:e.slice(1));n.delete(t),i.delete(t);let s=window.location.pathname;Array.from(n).length&&(s+=`?${n.toString()}`),Array.from(i).length&&(s+=`#${i.toString()}`),window.history.pushState({},"",s)}}const Et=t=>!!t&&typeof t=="string"&&!!String(t).toLowerCase().match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/),un=t=>!!t&&typeof t=="string"&&t.length>=$s,ta=t=>!!t&&typeof t=="string",ra=t=>t&&typeof t=="string"&&t.match(/^mfaTotp:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),cn={user:null,mfa:null,accessToken:{value:null,expiresAt:null},refreshTimer:{startedAt:null,attempts:0,lastAttempt:null},refreshToken:{value:null},errors:{}},na=({backendUrl:t,clientUrl:e,interpreter:r})=>{const n=Fe(t);return Le({schema:{context:{},events:{}},tsTypes:{},preserveActionOrder:!0,id:"changeEmail",initial:"idle",context:{error:null},states:{idle:{on:{REQUEST:[{cond:"invalidEmail",actions:"saveInvalidEmailError",target:".error"},{target:"requesting"}]},initial:"initial",states:{initial:{},success:{},error:{}}},requesting:{invoke:{src:"requestChange",id:"requestChange",onDone:{target:"idle.success",actions:"reportSuccess"},onError:{actions:["saveRequestError","reportError"],target:"idle.error"}}}}},{actions:{saveInvalidEmailError:k({error:i=>Me}),saveRequestError:k({error:(i,{data:{error:s}})=>s}),reportError:Y(i=>({type:"ERROR",error:i.error})),reportSuccess:Y("SUCCESS")},guards:{invalidEmail:(i,{email:s})=>!Et(s)},services:{requestChange:async(i,{email:s,options:a})=>(await n.post("/user/email/change",{newEmail:s,options:ce(e,a)},{headers:{authorization:`Bearer ${r==null?void 0:r.state.context.accessToken.value}`}})).data}})},ia=({backendUrl:t,interpreter:e})=>{const r=Fe(t);return Le({schema:{context:{},events:{}},tsTypes:{},preserveActionOrder:!0,id:"changePassword",initial:"idle",context:{error:null},states:{idle:{on:{REQUEST:[{cond:"invalidPassword",actions:"saveInvalidPasswordError",target:".error"},{target:"requesting"}]},initial:"initial",states:{initial:{},success:{},error:{}}},requesting:{invoke:{src:"requestChange",id:"requestChange",onDone:{target:"idle.success",actions:"reportSuccess"},onError:{actions:["saveRequestError","reportError"],target:"idle.error"}}}}},{actions:{saveInvalidPasswordError:k({error:n=>nr}),saveRequestError:k({error:(n,{data:{error:i}})=>i}),reportError:Y(n=>({type:"ERROR",error:n.error})),reportSuccess:Y("SUCCESS")},guards:{invalidPassword:(n,{password:i})=>!un(i)},services:{requestChange:(n,{password:i})=>r.post("/user/password",{newPassword:i},{headers:{authorization:`Bearer ${e==null?void 0:e.state.context.accessToken.value}`}})}})},sa=({backendUrl:t,clientUrl:e})=>{const r=Fe(t);return Le({schema:{context:{},events:{}},tsTypes:{},preserveActionOrder:!0,id:"changePassword",initial:"idle",context:{error:null},states:{idle:{on:{REQUEST:[{cond:"invalidEmail",actions:"saveInvalidEmailError",target:".error"},{target:"requesting"}]},initial:"initial",states:{initial:{},success:{},error:{}}},requesting:{invoke:{src:"requestChange",id:"requestChange",onDone:{target:"idle.success",actions:"reportSuccess"},onError:{actions:["saveRequestError","reportError"],target:"idle.error"}}}}},{actions:{saveInvalidEmailError:k({error:n=>Me}),saveRequestError:k({error:(n,{data:{error:i}})=>i}),reportError:Y(n=>({type:"ERROR",error:n.error})),reportSuccess:Y("SUCCESS")},guards:{invalidEmail:(n,{email:i})=>!Et(i)},services:{requestChange:(n,{email:i,options:s})=>r.post("/user/password/reset",{email:i,options:ce(e,s)})}})},aa=({backendUrl:t,clientUrl:e})=>{const r=Fe(t);return Le({schema:{context:{},events:{}},tsTypes:{},preserveActionOrder:!0,id:"sendVerificationEmail",initial:"idle",context:{error:null},states:{idle:{on:{REQUEST:[{cond:"invalidEmail",actions:"saveInvalidEmailError",target:".error"},{target:"requesting"}]},initial:"initial",states:{initial:{},success:{},error:{}}},requesting:{invoke:{src:"request",id:"request",onDone:{target:"idle.success",actions:"reportSuccess"},onError:{actions:["saveRequestError","reportError"],target:"idle.error"}}}}},{actions:{saveInvalidEmailError:k({error:n=>Me}),saveRequestError:k({error:(n,{data:{error:i}})=>i}),reportError:Y(n=>({type:"ERROR",error:n.error})),reportSuccess:Y("SUCCESS")},guards:{invalidEmail:(n,{email:i})=>!Et(i)},services:{request:async(n,{email:i,options:s})=>(await r.post("/user/email/send-verification-email",{email:i,options:ce(e,s)})).data}})},oa=({backendUrl:t,clientUrl:e,clientStorageGetter:r,clientStorageSetter:n,clientStorageType:i="web",clientStorage:s,refreshIntervalTime:a,autoRefreshToken:o=!0,autoSignIn:u=!0})=>{const f=r||Zs(i,s),c=n||ea(i,s),h=Fe(t),d=async(l,v,p)=>(await h.post(l,v,p)).data;return Le({schema:{context:{},events:{}},tsTypes:{},context:cn,preserveActionOrder:!0,id:"nhost",type:"parallel",states:{authentication:{initial:"starting",on:{SESSION_UPDATE:[{cond:"hasSession",actions:["saveSession","resetTimer","reportTokenChanged"],target:".signedIn"}]},states:{starting:{entry:"resetErrors",tags:["loading"],always:{cond:"isSignedIn",target:"signedIn"},invoke:{id:"importRefreshToken",src:"importRefreshToken",onDone:{actions:["saveSession","reportTokenChanged"],target:"signedIn"},onError:{actions:["saveAuthenticationError"],target:"signedOut"}}},signedOut:{initial:"noErrors",entry:"reportSignedOut",states:{noErrors:{},success:{},needsSmsOtp:{},needsMfa:{},failed:{initial:"server",states:{server:{},validation:{states:{password:{},email:{},phoneNumber:{},mfaTicket:{}}}}},signingOut:{initial:"pending",entry:["clearContextExceptRefreshToken"],invoke:{src:"signout",id:"signingOut",onDone:{target:".destroyingRefreshToken"},onError:{target:"failed.server",actions:["saveAuthenticationError"]}},states:{pending:{},destroyingRefreshToken:{initial:"pending",states:{pending:{},failed:{}},invoke:{id:"destroyingRefreshToken",src:"destroyRefreshToken",onDone:{target:"#nhost.authentication.signedOut.success",actions:["removeRefreshToken","reportTokenChanged"]},onError:{target:".failed",actions:["saveAuthenticationError"]}}}}}},on:{SIGNIN_PASSWORD:[{cond:"invalidEmail",actions:["saveInvalidEmail"],target:".failed.validation.email"},{cond:"invalidPassword",actions:["saveInvalidPassword"],target:".failed.validation.password"},"#nhost.authentication.authenticating.password"],SIGNIN_PASSWORDLESS_EMAIL:[{cond:"invalidEmail",actions:"saveInvalidEmail",target:".failed.validation.email"},"#nhost.authentication.authenticating.passwordlessEmail"],SIGNIN_PASSWORDLESS_SMS:[{cond:"invalidPhoneNumber",actions:"saveInvalidPhoneNumber",target:".failed.validation.phoneNumber"},"#nhost.authentication.authenticating.passwordlessSms"],SIGNIN_PASSWORDLESS_SMS_OTP:[{cond:"invalidPhoneNumber",actions:"saveInvalidPhoneNumber",target:".failed.validation.phoneNumber"},"#nhost.authentication.authenticating.passwordlessSmsOtp"],SIGNUP_EMAIL_PASSWORD:[{cond:"invalidEmail",actions:"saveInvalidSignUpEmail",target:".failed.validation.email"},{cond:"invalidPassword",actions:"saveInvalidSignUpPassword",target:".failed.validation.password"},"#nhost.authentication.registering"],SIGNIN_ANONYMOUS:"#nhost.authentication.authenticating.anonymous",SIGNIN_MFA_TOTP:[{cond:"noMfaTicket",actions:["saveNoMfaTicketError"],target:".failed"},{cond:"invalidMfaTicket",actions:["saveInvalidMfaTicketError"],target:".failed"},"#nhost.authentication.authenticating.mfa.totp"]}},authenticating:{entry:"resetErrors",states:{passwordlessEmail:{invoke:{src:"signInPasswordlessEmail",id:"authenticatePasswordlessEmail",onDone:{target:"#nhost.authentication.signedOut",actions:"reportAwaitEmailVerification"},onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed.server"}}},passwordlessSms:{invoke:{src:"signInPasswordlessSms",id:"authenticatePasswordlessSms",onDone:"#nhost.authentication.signedOut.needsSmsOtp",onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed.server"}}},passwordlessSmsOtp:{invoke:{src:"signInPasswordlessSmsOtp",id:"authenticatePasswordlessSmsOtp",onDone:{actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed.server"}}},password:{invoke:{src:"signInPassword",id:"authenticateUserWithPassword",onDone:[{cond:"hasMfaTicket",actions:["saveMfaTicket"],target:"#nhost.authentication.signedOut.needsMfa"},{actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"}],onError:[{cond:"unverified",actions:"reportAwaitEmailVerification",target:"#nhost.authentication.signedOut"},{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed.server"}]}},anonymous:{invoke:{src:"signInAnonymous",id:"authenticateAnonymously",onDone:{actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed.server"}}},mfa:{states:{totp:{invoke:{src:"signInMfaTotp",id:"signInMfaTotp",onDone:{actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:{actions:["saveAuthenticationError"],target:"#nhost.authentication.signedOut.failed.server"}}}}}}},registering:{entry:["resetErrors"],invoke:{src:"registerUser",id:"registerUser",onDone:[{cond:"hasSession",target:"signedIn",actions:["saveSession","reportTokenChanged"]},{actions:"reportAwaitEmailVerification",target:"signedOut"}],onError:[{cond:"unverified",actions:"reportAwaitEmailVerification",target:"signedOut"},{actions:"saveRegistrationError",target:"signedOut.failed.server"}]}},signedIn:{type:"parallel",entry:["reportSignedIn","cleanUrl","broadcastToken","resetErrors"],on:{SIGNOUT:"signedOut.signingOut",DEANONYMIZE:{target:".deanonymizing"}},states:{refreshTimer:{id:"timer",initial:"idle",states:{disabled:{type:"final"},stopped:{always:{cond:"noToken",target:"idle"}},idle:{always:[{cond:"isAutoRefreshDisabled",target:"disabled"},{cond:"hasRefreshToken",target:"running"}]},running:{initial:"pending",entry:"resetTimer",states:{pending:{after:{"1000":{internal:!1,target:"pending"}},always:{cond:"refreshTimerShouldRefresh",target:"refreshing"}},refreshing:{invoke:{src:"refreshToken",id:"refreshToken",onDone:{actions:["saveSession","resetTimer","reportTokenChanged"],target:"pending"},onError:[{actions:"saveRefreshAttempt",target:"pending"}]}}}}}},deanonymizing:{initial:"error",states:{error:{},success:{}}}}}}},token:{initial:"idle",states:{idle:{on:{TRY_TOKEN:"running"},initial:"noErrors",states:{noErrors:{},error:{}}},running:{invoke:{src:"refreshToken",id:"authenticateWithToken",onDone:{actions:["saveSession","reportTokenChanged"],target:["#nhost.authentication.signedIn","idle.noErrors"]},onError:[{cond:"isSignedIn",target:"idle.error"},{actions:"saveAuthenticationError",target:["#nhost.authentication.signedOut.failed.server","idle.error"]}]}}}},email:{initial:"unknown",on:{SIGNED_IN:[{cond:"needsVerification",target:".awaitingVerification"},".valid"],SIGNOUT:".unknown",AWAIT_EMAIL_VERIFICATION:".awaitingVerification"},states:{unknown:{},awaitingVerification:{},valid:{}}}}},{actions:{reportSignedIn:Y("SIGNED_IN"),reportSignedOut:Y("SIGNED_OUT"),reportAwaitEmailVerification:Y("AWAIT_EMAIL_VERIFICATION"),reportTokenChanged:Y("TOKEN_CHANGED"),clearContextExceptRefreshToken:k(({refreshToken:{value:l}})=>(c(rr,null),K(G({},cn),{refreshToken:{value:l}}))),saveSession:k({user:(l,{data:v})=>{var p;return(p=v==null?void 0:v.session)==null?void 0:p.user},accessToken:(l,{data:v})=>{var p,y;if(v.session.accessTokenExpiresIn){const S=new Date(Date.now()+v.session.accessTokenExpiresIn*1e3).toISOString();c(rr,S)}else c(rr,null);return{value:(p=v==null?void 0:v.session)==null?void 0:p.accessToken,expiresAt:new Date(Date.now()+((y=v==null?void 0:v.session)==null?void 0:y.accessTokenExpiresIn)*1e3)}},refreshToken:(l,{data:v})=>{var p;return c(tr,v.session.refreshToken),{value:(p=v==null?void 0:v.session)==null?void 0:p.refreshToken}}}),saveMfaTicket:k({mfa:(l,v)=>{var p,y;return(y=(p=v.data)==null?void 0:p.mfa)!=null?y:null}}),resetTimer:k({refreshTimer:(l,v)=>({startedAt:new Date,attempts:0,lastAttempt:null})}),saveRefreshAttempt:k({refreshTimer:(l,v)=>({startedAt:l.refreshTimer.startedAt,attempts:l.refreshTimer.attempts+1,lastAttempt:new Date})}),saveAuthenticationError:k({errors:({errors:l},{data:{error:v}})=>K(G({},l),{authentication:v})}),resetErrors:k({errors:l=>({})}),saveInvalidEmail:k({errors:({errors:l})=>K(G({},l),{authentication:Me})}),saveInvalidPassword:k({errors:({errors:l})=>K(G({},l),{authentication:nr})}),saveInvalidPhoneNumber:k({errors:({errors:l})=>K(G({},l),{authentication:Fs})}),saveInvalidMfaTicketError:k({errors:({errors:l})=>K(G({},l),{authentication:qs})}),saveNoMfaTicketError:k({errors:({errors:l})=>K(G({},l),{authentication:Hs})}),saveRegistrationError:k({errors:({errors:l},{data:{error:v}})=>K(G({},l),{registration:v})}),saveInvalidSignUpPassword:k({errors:({errors:l})=>K(G({},l),{registration:nr})}),saveInvalidSignUpEmail:k({errors:({errors:l})=>K(G({},l),{registration:Me})}),removeRefreshToken:k({refreshToken:l=>({value:null})}),cleanUrl:()=>{u&&gt("refreshToken")&&(on("refreshToken"),on("type"))},broadcastToken:l=>{if(u)try{new BroadcastChannel("nhost").postMessage(l.refreshToken.value)}catch{}}},guards:{needsVerification:(l,v)=>!l.user||l.user.isAnonymous,isSignedIn:l=>!!l.user&&!!l.refreshToken.value&&!!l.accessToken.value,noToken:l=>!l.refreshToken.value,noMfaTicket:(l,{ticket:v})=>{var p;return!v&&!((p=l.mfa)!=null&&p.ticket)},hasRefreshToken:l=>!!l.refreshToken.value,isAutoRefreshDisabled:()=>!o,refreshTimerShouldRefresh:l=>{var v;const{expiresAt:p}=l.accessToken;return p?l.refreshTimer.lastAttempt?Date.now()-l.refreshTimer.lastAttempt.getTime()>Ms*1e3:a&&Date.now()-(((v=l.refreshTimer.startedAt)==null?void 0:v.getTime())||0)>a*1e3?!0:p.getTime()-Date.now()-1e3*js<=0:!1},unverified:(l,{data:{error:v}})=>v.status===401&&v.message==="Email is not verified",hasSession:(l,v)=>{var p;return!!((p=v.data)!=null&&p.session)},hasMfaTicket:(l,v)=>{var p;return!!((p=v.data)!=null&&p.mfa)},invalidEmail:(l,{email:v})=>!Et(v),invalidPassword:(l,{password:v})=>!un(v),invalidPhoneNumber:(l,{phoneNumber:v})=>!ta(v),invalidMfaTicket:(l,{ticket:v})=>{var p;return!ra(v||((p=l.mfa)==null?void 0:p.ticket))}},services:{signInPassword:(l,{email:v,password:p})=>d("/signin/email-password",{email:v,password:p}),signInPasswordlessSms:(l,{phoneNumber:v,options:p})=>d("/signin/passwordless/sms",{phoneNumber:v,options:ce(e,p)}),signInPasswordlessSmsOtp:(l,{phoneNumber:v,otp:p})=>d("/signin/passwordless/sms/otp",{phoneNumber:v,otp:p}),signInPasswordlessEmail:(l,{email:v,options:p})=>d("/signin/passwordless/email",{email:v,options:ce(e,p)}),signInAnonymous:l=>d("/signin/anonymous"),signInMfaTotp:(l,{ticket:v,otp:p})=>{var y;return d("/signin/mfa/totp",{ticket:v||((y=l.mfa)==null?void 0:y.ticket),otp:p})},refreshToken:async(l,v)=>{const p=v.type==="TRY_TOKEN"?v.token:l.refreshToken.value;return{session:await d("/token",{refreshToken:p})}},signout:(l,v)=>d("/signout",{refreshToken:l.refreshToken.value,all:!!v.all}),destroyRefreshToken:async()=>Promise.resolve(c(tr,null)),registerUser:(l,{email:v,password:p,options:y})=>d("/signup/email-password",{email:v,password:p,options:ce(e,y)}),importRefreshToken:async()=>{let l=null;if(u){const p=gt("refreshToken")||null;if(p)try{return{session:await d("/token",{refreshToken:p})}}catch(y){l=y.error}else{const y=gt("error");if(y)return Promise.reject({error:{status:re,error:y,message:gt("errorDescription")||y}})}}const v=await f(tr);if(v)try{return{session:await d("/token",{refreshToken:v})}}catch(p){l=p.error}return Promise.reject({error:l})}}})};class ua{constructor(e){var r=e,{clientStorageType:n="web",autoSignIn:i=!0,autoRefreshToken:s=!0,start:a=!0,backendUrl:o,clientUrl:u}=r,f=Ls(r,["clientStorageType","autoSignIn","autoRefreshToken","start","backendUrl","clientUrl"]);if(this._subscriptions=new Set,this.backendUrl=o,this.clientUrl=u,this.machine=oa(K(G({},f),{backendUrl:o,clientUrl:u,clientStorageType:n,autoSignIn:i,autoRefreshToken:s})),a&&(this.interpreter=pe(this.machine),this.interpreter.start()),typeof window!="undefined"&&i)try{this._channel=new BroadcastChannel("nhost"),this._channel.addEventListener("message",c=>{var h;const d=(h=this.interpreter)==null?void 0:h.state.context.refreshToken.value;this.interpreter&&c.data!==d&&this.interpreter.send({type:"TRY_TOKEN",token:c.data})})}catch{}}get interpreter(){return this._interpreter}set interpreter(e){this._interpreter=e,e&&this._subscriptions.forEach(r=>r(this))}onStart(e){this.interpreter?e(this):this._subscriptions.add(e)}}var ln=Object.getOwnPropertySymbols,ca=Object.prototype.hasOwnProperty,la=Object.prototype.propertyIsEnumerable,fa=(t,e)=>{var r={};for(var n in t)ca.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&ln)for(var n of ln(t))e.indexOf(n)<0&&la.call(t,n)&&(r[n]=t[n]);return r};const da=()=>typeof window!="undefined",se=t=>!t||!t.accessToken.value||!t.refreshToken.value||!t.accessToken.expiresAt?null:{accessToken:t.accessToken.value,accessTokenExpiresIn:(t.accessToken.expiresAt.getTime()-Date.now())/1e3,refreshToken:t.refreshToken.value,user:t.user};class ha{constructor({url:e,autoRefreshToken:r=!0,autoSignIn:n=!0,autoLogin:i,clientStorage:s,clientStorageType:a,clientStorageGetter:o,clientStorageSetter:u,refreshIntervalTime:f,start:c=!0}){var h;this._client=new ua({backendUrl:e,clientUrl:typeof window!="undefined"&&((h=window.location)==null?void 0:h.origin)||"",autoRefreshToken:r,autoSignIn:typeof i=="boolean"?i:n,start:c,clientStorage:s,clientStorageType:a,clientStorageGetter:o,clientStorageSetter:u,refreshIntervalTime:f})}async signUp(e){const r=await this.waitUntilReady(),{email:n,password:i,options:s}=e;return new Promise(a=>{const{changed:o}=r.send("SIGNUP_EMAIL_PASSWORD",{email:n,password:i,options:s});if(!o)return a({session:null,error:Be});r.onTransition(u=>{if(u.matches({authentication:{signedOut:"noErrors"},email:"awaitingVerification"}))return a({session:null,error:null});if(u.matches({authentication:{signedOut:"failed"}}))return a({session:null,error:u.context.errors.registration||null});if(u.matches({authentication:"signedIn"}))return a({session:se(u.context),error:null})})})}async signIn(e){const r=await this.waitUntilReady();if("provider"in e){const{provider:i,options:s}=e,a=an(`${this._client.backendUrl}/signin/provider/${i}`,ce(this._client.clientUrl,s));return da()&&(window.location.href=a),{providerUrl:a,provider:i,session:null,mfa:null,error:null}}if("email"in e&&"password"in e)return new Promise(i=>{const{changed:s}=r.send("SIGNIN_PASSWORD",e);if(!s)return i({session:null,mfa:null,error:Be});r.onTransition(a=>{a.matches({authentication:"signedIn"})?i({session:se(a.context),mfa:null,error:null}):a.matches({authentication:{signedOut:"noErrors"},email:"awaitingVerification"})?i({session:null,mfa:null,error:Js}):a.matches({authentication:{signedOut:"needsMfa"}})?i({session:null,mfa:a.context.mfa,error:null}):a.matches({authentication:{signedOut:"failed"}})&&i({session:null,mfa:null,error:a.context.errors.authentication||null})})});if("email"in e&&!("otp"in e))return new Promise(i=>{const{changed:s}=r.send("SIGNIN_PASSWORDLESS_EMAIL",e);if(!s)return i({session:null,mfa:null,error:Be});r.onTransition(a=>{a.matches({authentication:{signedOut:"noErrors"},email:"awaitingVerification"})?i({session:null,mfa:null,error:null}):a.matches({authentication:{signedOut:"failed"}})&&i({session:null,mfa:null,error:a.context.errors.authentication||null})})});if("phoneNumber"in e&&!("otp"in e))return new Promise(i=>{const{changed:s}=r.send("SIGNIN_PASSWORDLESS_SMS",e);if(!s)return i({session:null,mfa:null,error:Be});r.onTransition(a=>{a.matches({authentication:{signedOut:"needsSmsOtp"}})?i({session:null,mfa:null,error:null}):a.matches({authentication:{signedOut:"failed"}})&&i({session:null,mfa:null,error:a.context.errors.authentication||null})})});if("otp"in e)return new Promise(i=>{const{changed:s}=r.send("SIGNIN_PASSWORDLESS_SMS_OTP",e);if(!s)return i({session:null,mfa:null,error:Be});r.onTransition(a=>{a.matches({authentication:"signedIn"})?i({session:se(a.context),mfa:null,error:null}):a.matches({authentication:{signedOut:"failed"}})&&i({session:null,mfa:null,error:a.context.errors.authentication||null})})});const{changed:n}=r.send("SIGNIN_ANONYMOUS");return n?new Promise(i=>{r.onTransition(s=>{s.matches({authentication:"signedIn"})&&i({session:se(s.context),mfa:null,error:null}),s.matches({authentication:{signedOut:"failed"}})&&i({session:null,mfa:null,error:s.context.errors.authentication||null})})}):{session:null,mfa:null,error:Ys}}async signOut(e){const r=await this.waitUntilReady();return new Promise(n=>{const{event:i}=r.send("SIGNOUT",{all:e==null?void 0:e.all});if(i.type!=="SIGNED_OUT")return n({error:zs});r.onTransition(s=>{s.matches({authentication:{signedOut:"success"}})?n({error:null}):s.matches({authentication:{signedOut:{failed:"server"}}})&&n({error:s.context.errors.signout||null})})})}async resetPassword({email:e,options:r}){return new Promise(n=>{const i=pe(sa(this._client));i.onTransition(({event:s})=>{if(s.type==="ERROR")return n({error:s.error});if(s.type==="SUCCESS")return n({error:null})}),i.start(),i.send("REQUEST",{email:e,options:r})})}async changePassword(e){return new Promise(r=>{const n=pe(ia(this._client));n.onTransition(({event:i})=>{if(i.type==="ERROR")return r({error:i.error});if(i.type==="SUCCESS")return r({error:null})}),n.start(),n.send("REQUEST",{password:e.newPassword})})}async sendVerificationEmail(e){return new Promise(r=>{const n=pe(aa(this._client));n.onTransition(({event:i})=>{if(i.type==="ERROR")return r({error:i.error});if(i.type==="SUCCESS")return r({error:null})}),n.start(),n.send("REQUEST",{email:e.email,options:e.options})})}async changeEmail({newEmail:e,options:r}){return new Promise(n=>{const i=pe(na(this._client));i.onTransition(({event:s})=>{if(s.type==="ERROR")return n({error:s.error});if(s.type==="SUCCESS")return n({error:null})}),i.start(),i.send("REQUEST",{email:e,options:r})})}async deanonymize(e){const r=await this.waitUntilReady();return new Promise(n=>{var i;if(!this.isAuthenticated()||!((i=r.state.context.user)!=null&&i.isAnonymous))return{error:Ws};const s=e,{signInMethod:a,connection:o}=s,u=fa(s,["signInMethod","connection"]);r.send("DEANONYMIZE",{signInMethod:a,connection:o,options:u}),r.onTransition(f=>{f.matches({authentication:{signedIn:{deanonymizing:"success"}}})?n({error:null}):f.matches({authentication:{signedIn:{deanonymizing:"error"}}})&&n({error:f.context.errors.authentication||null})}),r.start()})}onTokenChanged(e){const r=n=>n.onTransition(({event:i,context:s})=>{i.type==="TOKEN_CHANGED"&&e(se(s))});if(this._client.interpreter){const n=r(this._client.interpreter);return()=>n.stop()}else return this._client.onStart(n=>{r(n.interpreter)}),()=>{console.log("onTokenChanged was added before the interpreter started. Cannot unsubscribe listener.")}}onAuthStateChanged(e){const r=n=>n.onTransition(({event:i,context:s})=>{(i.type==="SIGNED_IN"||i.type==="SIGNED_OUT")&&e(i.type,se(s))});if(this._client.interpreter){const n=r(this._client.interpreter);return()=>n.stop()}else return this._client.onStart(n=>{r(n.interpreter)}),()=>{console.log("onAuthStateChanged was added before the interpreter started. Cannot unsubscribe listener.")}}isAuthenticated(){var e;return!!((e=this._client.interpreter)!=null&&e.state.matches({authentication:"signedIn"}))}async isAuthenticatedAsync(){return(await this.waitUntilReady()).state.matches({authentication:"signedIn"})}getAuthenticationStatus(){return this.isReady()?{isAuthenticated:this.isAuthenticated(),isLoading:!1}:{isAuthenticated:!1,isLoading:!0}}getJWTToken(){return this.getAccessToken()}getAccessToken(){var e,r;return(r=(e=this._client.interpreter)==null?void 0:e.state.context.accessToken.value)!=null?r:void 0}getDecodedAccessToken(){const e=this.getAccessToken();return e?wn(e):null}getHasuraClaims(){var e;return((e=this.getDecodedAccessToken())==null?void 0:e["https://hasura.io/jwt/claims"])||null}getHasuraClaim(e){var r;return((r=this.getHasuraClaims())==null?void 0:r[e.startsWith("x-hasura-")?e:`x-hasura-${e}`])||null}async refreshSession(e){try{const r=await this.waitUntilReady();return new Promise(n=>{const i=e||r.state.context.refreshToken.value;if(!i)return n({session:null,error:Vs});const{changed:s}=r.send("TRY_TOKEN",{token:i});if(!s)return n({session:null,error:Gs});r==null||r.onTransition(a=>{a.matches({token:{idle:"error"}})?n({session:null,error:Ks}):a.event.type==="TOKEN_CHANGED"&&n({session:se(a.context),error:null})})})}catch(r){return{session:null,error:r.message}}}getSession(){var e,r;return se((r=(e=this._client.interpreter)==null?void 0:e.state)==null?void 0:r.context)}getUser(){var e,r,n;return((n=(r=(e=this._client.interpreter)==null?void 0:e.state)==null?void 0:r.context)==null?void 0:n.user)||null}waitUntilReady(){const r=this._client.interpreter;if(!r)throw Error("Auth interpreter not set");return r.state.hasTag("loading")?new Promise((n,i)=>{let s=setTimeout(()=>i(`The state machine is not yet ready after ${15} seconds.`),15e3);r.onTransition(a=>{if(!a.hasTag("loading"))return clearTimeout(s),n(r)})}):Promise.resolve(r)}isReady(){var e,r;return!((r=(e=this._client.interpreter)==null?void 0:e.state)!=null&&r.hasTag("loading"))}get client(){return this._client}}var va=Object.defineProperty,pa=Object.defineProperties,ya=Object.getOwnPropertyDescriptors,fn=Object.getOwnPropertySymbols,ma=Object.prototype.hasOwnProperty,ga=Object.prototype.propertyIsEnumerable,dn=(t,e,r)=>e in t?va(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,qe=(t,e)=>{for(var r in e||(e={}))ma.call(e,r)&&dn(t,r,e[r]);if(fn)for(var r of fn(e))ga.call(e,r)&&dn(t,r,e[r]);return t},hn=(t,e)=>pa(t,ya(e));class Ea{constructor({url:e}){this.url=e,this.httpClient=ht.create({baseURL:this.url})}async upload(e){try{return{fileMetadata:(await this.httpClient.post("/files",e.file,{headers:hn(qe(qe({},this.generateUploadHeaders(e)),this.generateAuthHeaders()),{"Content-Type":"multipart/form-data"})})).data,error:null}}catch(r){return{fileMetadata:null,error:r}}}async getPresignedUrl(e){try{const{fileId:r}=e;return{presignedUrl:(await this.httpClient.get(`/files/${r}/presignedurl`,{headers:qe({},this.generateAuthHeaders())})).data,error:null}}catch(r){return{presignedUrl:null,error:r}}}async delete(e){try{const{fileId:r}=e;return await this.httpClient.delete(`/files/${r}`,{headers:qe({},this.generateAuthHeaders())}),{error:null}}catch(r){return{error:r}}}setAccessToken(e){return this.accessToken=e,this}setAdminSecret(e){return this.adminSecret=e,this}generateUploadHeaders(e){const{bucketId:r,name:n,id:i}=e,s={};return r&&(s["x-nhost-bucket-id"]=r),i&&(s["x-nhost-file-id"]=i),n&&(s["x-nhost-file-name"]=n),s}generateAuthHeaders(){return!this.adminSecret&&!this.accessToken?null:this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:{Authorization:`Bearer ${this.accessToken}`}}}class wa{constructor({url:e}){this.url=e,this.api=new Ea({url:e})}async upload(e){const r=new FormData;r.append("file",e.file);const{fileMetadata:n,error:i}=await this.api.upload(hn(qe({},e),{file:r}));return i?{fileMetadata:null,error:i}:n?{fileMetadata:n,error:null}:{fileMetadata:null,error:new Error("Invalid file returned")}}getUrl(e){return this.getPublicUrl(e)}getPublicUrl(e){const{fileId:r}=e;return`${this.url}/files/${r}`}async getPresignedUrl(e){const{presignedUrl:r,error:n}=await this.api.getPresignedUrl(e);return n?{presignedUrl:null,error:n}:r?{presignedUrl:r,error:null}:{presignedUrl:null,error:new Error("Invalid file id")}}async delete(e){const{error:r}=await this.api.delete(e);return r?{error:r}:{error:null}}setAccessToken(e){return this.api.setAccessToken(e),this}setAdminSecret(e){return this.api.setAdminSecret(e),this}}class vn{constructor(e){const{url:r}=e;this.accessToken=null,this.instance=ht.create({baseURL:r})}async call(e,r,n){const i=le(le({},this.generateAccessTokenHeaders()),n==null?void 0:n.headers);let s;try{s=await this.instance.post(e,r,ir(le({},n),{headers:i}))}catch(a){if(a instanceof Error)return{res:null,error:a}}return s?{res:s,error:null}:{res:null,error:new Error("Unable to make post request to funtion")}}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){if(!!this.accessToken)return{Authorization:`Bearer ${this.accessToken}`}}}class pn{constructor(e){const{url:r}=e;this.url=r,this.accessToken=null,this.instance=ht.create({baseURL:r})}async request(e,r,n){const i=le(le({},n==null?void 0:n.headers),this.generateAccessTokenHeaders());try{const s="",o=(await this.instance.post("",{operationName:s||void 0,query:typeof e=="string"?e:$.print(e),variables:r},ir(le({},n),{headers:i}))).data,{data:u}=o;return o.errors?{data:null,error:o.errors}:typeof u!="object"||Array.isArray(u)||u===null?{data:null,error:new Error("incorrect response data from GraphQL server")}:{data:u,error:null}}catch(s){return s instanceof Error?{data:null,error:s}:(console.error(s),{data:null,error:new Error("Unable to get do GraphQL request")})}}getUrl(){return this.url}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){if(!!this.accessToken)return{Authorization:`Bearer ${this.accessToken}`}}}class yn{constructor({backendUrl:e,refreshIntervalTime:r,clientStorageGetter:n,clientStorageSetter:i,clientStorage:s,clientStorageType:a,autoRefreshToken:o,autoSignIn:u,start:f=!0}){var c;if(!e)throw new Error("Please specify a `backendUrl`. Docs: [todo]!");this.auth=new ha({url:`${e}/v1/auth`,refreshIntervalTime:r,clientStorageGetter:n,clientStorageSetter:i,clientStorage:s,clientStorageType:a,autoRefreshToken:o,autoSignIn:u,start:f}),this.storage=new wa({url:`${e}/v1/storage`}),this.functions=new vn({url:`${e}/v1/functions`}),this.graphql=new pn({url:`${e}/v1/graphql`}),this.storage.setAccessToken(this.auth.getAccessToken()),this.functions.setAccessToken(this.auth.getAccessToken()),this.graphql.setAccessToken(this.auth.getAccessToken()),(c=this.auth.client)==null||c.onStart(()=>{this.auth.onAuthStateChanged((h,d)=>{h==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(h=>{this.storage.setAccessToken(h==null?void 0:h.accessToken),this.functions.setAccessToken(h==null?void 0:h.accessToken),this.graphql.setAccessToken(h==null?void 0:h.accessToken)})})}}const Sa=t=>new yn(t);U.NhostClient=yn,U.NhostFunctionsClient=vn,U.NhostGraphqlClient=pn,U.createClient=Sa,Object.defineProperties(U,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
19
+ //# sourceMappingURL=nhost-js.umd.js.map