@nhost/nhost-js 1.1.7 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clients/functions.d.ts +1 -0
- package/dist/clients/functions.d.ts.map +1 -0
- package/dist/clients/graphql.d.ts +1 -0
- package/dist/clients/graphql.d.ts.map +1 -0
- package/dist/clients/index.d.ts +1 -0
- package/dist/clients/index.d.ts.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/nhost-client.d.ts +1 -0
- package/dist/core/nhost-client.d.ts.map +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.es.js +184 -47
- package/dist/index.es.js.map +1 -7
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +25 -25
- package/umd/clients/functions.d.ts +17 -0
- package/umd/clients/functions.d.ts.map +1 -0
- package/umd/clients/graphql.d.ts +20 -0
- package/umd/clients/graphql.d.ts.map +1 -0
- package/umd/clients/index.d.ts +3 -0
- package/umd/clients/index.d.ts.map +1 -0
- package/umd/core/index.d.ts +2 -0
- package/umd/core/index.d.ts.map +1 -0
- package/umd/core/nhost-client.d.ts +26 -0
- package/umd/core/nhost-client.d.ts.map +1 -0
- package/umd/index.d.ts +6 -0
- package/umd/index.d.ts.map +1 -0
- package/umd/nhost-js.umd.js +19 -0
- package/umd/nhost-js.umd.js.map +1 -0
- package/umd/types.d.ts +20 -0
- package/umd/types.d.ts.map +1 -0
- package/src/index.ts +0 -7
package/dist/types.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "1.1.10",
|
|
4
4
|
"description": "Nhost JavaScript SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -21,51 +21,51 @@
|
|
|
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": "
|
|
32
|
-
"@nhost/hasura-storage-js": "
|
|
33
|
-
"axios": "^0.
|
|
42
|
+
"@nhost/hasura-auth-js": "1.1.5",
|
|
43
|
+
"@nhost/hasura-storage-js": "0.2.1",
|
|
44
|
+
"axios": "^0.26.0",
|
|
34
45
|
"jwt-decode": "^3.1.2",
|
|
35
46
|
"query-string": "^7.0.1"
|
|
36
47
|
},
|
|
37
48
|
"devDependencies": {
|
|
38
|
-
"@nhost/
|
|
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
|
-
"
|
|
47
|
-
"build
|
|
48
|
-
"build:
|
|
49
|
-
"
|
|
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": "pnpm jest --runInBand --config ../../config/jest.config.js",
|
|
50
61
|
"prettier": "prettier --check src/",
|
|
51
62
|
"prettier:fix": "prettier --write src/",
|
|
52
63
|
"lint": "eslint . --ext .ts,.tsx",
|
|
53
64
|
"lint:fix": "eslint . --ext .ts,.tsx --fix",
|
|
54
65
|
"verify": "run-p prettier lint",
|
|
55
66
|
"verify:fix": "run-p prettier:fix lint:fix",
|
|
56
|
-
"typedoc": "typedoc --options ./nhost-js.typedoc.json",
|
|
67
|
+
"typedoc": "typedoc --options ./nhost-js.typedoc.json --tsconfig ./typedoc.tsconfig.json",
|
|
57
68
|
"docgen": "pnpm typedoc && docgen --config ./nhost-js.docgen.json"
|
|
58
69
|
},
|
|
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
70
|
"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
71
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
call<T = unknown, D = any>(url: string, data: D, config?: AxiosRequestConfig): Promise<FunctionCallResponse<T>>;
|
|
14
|
+
setAccessToken(accessToken: string | undefined): void;
|
|
15
|
+
private generateAccessTokenHeaders;
|
|
16
|
+
}
|
|
17
|
+
//# 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;IAS7C,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,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS;IAS9C,OAAO,CAAC,0BAA0B;CAUnC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
request<T = any, V = any>(document: string | DocumentNode, variables?: V, config?: AxiosRequestConfig): Promise<GraphqlRequestResponse<T>>;
|
|
16
|
+
getUrl(): string;
|
|
17
|
+
setAccessToken(accessToken: string | undefined): void;
|
|
18
|
+
private generateAccessTokenHeaders;
|
|
19
|
+
}
|
|
20
|
+
//# 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;IAU3C,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,MAAM,IAAI,MAAM;IAIhB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS;IAS9C,OAAO,CAAC,0BAA0B;CAUnC"}
|
|
@@ -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 @@
|
|
|
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(D,$){typeof exports=="object"&&typeof module!="undefined"?$(exports,require("graphql/language/printer")):typeof define=="function"&&define.amd?define(["exports","graphql/language/printer"],$):(D=typeof globalThis!="undefined"?globalThis:D||self,$(D["@nhost/nhost-js"]={},D["graphql/language/printer"]))})(this,function(D,$){"use strict";var Zs=Object.defineProperty,ea=Object.defineProperties;var ta=Object.getOwnPropertyDescriptors;var rn=Object.getOwnPropertySymbols;var ra=Object.prototype.hasOwnProperty,na=Object.prototype.propertyIsEnumerable;var nn=(D,$,F)=>$ in D?Zs(D,$,{enumerable:!0,configurable:!0,writable:!0,value:F}):D[$]=F,ae=(D,$)=>{for(var F in $||($={}))ra.call($,F)&&nn(D,F,$[F]);if(rn)for(var F of rn($))na.call($,F)&&nn(D,F,$[F]);return D},Yt=(D,$)=>ea(D,ta($));function F(t){this.message=t}F.prototype=new Error,F.prototype.name="InvalidCharacterError";var Kt=typeof window!="undefined"&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new F("'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 sn(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(Kt(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 Kt(e)}}function Ue(t){this.message=t}function an(t,e){if(typeof t!="string")throw new Ue("Invalid token specified");var r=(e=e||{}).header===!0?0:1;try{return JSON.parse(sn(t.split(".")[r]))}catch(n){throw new Ue("Invalid token specified: "+n.message)}}Ue.prototype=new Error,Ue.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 g=function(){return g=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},g.apply(this,arguments)};function dt(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 x(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 _(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 U(t,e,r){if(r||arguments.length===2)for(var n=0,i=e.length,s;n<i;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return t.concat(s||Array.prototype.slice.call(e))}var R;(function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"})(R||(R={}));var Ee;(function(t){t.Parent="#_parent",t.Internal="#_internal"})(Ee||(Ee={}));var ht=R.Start,vt=R.Stop,De=R.Raise,je=R.Send,Xt=R.Cancel,on=R.NullEvent,pt=R.Assign;R.After,R.DoneState;var Qt=R.Log,un=R.Init,yt=R.Invoke;R.ErrorExecution;var Zt=R.ErrorPlatform,cn=R.ErrorCustom,er=R.Update,ln=R.Choose,fn=R.Pure,tr=".",rr={},gt="xstate.guard",dn="",Se=!0,$e;function mt(t,e,r){r===void 0&&(r=tr);var n=Te(t,r),i=Te(e,r);return O(i)?O(n)?i===n:!1:O(n)?n in i:Object.keys(n).every(function(s){return s in i?mt(n[s],i[s]):!1})}function nr(t){try{return O(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 wt(t,e){try{return oe(t)?t:t.toString().split(e)}catch{throw new Error("'".concat(t,"' is not a valid state path."))}}function hn(t){return typeof t=="object"&&"value"in t&&"context"in t&&"event"in t&&"_event"in t}function Te(t,e){if(hn(t))return t.value;if(oe(t))return Le(t);if(typeof t!="string")return t;var r=wt(t,e);return Le(r)}function Le(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 be(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 ir(t,e,r){var n,i,s={};try{for(var a=x(Object.keys(t)),o=a.next();!o.done;o=a.next()){var c=o.value,f=t[c];!r(f)||(s[c]=e(f,c,t))}}catch(u){n={error:u}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return s}var vn=function(t){return function(e){var r,n,i=e;try{for(var s=x(t),a=s.next();!a.done;a=s.next()){var o=a.value;i=i[o]}}catch(c){r={error:c}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}return i}};function pn(t,e){return function(r){var n,i,s=r;try{for(var a=x(t),o=a.next();!o.done;o=a.next()){var c=o.value;s=s[e][c]}}catch(f){n={error:f}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return s}}function Me(t){if(!t)return[[]];if(O(t))return[[t]];var e=k(Object.keys(t).map(function(r){var n=t[r];return typeof n!="string"&&(!n||!Object.keys(n).length)?[[r]]:Me(t[r]).map(function(i){return[r].concat(i)})}));return e}function k(t){var e;return(e=[]).concat.apply(e,U([],_(t),!1))}function sr(t){return oe(t)?t:[t]}function W(t){return t===void 0?[]:sr(t)}function qe(t,e,r){var n,i;if(N(t))return t(e,r.data);var s={};try{for(var a=x(Object.keys(t)),o=a.next();!o.done;o=a.next()){var c=o.value,f=t[c];N(f)?s[c]=f(e,r.data):s[c]=f}}catch(u){n={error:u}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return s}function yn(t){return/^(done|error)\./.test(t)}function ar(t){return!!(t instanceof Promise||t!==null&&(N(t)||typeof t=="object")&&N(t.then))}function gn(t){return t!==null&&typeof t=="object"&&"transition"in t&&typeof t.transition=="function"}function or(t,e){var r,n,i=_([[],[]],2),s=i[0],a=i[1];try{for(var o=x(t),c=o.next();!c.done;c=o.next()){var f=c.value;e(f)?s.push(f):a.push(f)}}catch(u){r={error:u}}finally{try{c&&!c.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return[s,a]}function ur(t,e){return be(t.states,function(r,n){if(!!r){var i=(O(e)?void 0:e[n])||(r?r.current:void 0);if(!!i)return{current:i,states:ur(r,i)}}})}function mn(t,e){return{current:e,states:ur(t,e)}}function cr(t,e,r,n){var i=t&&r.reduce(function(s,a){var o,c,f=a.assignment,u={state:n,action:a,_event:e},v={};if(N(f))v=f(s,e.data,u);else try{for(var d=x(Object.keys(f)),l=d.next();!l.done;l=d.next()){var h=l.value,p=f[h];v[h]=N(p)?p(s,e.data,u):p}}catch(y){o={error:y}}finally{try{l&&!l.done&&(c=d.return)&&c.call(d)}finally{if(o)throw o.error}}return Object.assign({},s,v)},t);return i}var xe=function(){};function oe(t){return Array.isArray(t)}function N(t){return typeof t=="function"}function O(t){return typeof t=="string"}function lr(t,e){if(!!t)return O(t)?{type:gt,name:t,predicate:e?e[t]:void 0}:N(t)?{type:gt,name:t.name,predicate:t}:t}function wn(t){try{return"subscribe"in t&&N(t.subscribe)}catch{return!1}}var ee=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();$e={},$e[ee]=function(){return this},$e[Symbol.observable]=function(){return this};function ie(t){return!!t&&"__xstatenode"in t}function En(t){return!!t&&typeof t.send=="function"}function Et(t,e){return O(t)||typeof t=="number"?g({type:t},e):t}function q(t,e){if(!O(t)&&"$$type"in t&&t.$$type==="scxml")return t;var r=Et(t);return g({name:r.type,data:r,$$type:"scxml",type:"external"},e)}function ue(t,e){var r=sr(e).map(function(n){return typeof n=="undefined"||typeof n=="string"||ie(n)?{target:n,event:t}:g(g({},n),{event:t})});return r}function Sn(t){if(!(t===void 0||t===dn))return W(t)}function fr(t,e,r,n,i){var s=t.options.guards,a={state:i,cond:e,_event:n};if(e.type===gt)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 dr(t){return typeof t=="string"?{type:t}:t}function St(t,e,r){if(typeof t=="object")return t;var n=function(){};return{next:t,error:e||n,complete:r||n}}function Be(t,e){return"".concat(t,":invocation[").concat(e,"]")}var Fe=q({type:un});function Tt(t,e){return e&&e[t]||void 0}function Oe(t,e){var r;if(O(t)||typeof t=="number"){var n=Tt(t,e);N(n)?r={type:t,exec:n}:n?r=n:r={type:t,exec:void 0}}else if(N(t))r={type:t.name||t.toString(),exec:t};else{var n=Tt(t.type,e);if(N(n))r=g(g({},t),{exec:n});else if(n){var i=n.type||t.type;r=g(g(g({},n),t),{type:i})}else r=t}return r}var He=function(t,e){if(!t)return[];var r=oe(t)?t:[t];return r.map(function(n){return Oe(n,e)})};function bt(t){var e=Oe(t);return g(g({id:O(t)?t:e.id},e),{type:e.type})}function Tn(t){return O(t)?{type:De,event:t}:xt(t,{to:Ee.Internal})}function bn(t){return{type:De,_event:q(t.event)}}function xt(t,e){return{to:e?e.to:void 0,type:je,event:N(t)?t:Et(t),delay:e?e.delay:void 0,id:e&&e.id!==void 0?e.id:N(t)?t.name:nr(t)}}function xn(t,e,r,n){var i={_event:r},s=q(N(t.event)?t.event(e,r.data,i):t.event),a;if(O(t.delay)){var o=n&&n[t.delay];a=N(o)?o(e,r.data,i):o}else a=N(t.delay)?t.delay(e,r.data,i):t.delay;var c=N(t.to)?t.to(e,r.data,i):t.to;return g(g({},t),{to:c,_event:s,event:s.data,delay:a})}var On=function(t,e,r){return g(g({},t),{value:O(t.expr)?t.expr:t.expr(e,r.data,{_event:r})})},_n=function(t){return{type:Xt,sendId:t}};function An(t){var e=bt(t);return{type:R.Start,activity:e,exec:void 0}}function In(t){var e=N(t)?t:bt(t);return{type:R.Stop,activity:e,exec:void 0}}function Rn(t,e,r){var n=N(t.activity)?t.activity(e,r.data):t.activity,i=typeof n=="string"?{id:n}:n,s={type:R.Stop,activity:i};return s}var Nn=function(t){return{type:pt,assignment:t}};function kn(t,e){var r=e?"#".concat(e):"";return"".concat(R.After,"(").concat(t,")").concat(r)}function Ge(t,e){var r="".concat(R.DoneState,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Ve(t,e){var r="".concat(R.DoneInvoke,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function _e(t,e){var r="".concat(R.ErrorPlatform,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Ot(t,e,r,n,i,s){s===void 0&&(s=!1);var a=_(s?[[],i]:or(i,function(d){return d.type===pt}),2),o=a[0],c=a[1],f=o.length?cr(r,n,o,e):r,u=s?[r]:void 0,v=k(c.map(function(d){var l;switch(d.type){case De:return bn(d);case je:var h=xn(d,f,n,t.options.delays);return h;case Qt:return On(d,f,n);case ln:{var p=d,y=(l=p.conds.find(function(C){var M=lr(C.cond,t.options.guards);return!M||fr(t,M,f,n,e)}))===null||l===void 0?void 0:l.actions;if(!y)return[];var E=_(Ot(t,e,f,n,He(W(y),t.options.actions),s),2),m=E[0],S=E[1];return f=S,u==null||u.push(f),m}case fn:{var y=d.get(f,n.data);if(!y)return[];var A=_(Ot(t,e,f,n,He(W(y),t.options.actions),s),2),I=A[0],j=A[1];return f=j,u==null||u.push(f),I}case vt:return Rn(d,f,n);case pt:{f=cr(f,n,[d],e),u==null||u.push(f);break}default:var T=Oe(d,t.options.actions),w=T.exec;if(w&&u){var b=u.length-1;T=g(g({},T),{exec:function(C){for(var M=[],V=1;V<arguments.length;V++)M[V-1]=arguments[V];w.apply(void 0,U([u[b]],_(M),!1))}})}return T}}).filter(function(d){return!!d}));return[v,f]}var Ae=function(t,e){var r=e(t);return r};function hr(t){var e;return e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},e[ee]=function(){return this},e}function Pn(t,e,r,n){var i,s=dr(t.src),a=(i=e==null?void 0:e.options.services)===null||i===void 0?void 0:i[s.type],o=t.data?qe(t.data,r,n):void 0,c=a?Cn(a,t.id,o):hr(t.id);return c.meta=t,c}function Cn(t,e,r){var n=hr(e);if(n.deferred=!0,ie(t)){var i=n.state=Ae(void 0,function(){return(r?t.withContext(r):t).initialState});n.getSnapshot=function(){return i}}return n}function Un(t){try{return typeof t.send=="function"}catch{return!1}}function Dn(t){return Un(t)&&"id"in t}function jn(t){var e;return g((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},e[ee]=function(){return this},e),t)}var ze=function(t){return t.type==="atomic"||t.type==="final"};function ce(t){return Object.keys(t.states).map(function(e){return t.states[e]}).filter(function(e){return e.type!=="history"})}function vr(t){var e=[t];return ze(t)?e:e.concat(k(ce(t).map(vr)))}function le(t,e){var r,n,i,s,a,o,c,f,u=new Set(t),v=_t(u),d=new Set(e);try{for(var l=x(d),h=l.next();!h.done;h=l.next())for(var p=h.value,y=p.parent;y&&!d.has(y);)d.add(y),y=y.parent}catch(b){r={error:b}}finally{try{h&&!h.done&&(n=l.return)&&n.call(l)}finally{if(r)throw r.error}}var E=_t(d);try{for(var m=x(d),S=m.next();!S.done;S=m.next()){var p=S.value;if(p.type==="compound"&&(!E.get(p)||!E.get(p).length))v.get(p)?v.get(p).forEach(function(C){return d.add(C)}):p.initialStateNodes.forEach(function(C){return d.add(C)});else if(p.type==="parallel")try{for(var A=(a=void 0,x(ce(p))),I=A.next();!I.done;I=A.next()){var j=I.value;d.has(j)||(d.add(j),v.get(j)?v.get(j).forEach(function(C){return d.add(C)}):j.initialStateNodes.forEach(function(C){return d.add(C)}))}}catch(C){a={error:C}}finally{try{I&&!I.done&&(o=A.return)&&o.call(A)}finally{if(a)throw a.error}}}}catch(b){i={error:b}}finally{try{S&&!S.done&&(s=m.return)&&s.call(m)}finally{if(i)throw i.error}}try{for(var T=x(d),w=T.next();!w.done;w=T.next())for(var p=w.value,y=p.parent;y&&!d.has(y);)d.add(y),y=y.parent}catch(b){c={error:b}}finally{try{w&&!w.done&&(f=T.return)&&f.call(T)}finally{if(c)throw c.error}}return d}function pr(t,e){var r=e.get(t);if(!r)return{};if(t.type==="compound"){var n=r[0];if(n){if(ze(n))return n.key}else return{}}var i={};return r.forEach(function(s){i[s.key]=pr(s,e)}),i}function _t(t){var e,r,n=new Map;try{for(var i=x(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 $n(t,e){var r=le([t],e);return pr(t,_t(r))}function Je(t,e){return Array.isArray(t)?t.some(function(r){return r===e}):t instanceof Set?t.has(e):!1}function Ln(t){return U([],_(new Set(k(U([],_(t.map(function(e){return e.ownEvents})),!1)))),!1)}function Ie(t,e){return e.type==="compound"?ce(e).some(function(r){return r.type==="final"&&Je(t,r)}):e.type==="parallel"?ce(e).every(function(r){return Ie(t,r)}):!1}function Mn(t){return t===void 0&&(t=[]),t.reduce(function(e,r){return r.meta!==void 0&&(e[r.id]=r.meta),e},{})}function yr(t){return new Set(k(t.map(function(e){return e.tags})))}function gr(t,e){if(t===e)return!0;if(t===void 0||e===void 0)return!1;if(O(t)||O(e))return t===e;var r=Object.keys(t),n=Object.keys(e);return r.length===n.length&&r.every(function(i){return gr(t[i],e[i])})}function qn(t){return typeof t!="object"||t===null?!1:"value"in t&&"_event"in t}function Bn(t,e){var r=t.exec,n=g(g({},t),{exec:r!==void 0?function(){return r(e.context,e.event,{action:t,state:e,_event:e._event})}:void 0});return n}var Z=function(){function t(e){var r=this,n;this.actions=[],this.activities=rr,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||rr,this.meta=Mn(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 Ln(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=Fe;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=Fe;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="."),O(e))return[e];var i=Object.keys(e);return i.concat.apply(i,U([],_(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=dt(e,["configuration","transitions","tags","machine"]);return g(g({},n),{tags:Array.from(r)})},t.prototype.matches=function(e){return mt(e,this.value)},t.prototype.hasTag=function(e){return this.tags.has(e)},t.prototype.can=function(e){var r;xe(!!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}(),Fn={deferEvents:!1},mr=function(){function t(e){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=g(g({},Fn),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}(),At=new Map,Hn=0,We={bookId:function(){return"x:".concat(Hn++)},register:function(t,e){return At.set(t,e),t},get:function(t){return At.get(t)},free:function(t){At.delete(t)}};function It(){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 Gn(){var t=It();if(t&&"__xstate__"in t)return t.__xstate__}function Vn(t){if(!!It()){var e=Gn();e&&e.register(t)}}function zn(t,e){e===void 0&&(e={});var r=t.initialState,n=new Set,i=[],s=!1,a=function(){if(!s){for(s=!0;i.length>0;){var f=i.shift();r=t.transition(r,f,c),n.forEach(function(u){return u.next(r)})}s=!1}},o=jn({id:e.id,send:function(f){i.push(f),a()},getSnapshot:function(){return r},subscribe:function(f,u,v){var d=St(f,u,v);return n.add(d),d.next(r),{unsubscribe:function(){n.delete(d)}}}}),c={parent:e.parent,self:o,id:e.id||"anonymous",observers:n};return r=t.start?t.start(c):r,o}var Jn={sync:!1,autoForward:!1},B;(function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"})(B||(B={}));var Wn=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=B.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(u,v){if(oe(u))return n.batch(u),n.state;var d=q(Et(u,v));if(n.status===B.Stopped)return n.state;if(n.status!==B.Running&&!n.options.deferEvents)throw new Error('Event "'.concat(d.name,'" was sent to uninitialized service "').concat(n.machine.id,`". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.
|
|
15
|
+
Event: `).concat(JSON.stringify(d.data)));return n.scheduler.schedule(function(){n.forward(d);var l=n.nextState(d);n.update(l,d)}),n._state},this.sendTo=function(u,v){var d=n.parent&&(v===Ee.Parent||n.parent.id===v),l=d?n.parent:O(v)?n.children.get(v)||We.get(v):En(v)?v:void 0;if(!l){if(!d)throw new Error("Unable to send event to child '".concat(v,"' from service '").concat(n.id,"'."));return}"machine"in l?l.send(g(g({},u),{name:u.name===cn?"".concat(_e(n.id)):u.name,origin:n.sessionId})):l.send(u.data)};var i=g(g({},t.defaultOptions),r),s=i.clock,a=i.logger,o=i.parent,c=i.id,f=c!==void 0?c:e.id;this.id=f,this.logger=a,this.clock=s,this.parent=o,this.options=i,this.scheduler=new mr({deferEvents:this.options.deferEvents}),this.sessionId=We.bookId()}return Object.defineProperty(t.prototype,"initialState",{get:function(){var e=this;return this._initialState?this._initialState:Ae(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=x(e.actions),a=s.next();!a.done;a=s.next()){var o=a.value;this.exec(o,e,r)}}catch(c){n={error:c}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}},t.prototype.update=function(e,r){var n,i,s,a,o,c,f,u,v=this;if(e._sessionid=this.sessionId,this._state=e,this.options.execute&&this.execute(this.state),this.children.forEach(function(b){v.state.children[b.id]=b}),this.devTools&&this.devTools.send(r.data,e),e.event)try{for(var d=x(this.eventListeners),l=d.next();!l.done;l=d.next()){var h=l.value;h(e.event)}}catch(b){n={error:b}}finally{try{l&&!l.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}try{for(var p=x(this.listeners),y=p.next();!y.done;y=p.next()){var h=y.value;h(e,e.event)}}catch(b){s={error:b}}finally{try{y&&!y.done&&(a=p.return)&&a.call(p)}finally{if(s)throw s.error}}try{for(var E=x(this.contextListeners),m=E.next();!m.done;m=E.next()){var S=m.value;S(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(b){o={error:b}}finally{try{m&&!m.done&&(c=E.return)&&c.call(E)}finally{if(o)throw o.error}}var A=Ie(e.configuration||[],this.machine);if(this.state.configuration&&A){var I=e.configuration.find(function(b){return b.type==="final"&&b.parent===v.machine}),j=I&&I.doneData?qe(I.doneData,e.context,r):void 0;try{for(var T=x(this.doneListeners),w=T.next();!w.done;w=T.next()){var h=w.value;h(Ve(this.id,j))}}catch(b){f={error:b}}finally{try{w&&!w.done&&(u=T.return)&&u.call(T)}finally{if(f)throw f.error}}this.stop()}},t.prototype.onTransition=function(e){return this.listeners.add(e),this.status===B.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!==B.NotStarted&&s(this.state),a&&(this.status===B.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===B.Running)return this;this.machine._init(),We.register(this.sessionId,this),this.initialized=!0,this.status=B.Running;var n=e===void 0?this.initialState:Ae(this,function(){return qn(e)?r.machine.resolveState(e):r.machine.resolveState(Z.from(e,r.machine.context))});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(function(){r.update(n,Fe)}),this},t.prototype.stop=function(){var e,r,n,i,s,a,o,c,f,u,v=this;try{for(var d=x(this.listeners),l=d.next();!l.done;l=d.next()){var h=l.value;this.listeners.delete(h)}}catch(w){e={error:w}}finally{try{l&&!l.done&&(r=d.return)&&r.call(d)}finally{if(e)throw e.error}}try{for(var p=x(this.stopListeners),y=p.next();!y.done;y=p.next()){var h=y.value;h(),this.stopListeners.delete(h)}}catch(w){n={error:w}}finally{try{y&&!y.done&&(i=p.return)&&i.call(p)}finally{if(n)throw n.error}}try{for(var E=x(this.contextListeners),m=E.next();!m.done;m=E.next()){var h=m.value;this.contextListeners.delete(h)}}catch(w){s={error:w}}finally{try{m&&!m.done&&(a=E.return)&&a.call(E)}finally{if(s)throw s.error}}try{for(var S=x(this.doneListeners),A=S.next();!A.done;A=S.next()){var h=A.value;this.doneListeners.delete(h)}}catch(w){o={error:w}}finally{try{A&&!A.done&&(c=S.return)&&c.call(S)}finally{if(o)throw o.error}}if(!this.initialized)return this;U([],_(this.state.configuration),!1).sort(function(w,b){return b.order-w.order}).forEach(function(w){var b,C;try{for(var M=x(w.definition.exit),V=M.next();!V.done;V=M.next()){var ne=V.value;v.exec(ne,v.state)}}catch(ft){b={error:ft}}finally{try{V&&!V.done&&(C=M.return)&&C.call(M)}finally{if(b)throw b.error}}}),this.children.forEach(function(w){N(w.stop)&&w.stop()}),this.children.clear();try{for(var I=x(Object.keys(this.delayedEventsMap)),j=I.next();!j.done;j=I.next()){var T=j.value;this.clock.clearTimeout(this.delayedEventsMap[T])}}catch(w){f={error:w}}finally{try{j&&!j.done&&(u=I.return)&&u.call(I)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.scheduler=new mr({deferEvents:this.options.deferEvents}),this.initialized=!1,this.status=B.Stopped,this._initialState=void 0,We.free(this.sessionId),this},t.prototype.batch=function(e){var r=this;if(!(this.status===B.NotStarted&&this.options.deferEvents)){if(this.status!==B.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'))}this.scheduler.schedule(function(){var n,i,s=r.state,a=!1,o=[],c=function(d){var l=q(d);r.forward(l),s=Ae(r,function(){return r.machine.transition(s,l)}),o.push.apply(o,U([],_(s.actions.map(function(h){return Bn(h,s)})),!1)),a=a||!!s.changed};try{for(var f=x(e),u=f.next();!u.done;u=f.next()){var v=u.value;c(v)}}catch(d){n={error:d}}finally{try{u&&!u.done&&(i=f.return)&&i.call(f)}finally{if(n)throw n.error}}s.changed=a,s.actions=o,r.update(s,q(e[e.length-1]))})},t.prototype.sender=function(e){return this.send.bind(this,e)},t.prototype.nextState=function(e){var r=this,n=q(e);if(n.name.indexOf(Zt)===0&&!this.state.nextEvents.some(function(s){return s.indexOf(Zt)===0}))throw n.data.data;var i=Ae(this,function(){return r.machine.transition(r.state,n)});return i},t.prototype.forward=function(e){var r,n;try{for(var i=x(this.forwardTo),s=i.next();!s.done;s=i.next()){var a=s.value,o=this.children.get(a);if(!o)throw new Error("Unable to forward event '".concat(e,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(a,"'."));o.send(e)}}catch(c){r={error:c}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}},t.prototype.defer=function(e){var r=this;this.delayedEventsMap[e.id]=this.clock.setTimeout(function(){e.to?r.sendTo(e._event,e.to):r.send(e._event)},e.delay)},t.prototype.cancel=function(e){this.clock.clearTimeout(this.delayedEventsMap[e]),delete this.delayedEventsMap[e]},t.prototype.exec=function(e,r,n){n===void 0&&(n=this.machine.options.actions);var i=r.context,s=r._event,a=e.exec||Tt(e.type,n),o=N(a)?a:a?a.exec:e.exec;if(o)try{return o(i,s.data,{action:e,state:this.state,_event:s})}catch(A){throw this.parent&&this.parent.send({type:"xstate.error",data:A}),A}switch(e.type){case je:var c=e;if(typeof c.delay=="number"){this.defer(c);return}else c.to?this.sendTo(c._event,c.to):this.send(c._event);break;case Xt:this.cancel(e.sendId);break;case ht:{if(this.status!==B.Running)return;var f=e.activity;if(!this.state.activities[f.id||f.type])break;if(f.type===R.Invoke){var u=dr(f.src),v=this.machine.options.services?this.machine.options.services[u.type]:void 0,d=f.id,l=f.data,h="autoForward"in f?f.autoForward:!!f.forward;if(!v)return;var p=l?qe(l,i,s):void 0;if(typeof v=="string")return;var y=N(v)?v(i,s.data,{data:p,src:u,meta:f.meta}):v;if(!y)return;var E=void 0;ie(y)&&(y=p?y.withContext(p):y,E={autoForward:h}),this.spawn(y,d,E)}else this.spawnActivity(f);break}case vt:{this.stopChild(e.activity.id);break}case Qt:var m=e.label,S=e.value;m?this.logger(m,S):this.logger(S);break}},t.prototype.removeChild=function(e){var r;this.children.delete(e),this.forwardTo.delete(e),(r=this.state)===null||r===void 0||delete r.children[e]},t.prototype.stopChild=function(e){var r=this.children.get(e);!r||(this.removeChild(e),N(r.stop)&&r.stop())},t.prototype.spawn=function(e,r,n){if(ar(e))return this.spawnPromise(Promise.resolve(e),r);if(N(e))return this.spawnCallback(e,r);if(Dn(e))return this.spawnActor(e,r);if(wn(e))return this.spawnObservable(e,r);if(ie(e))return this.spawnMachine(e,g(g({},n),{id:r}));if(gn(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,g(g({},this.options),{parent:this,id:r.id||e.id})),s=g(g({},Jn),r);s.sync&&i.onTransition(function(o){n.send(er,{state:o,id:i.id})});var a=i;return this.children.set(i.id,a),s.autoForward&&this.forwardTo.add(i.id),i.onDone(function(o){n.removeChild(i.id),n.send(q(o,{origin:i.id}))}).start(),a},t.prototype.spawnBehavior=function(e,r){var n=zn(e,{id:r,parent:this});return this.children.set(r,n),n},t.prototype.spawnPromise=function(e,r){var n,i=this,s=!1,a;e.then(function(c){s||(a=c,i.removeChild(r),i.send(q(Ve(r,c),{origin:r})))},function(c){if(!s){i.removeChild(r);var f=_e(r,c);try{i.send(q(f,{origin:r}))}catch{i.devTools&&i.devTools.send(f,i.state),i.machine.strict&&i.stop()}}});var o=(n={id:r,send:function(){},subscribe:function(c,f,u){var v=St(c,f,u),d=!1;return e.then(function(l){d||(v.next(l),!d&&v.complete())},function(l){d||v.error(l)}),{unsubscribe:function(){return d=!0}}},stop:function(){s=!0},toJSON:function(){return{id:r}},getSnapshot:function(){return a}},n[ee]=function(){return this},n);return this.children.set(r,o),o},t.prototype.spawnCallback=function(e,r){var n,i=this,s=!1,a=new Set,o=new Set,c,f=function(d){c=d,o.forEach(function(l){return l(d)}),!s&&i.send(q(d,{origin:r}))},u;try{u=e(f,function(d){a.add(d)})}catch(d){this.send(_e(r,d))}if(ar(u))return this.spawnPromise(u,r);var v=(n={id:r,send:function(d){return a.forEach(function(l){return l(d)})},subscribe:function(d){var l=St(d);return o.add(l.next),{unsubscribe:function(){o.delete(l.next)}}},stop:function(){s=!0,N(u)&&u()},toJSON:function(){return{id:r}},getSnapshot:function(){return c}},n[ee]=function(){return this},n);return this.children.set(r,v),v},t.prototype.spawnObservable=function(e,r){var n,i=this,s,a=e.subscribe(function(c){s=c,i.send(q(c,{origin:r}))},function(c){i.removeChild(r),i.send(q(_e(r,c),{origin:r}))},function(){i.removeChild(r),i.send(q(Ve(r),{origin:r}))}),o=(n={id:r,send:function(){},subscribe:function(c,f,u){return e.subscribe(c,f,u)},stop:function(){return a.unsubscribe()},getSnapshot:function(){return s},toJSON:function(){return{id:r}}},n[ee]=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[ee]=function(){return this},n))},t.prototype.attachDev=function(){var e=It();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(g(g({name:this.id,autoPause:!0,stateSanitizer:function(n){return{value:n.value,context:n.context,actions:n.actions}}},r),{features:g({jump:!1,skip:!1},r?r.features:void 0)}),this.machine),this.devTools.init(this.state)}Vn(this)}},t.prototype.toJSON=function(){return{id:this.id}},t.prototype[ee]=function(){return this},t.prototype.getSnapshot=function(){return this.status===B.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=fe,t}();function fe(t,e){var r=new Wn(t,e);return r}function Yn(t){if(typeof t=="string"){var e={type:t};return e.toString=function(){return t},e}return t}function Ye(t){return g(g({type:yt},t),{toJSON:function(){t.onDone,t.onError;var e=dt(t,["onDone","onError"]);return g(g({},e),{type:yt,src:Yn(t.src)})}})}var de="",Rt="#",Re="*",he={},ve=function(t){return t[0]===Rt},Kn=function(){return{actions:{},guards:{},services:{},activities:{},delays:{}}},Xn=function(t,e,r){var n=r.slice(0,-1).some(function(s){return!("cond"in s)&&!("in"in s)&&(O(s.target)||ie(s.target))}),i=e===de?"the transient event":"event '".concat(e,"'");xe(!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.")},Qn=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(Kn(),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:tr),this.id=this.config.id||U([this.machine.key],_(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?be(this.config.states,function(f,u){var v,d=new t(f,{},void 0,{parent:s,key:u});return Object.assign(s.idMap,g((v={},v[d.id]=d,v),d.idMap)),d}):he;var o=0;function c(f){var u,v;f.order=o++;try{for(var d=x(ce(f)),l=d.next();!l.done;l=d.next()){var h=l.value;c(h)}}catch(p){u={error:p}}finally{try{l&&!l.done&&(v=d.return)&&v.call(d)}finally{if(u)throw u.error}}}c(this),this.history=this.config.history===!0?"shallow":this.config.history||!1,this._transient=!!this.config.always||(this.config.on?Array.isArray(this.config.on)?this.config.on.some(function(f){var u=f.event;return u===de}):de in this.config.on:!1),this.strict=!!this.config.strict,this.onEntry=W(this.config.entry||this.config.onEntry).map(function(f){return Oe(f)}),this.onExit=W(this.config.exit||this.config.onExit).map(function(f){return Oe(f)}),this.meta=this.config.meta,this.doneData=this.type==="final"?this.config.data:void 0,this.invoke=W(this.config.invoke).map(function(f,u){var v,d;if(ie(f)){var l=Be(s.id,u);return s.machine.options.services=g((v={},v[l]=f,v),s.machine.options.services),Ye({src:l,id:l})}else if(O(f.src)){var l=f.id||Be(s.id,u);return Ye(g(g({},f),{id:l,src:f.src}))}else if(ie(f.src)||N(f.src)){var l=f.id||Be(s.id,u);return s.machine.options.services=g((d={},d[l]=f.src,d),s.machine.options.services),Ye(g(g({id:l},f),{src:l}))}else{var h=f.src;return Ye(g(g({id:Be(s.id,u)},f),{src:h}))}}),this.activities=W(this.config.activities).concat(this.invoke).map(function(f){return bt(f)}),this.transition=this.transition.bind(this),this.tags=W(this.config.tags)}return t.prototype._init=function(){this.__cache.transitions||vr(this).forEach(function(e){return e.on})},t.prototype.withConfig=function(e,r){var n=this.options,i=n.actions,s=n.activities,a=n.guards,o=n.services,c=n.delays;return new t(this.config,{actions:g(g({},i),e.actions),activities:g(g({},s),e.activities),guards:g(g({},a),e.guards),services:g(g({},o),e.services),delays:g(g({},c),e.delays)},r!=null?r:this.context)},t.prototype.withContext=function(e){return new t(this.config,this.options,e)},Object.defineProperty(t.prototype,"context",{get:function(){return N(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:be(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===de,n=this.transitions.filter(function(i){var s=i.eventType===e;return r?s:s||i.eventType===Re});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=N(s)?"".concat(e.id,":delay[").concat(a,"]"):s,c=kn(o,e.id);return e.onEntry.push(xt(c,{delay:s})),e.onExit.push(_n(c)),c},i=oe(r)?r.map(function(s,a){var o=n(s.delay,a);return g(g({},s),{event:o})}):k(Object.keys(r).map(function(s,a){var o=r[s],c=O(o)?{target:o}:o,f=isNaN(+s)?s:+s,u=n(f,a);return W(c).map(function(v){return g(g({},v),{event:u,delay:f})})}));return i.map(function(s){var a=s.delay;return g(g({},e.formatTransition(s)),{delay:a})})},t.prototype.getStateNodes=function(e){var r,n=this;if(!e)return[];var i=e instanceof Z?e.value:Te(e,this.delimiter);if(O(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,U([],_(k(a.map(function(c){return n.getStateNode(c).getStateNodes(i[c])}))),!1)),o},t.prototype.handles=function(e){var r=nr(e);return this.events.includes(r)},t.prototype.resolveState=function(e){var r=e instanceof Z?e:Z.create(e),n=Array.from(le([],this.getStateNodes(r.value)));return new Z(g(g({},r),{value:this.resolve(r.value),configuration:n,done:Ie(n,this),tags:yr(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=x(Object.keys(e)),c=o.next();!c.done;c=o.next()){var f=c.value,u=e[f];if(!!u){var v=this.getStateNode(f),d=v._transition(u,r,n);d&&(a[f]=d)}}}catch(m){i={error:m}}finally{try{c&&!c.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}var l=Object.keys(a).map(function(m){return a[m]}),h=k(l.map(function(m){return m.transitions})),p=l.some(function(m){return m.transitions.length>0});if(!p)return this.next(r,n);var y=k(l.map(function(m){return m.entrySet})),E=k(Object.keys(a).map(function(m){return a[m].configuration}));return{transitions:h,entrySet:y,exitSet:k(l.map(function(m){return m.exitSet})),configuration:E,source:r,actions:k(Object.keys(a).map(function(m){return a[m].actions}))}},t.prototype._transition=function(e,r,n){return O(e)?this.transitionLeafNode(e,r,n):Object.keys(e).length===1?this.transitionCompoundNode(e,r,n):this.transitionParallelNode(e,r,n)},t.prototype.getTransitionData=function(e,r){return this._transition(e.value,e,q(r))},t.prototype.next=function(e,r){var n,i,s=this,a=r.name,o=[],c=[],f;try{for(var u=x(this.getCandidates(a)),v=u.next();!v.done;v=u.next()){var d=v.value,l=d.cond,h=d.in,p=e.context,y=h?O(h)&&ve(h)?e.matches(Te(this.getStateNodeById(h).path,this.delimiter)):mt(Te(h,this.delimiter),vn(this.path.slice(0,-2))(e.value)):!0,E=!1;try{E=!l||fr(this.machine,l,p,r,e)}catch(I){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(I.message))}if(E&&y){d.target!==void 0&&(c=d.target),o.push.apply(o,U([],_(d.actions),!1)),f=d;break}}}catch(I){n={error:I}}finally{try{v&&!v.done&&(i=u.return)&&i.call(u)}finally{if(n)throw n.error}}if(!!f){if(!c.length)return{transitions:[f],entrySet:[],exitSet:[],configuration:e.value?[this]:[],source:e,actions:o};var m=k(c.map(function(I){return s.getRelativeStateNodes(I,e.historyValue)})),S=!!f.internal,A=S?[]:k(m.map(function(I){return s.nodesFromChild(I)}));return{transitions:[f],entrySet:A,exitSet:S?[]:[this],configuration:m,source:e,actions:o}}},t.prototype.nodesFromChild=function(e){if(e.escapes(this))return[];for(var r=[],n=e;n&&n!==this;)r.push(n),n=n.parent;return r.push(this),r},t.prototype.escapes=function(e){if(this===e)return!1;for(var r=this.parent;r;){if(r===e)return!1;r=r.parent}return!0},t.prototype.getActions=function(e,r,n,i){var s,a,o,c,f=le([],i?this.getStateNodes(i.value):[this]),u=e.configuration.length?le(f,e.configuration):f;try{for(var v=x(u),d=v.next();!d.done;d=v.next()){var l=d.value;Je(f,l)||e.entrySet.push(l)}}catch(T){s={error:T}}finally{try{d&&!d.done&&(a=v.return)&&a.call(v)}finally{if(s)throw s.error}}try{for(var h=x(f),p=h.next();!p.done;p=h.next()){var l=p.value;(!Je(u,l)||Je(e.exitSet,l.parent))&&e.exitSet.push(l)}}catch(T){o={error:T}}finally{try{p&&!p.done&&(c=h.return)&&c.call(h)}finally{if(o)throw o.error}}var y=k(e.entrySet.map(function(T){var w=[];if(T.type!=="final")return w;var b=T.parent;if(!b.parent)return w;w.push(Ge(T.id,T.doneData),Ge(b.id,T.doneData?qe(T.doneData,r,n):void 0));var C=b.parent;return C.type==="parallel"&&ce(C).every(function(M){return Ie(e.configuration,M)})&&w.push(Ge(C.id)),w}));e.exitSet.sort(function(T,w){return w.order-T.order}),e.entrySet.sort(function(T,w){return T.order-w.order});var E=new Set(e.entrySet),m=new Set(e.exitSet),S=_([k(Array.from(E).map(function(T){return U(U([],_(T.activities.map(function(w){return An(w)})),!1),_(T.onEntry),!1)})).concat(y.map(Tn)),k(Array.from(m).map(function(T){return U(U([],_(T.onExit),!1),_(T.activities.map(function(w){return In(w)})),!1)}))],2),A=S[0],I=S[1],j=He(I.concat(e.actions).concat(A),this.machine.options.actions);return j},t.prototype.transition=function(e,r,n){e===void 0&&(e=this.initialState);var i=q(r),s;if(e instanceof Z)s=n===void 0?e:this.resolveState(Z.from(e,n));else{var a=O(e)?this.resolve(Le(this.getResolvedPath(e))):this.resolve(e),o=n!=null?n:this.machine.context;s=this.resolveState(Z.from(a,o))}if(!Se&&i.name===Re)throw new Error("An event cannot have the wildcard type ('".concat(Re,"')"));if(this.strict&&!this.events.includes(i.name)&&!yn(i.name))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(i.name,"'"));var c=this._transition(s.value,s,i)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:s,actions:[]},f=le([],this.getStateNodes(s.value)),u=c.configuration.length?le(f,c.configuration):f;return c.configuration=U([],_(u),!1),this.resolveTransition(c,s,s.context,i)},t.prototype.resolveRaisedTransition=function(e,r,n){var i,s=e.actions;return e=this.transition(e,r),e._event=n,e.event=n.data,(i=e.actions).unshift.apply(i,U([],_(s),!1)),e},t.prototype.resolveTransition=function(e,r,n,i){var s,a,o=this;i===void 0&&(i=Fe);var c=e.configuration,f=!r||e.transitions.length>0,u=f?$n(this.machine,c):void 0,v=r?r.historyValue?r.historyValue:e.source?this.machine.historyValue(r.value):void 0:void 0,d=this.getActions(e,n,i,r),l=r?g({},r.activities):{};try{for(var h=x(d),p=h.next();!p.done;p=h.next()){var y=p.value;y.type===ht?l[y.activity.id||y.activity.type]=y:y.type===vt&&(l[y.activity.id||y.activity.type]=!1)}}catch(z){s={error:z}}finally{try{p&&!p.done&&(a=h.return)&&a.call(h)}finally{if(s)throw s.error}}var E=_(Ot(this,r,n,i,d,this.machine.config.preserveActionOrder),2),m=E[0],S=E[1],A=_(or(m,function(z){return z.type===De||z.type===je&&z.to===Ee.Internal}),2),I=A[0],j=A[1],T=m.filter(function(z){var we;return z.type===ht&&((we=z.activity)===null||we===void 0?void 0:we.type)===yt}),w=T.reduce(function(z,we){return z[we.activity.id]=Pn(we.activity,o.machine,S,i),z},r?g({},r.children):{}),b=f?e.configuration:r?r.configuration:[],C=Ie(b,this),M=new Z({value:u||r.value,context:S,_event:i,_sessionid:r?r._sessionid:null,historyValue:u?v?mn(v,u):void 0:r?r.historyValue:void 0,history:!u||e.source?r:void 0,actions:u?j:[],activities:u?l:r?r.activities:{},events:[],configuration:b,transitions:e.transitions,children:w,done:C,tags:yr(b),machine:this}),V=n!==S;M.changed=i.name===er||V;var ne=M.history;ne&&delete ne.history;var ft=!C&&(this._transient||c.some(function(z){return z._transient}));if(!f&&(!ft||i.name===de))return M;var X=M;if(!C)for(ft&&(X=this.resolveRaisedTransition(X,{type:on},i));I.length;){var Xs=I.shift();X=this.resolveRaisedTransition(X,Xs._event,i)}var Qs=X.changed||(ne?!!X.actions.length||V||typeof ne.value!=typeof X.value||!gr(X.value,ne.value):void 0);return X.changed=Qs,X.history=ne,X},t.prototype.getStateNode=function(e){if(ve(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=ve(e)?e.slice(Rt.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"&&ve(e))try{return this.getStateNodeById(e.slice(1))}catch{}for(var r=wt(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||he;switch(this.type){case"parallel":return be(this.initialStateValue,function(s,a){return s?n.getStateNode(a).resolve(e[a]||s):he});case"compound":if(O(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?be(e,function(s,a){return s?n.getStateNode(a).resolve(s):he}):this.initialStateValue||{};default:return e||he}},t.prototype.getResolvedPath=function(e){if(ve(e)){var r=this.machine.idMap[e.slice(Rt.length)];if(!r)throw new Error("Unable to find state node '".concat(e,"'"));return r.path}return wt(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=ir(this.states,function(n){return n.initialStateValue||he},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=ze(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;O(r.target)?e=ve(r.target)?Le(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(ze(this))return[this];if(this.type==="compound"&&!this.initial)return Se||xe(!1,"Compound state node '".concat(this.id,"' has no initial state.")),[this];var r=Me(this.initialStateValue);return k(r.map(function(n){return e.getFromRelativePath(n)}))},enumerable:!1,configurable:!0}),t.prototype.getFromRelativePath=function(e){if(!e.length)return[this];var 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:ir(this.states,function(r,n){if(!e)return r.historyValue();var i=O(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?k(Me(i).map(function(a){return n.getFromRelativePath(a)})):n.initialStateNodes}var s=pn(n.path,"states")(e).current;return O(s)?[n.getStateNode(s)]:k(Me(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=k(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=x(Object.keys(s)),c=o.next();!c.done;c=o.next()){var f=c.value,u=s[f];if(u.states)try{for(var v=(n=void 0,x(u.events)),d=v.next();!d.done;d=v.next()){var l=d.value;a.add("".concat(l))}}catch(h){n={error:h}}finally{try{d&&!d.done&&(i=v.return)&&i.call(v)}finally{if(n)throw n.error}}}}catch(h){e={error:h}}finally{try{c&&!c.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return this.__cache.events=Array.from(a)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ownEvents",{get:function(){var e=new Set(this.transitions.filter(function(r){return!(!r.target&&!r.actions.length&&r.internal)}).map(function(r){return r.eventType}));return Array.from(e)},enumerable:!1,configurable:!0}),t.prototype.resolveTarget=function(e){var r=this;if(e!==void 0)return e.map(function(n){if(!O(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=Sn(e.target),i="internal"in e?e.internal:n?n.some(function(c){return O(c)&&c[0]===r.delimiter}):!0,s=this.machine.options.guards,a=this.resolveTarget(n),o=g(g({},e),{actions:He(W(e.actions)),cond:lr(e.cond,s),target:a,source:this,internal:i,eventType:e.event,toJSON:function(){return g(g({},o),{target:o.target?o.target.map(function(c){return"#".concat(c.id)}):void 0,source:"#".concat(r.id)})}});return o},t.prototype.formatTransitions=function(){var e,r,n=this,i;if(!this.config.on)i=[];else if(Array.isArray(this.config.on))i=this.config.on;else{var s=this.config.on,a=Re,o=s[a],c=o===void 0?[]:o,f=dt(s,[typeof a=="symbol"?a:a+""]);i=k(Object.keys(f).map(function(m){!Se&&m===de&&xe(!1,"Empty string transition configs (e.g., `{ on: { '': ... }}`) for transient transitions are deprecated. Specify the transition in the `{ always: ... }` property instead. "+'Please check the `on` configuration for "#'.concat(n.id,'".'));var S=ue(m,f[m]);return Se||Xn(n,m,S),S}).concat(ue(Re,c)))}var u=this.config.always?ue("",this.config.always):[],v=this.config.onDone?ue(String(Ge(this.id)),this.config.onDone):[];Se||xe(!(this.config.onDone&&!this.parent),'Root nodes cannot have an ".onDone" transition. Please check the config of "'.concat(this.id,'".'));var d=k(this.invoke.map(function(m){var S=[];return m.onDone&&S.push.apply(S,U([],_(ue(String(Ve(m.id)),m.onDone)),!1)),m.onError&&S.push.apply(S,U([],_(ue(String(_e(m.id)),m.onError)),!1)),S})),l=this.after,h=k(U(U(U(U([],_(v),!1),_(d),!1),_(i),!1),_(u),!1).map(function(m){return W(m).map(function(S){return n.formatTransition(S)})}));try{for(var p=x(l),y=p.next();!y.done;y=p.next()){var E=y.value;h.push(E)}}catch(m){e={error:m}}finally{try{y&&!y.done&&(r=p.return)&&r.call(p)}finally{if(e)throw e.error}}return h},t}();function Ne(t,e){return new Qn(t,e)}var P=Nn,J=xt,Nt={exports:{}},wr=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)}},Zn=wr,te=Object.prototype.toString;function kt(t){return Array.isArray(t)}function Pt(t){return typeof t=="undefined"}function ei(t){return t!==null&&!Pt(t)&&t.constructor!==null&&!Pt(t.constructor)&&typeof t.constructor.isBuffer=="function"&&t.constructor.isBuffer(t)}function Er(t){return te.call(t)==="[object ArrayBuffer]"}function ti(t){return te.call(t)==="[object FormData]"}function ri(t){var e;return typeof ArrayBuffer!="undefined"&&ArrayBuffer.isView?e=ArrayBuffer.isView(t):e=t&&t.buffer&&Er(t.buffer),e}function ni(t){return typeof t=="string"}function ii(t){return typeof t=="number"}function Sr(t){return t!==null&&typeof t=="object"}function Ke(t){if(te.call(t)!=="[object Object]")return!1;var e=Object.getPrototypeOf(t);return e===null||e===Object.prototype}function si(t){return te.call(t)==="[object Date]"}function ai(t){return te.call(t)==="[object File]"}function oi(t){return te.call(t)==="[object Blob]"}function Tr(t){return te.call(t)==="[object Function]"}function ui(t){return Sr(t)&&Tr(t.pipe)}function ci(t){return te.call(t)==="[object URLSearchParams]"}function li(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function fi(){return typeof navigator!="undefined"&&(navigator.product==="ReactNative"||navigator.product==="NativeScript"||navigator.product==="NS")?!1:typeof window!="undefined"&&typeof document!="undefined"}function Ct(t,e){if(!(t===null||typeof t=="undefined"))if(typeof t!="object"&&(t=[t]),kt(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 Ut(){var t={};function e(i,s){Ke(t[s])&&Ke(i)?t[s]=Ut(t[s],i):Ke(i)?t[s]=Ut({},i):kt(i)?t[s]=i.slice():t[s]=i}for(var r=0,n=arguments.length;r<n;r++)Ct(arguments[r],e);return t}function di(t,e,r){return Ct(e,function(i,s){r&&typeof i=="function"?t[s]=Zn(i,r):t[s]=i}),t}function hi(t){return t.charCodeAt(0)===65279&&(t=t.slice(1)),t}var H={isArray:kt,isArrayBuffer:Er,isBuffer:ei,isFormData:ti,isArrayBufferView:ri,isString:ni,isNumber:ii,isObject:Sr,isPlainObject:Ke,isUndefined:Pt,isDate:si,isFile:ai,isBlob:oi,isFunction:Tr,isStream:ui,isURLSearchParams:ci,isStandardBrowserEnv:fi,forEach:Ct,merge:Ut,extend:di,trim:li,stripBOM:hi},pe=H;function br(t){return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var xr=function(e,r,n){if(!r)return e;var i;if(n)i=n(r);else if(pe.isURLSearchParams(r))i=r.toString();else{var s=[];pe.forEach(r,function(c,f){c===null||typeof c=="undefined"||(pe.isArray(c)?f=f+"[]":c=[c],pe.forEach(c,function(v){pe.isDate(v)?v=v.toISOString():pe.isObject(v)&&(v=JSON.stringify(v)),s.push(br(f)+"="+br(v))}))}),i=s.join("&")}if(i){var a=e.indexOf("#");a!==-1&&(e=e.slice(0,a)),e+=(e.indexOf("?")===-1?"?":"&")+i}return e},vi=H;function Xe(){this.handlers=[]}Xe.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},Xe.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},Xe.prototype.forEach=function(e){vi.forEach(this.handlers,function(n){n!==null&&e(n)})};var pi=Xe,yi=H,gi=function(e,r){yi.forEach(e,function(i,s){s!==r&&s.toUpperCase()===r.toUpperCase()&&(e[r]=i,delete e[s])})},Or=function(e,r,n,i,s){return e.config=r,n&&(e.code=n),e.request=i,e.response=s,e.isAxiosError=!0,e.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}},e},_r={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},mi=Or,Ar=function(e,r,n,i,s){var a=new Error(e);return mi(a,r,n,i,s)},wi=Ar,Ei=function(e,r,n){var i=n.config.validateStatus;!n.status||!i||i(n.status)?e(n):r(wi("Request failed with status code "+n.status,n.config,null,n.request,n))},Qe=H,Si=Qe.isStandardBrowserEnv()?function(){return{write:function(r,n,i,s,a,o){var c=[];c.push(r+"="+encodeURIComponent(n)),Qe.isNumber(i)&&c.push("expires="+new Date(i).toGMTString()),Qe.isString(s)&&c.push("path="+s),Qe.isString(a)&&c.push("domain="+a),o===!0&&c.push("secure"),document.cookie=c.join("; ")},read:function(r){var n=document.cookie.match(new RegExp("(^|;\\s*)("+r+")=([^;]*)"));return n?decodeURIComponent(n[3]):null},remove:function(r){this.write(r,"",Date.now()-864e5)}}}():function(){return{write:function(){},read:function(){return null},remove:function(){}}}(),Ti=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},bi=function(e,r){return r?e.replace(/\/+$/,"")+"/"+r.replace(/^\/+/,""):e},xi=Ti,Oi=bi,_i=function(e,r){return e&&!xi(r)?Oi(e,r):r},Dt=H,Ai=["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"],Ii=function(e){var r={},n,i,s;return e&&Dt.forEach(e.split(`
|
|
18
|
+
`),function(o){if(s=o.indexOf(":"),n=Dt.trim(o.substr(0,s)).toLowerCase(),i=Dt.trim(o.substr(s+1)),n){if(r[n]&&Ai.indexOf(n)>=0)return;n==="set-cookie"?r[n]=(r[n]?r[n]:[]).concat([i]):r[n]=r[n]?r[n]+", "+i:i}}),r},Ir=H,Ri=Ir.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=Ir.isString(a)?i(a):a;return o.protocol===n.protocol&&o.host===n.host}}():function(){return function(){return!0}}();function jt(t){this.message=t}jt.prototype.toString=function(){return"Cancel"+(this.message?": "+this.message:"")},jt.prototype.__CANCEL__=!0;var Ze=jt,et=H,Ni=Ei,ki=Si,Pi=xr,Ci=_i,Ui=Ii,Di=Ri,$t=Ar,ji=_r,$i=Ze,Rr=function(e){return new Promise(function(n,i){var s=e.data,a=e.headers,o=e.responseType,c;function f(){e.cancelToken&&e.cancelToken.unsubscribe(c),e.signal&&e.signal.removeEventListener("abort",c)}et.isFormData(s)&&delete a["Content-Type"];var u=new XMLHttpRequest;if(e.auth){var v=e.auth.username||"",d=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";a.Authorization="Basic "+btoa(v+":"+d)}var l=Ci(e.baseURL,e.url);u.open(e.method.toUpperCase(),Pi(l,e.params,e.paramsSerializer),!0),u.timeout=e.timeout;function h(){if(!!u){var y="getAllResponseHeaders"in u?Ui(u.getAllResponseHeaders()):null,E=!o||o==="text"||o==="json"?u.responseText:u.response,m={data:E,status:u.status,statusText:u.statusText,headers:y,config:e,request:u};Ni(function(A){n(A),f()},function(A){i(A),f()},m),u=null}}if("onloadend"in u?u.onloadend=h:u.onreadystatechange=function(){!u||u.readyState!==4||u.status===0&&!(u.responseURL&&u.responseURL.indexOf("file:")===0)||setTimeout(h)},u.onabort=function(){!u||(i($t("Request aborted",e,"ECONNABORTED",u)),u=null)},u.onerror=function(){i($t("Network Error",e,null,u)),u=null},u.ontimeout=function(){var E=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded",m=e.transitional||ji;e.timeoutErrorMessage&&(E=e.timeoutErrorMessage),i($t(E,e,m.clarifyTimeoutError?"ETIMEDOUT":"ECONNABORTED",u)),u=null},et.isStandardBrowserEnv()){var p=(e.withCredentials||Di(l))&&e.xsrfCookieName?ki.read(e.xsrfCookieName):void 0;p&&(a[e.xsrfHeaderName]=p)}"setRequestHeader"in u&&et.forEach(a,function(E,m){typeof s=="undefined"&&m.toLowerCase()==="content-type"?delete a[m]:u.setRequestHeader(m,E)}),et.isUndefined(e.withCredentials)||(u.withCredentials=!!e.withCredentials),o&&o!=="json"&&(u.responseType=e.responseType),typeof e.onDownloadProgress=="function"&&u.addEventListener("progress",e.onDownloadProgress),typeof e.onUploadProgress=="function"&&u.upload&&u.upload.addEventListener("progress",e.onUploadProgress),(e.cancelToken||e.signal)&&(c=function(y){!u||(i(!y||y&&y.type?new $i("canceled"):y),u.abort(),u=null)},e.cancelToken&&e.cancelToken.subscribe(c),e.signal&&(e.signal.aborted?c():e.signal.addEventListener("abort",c))),s||(s=null),u.send(s)})},L=H,Nr=gi,Li=Or,Mi=_r,qi={"Content-Type":"application/x-www-form-urlencoded"};function kr(t,e){!L.isUndefined(t)&&L.isUndefined(t["Content-Type"])&&(t["Content-Type"]=e)}function Bi(){var t;return(typeof XMLHttpRequest!="undefined"||typeof process!="undefined"&&Object.prototype.toString.call(process)==="[object process]")&&(t=Rr),t}function Fi(t,e,r){if(L.isString(t))try{return(e||JSON.parse)(t),L.trim(t)}catch(n){if(n.name!=="SyntaxError")throw n}return(r||JSON.stringify)(t)}var tt={transitional:Mi,adapter:Bi(),transformRequest:[function(e,r){return Nr(r,"Accept"),Nr(r,"Content-Type"),L.isFormData(e)||L.isArrayBuffer(e)||L.isBuffer(e)||L.isStream(e)||L.isFile(e)||L.isBlob(e)?e:L.isArrayBufferView(e)?e.buffer:L.isURLSearchParams(e)?(kr(r,"application/x-www-form-urlencoded;charset=utf-8"),e.toString()):L.isObject(e)||r&&r["Content-Type"]==="application/json"?(kr(r,"application/json"),Fi(e)):e}],transformResponse:[function(e){var r=this.transitional||tt.transitional,n=r&&r.silentJSONParsing,i=r&&r.forcedJSONParsing,s=!n&&this.responseType==="json";if(s||i&&L.isString(e)&&e.length)try{return JSON.parse(e)}catch(a){if(s)throw a.name==="SyntaxError"?Li(a,this,"E_JSON_PARSE"):a}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};L.forEach(["delete","get","head"],function(e){tt.headers[e]={}}),L.forEach(["post","put","patch"],function(e){tt.headers[e]=L.merge(qi)});var Lt=tt,Hi=H,Gi=Lt,Vi=function(e,r,n){var i=this||Gi;return Hi.forEach(n,function(a){e=a.call(i,e,r)}),e},Pr=function(e){return!!(e&&e.__CANCEL__)},Cr=H,Mt=Vi,zi=Pr,Ji=Lt,Wi=Ze;function qt(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new Wi("canceled")}var Yi=function(e){qt(e),e.headers=e.headers||{},e.data=Mt.call(e,e.data,e.headers,e.transformRequest),e.headers=Cr.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),Cr.forEach(["delete","get","head","post","put","patch","common"],function(i){delete e.headers[i]});var r=e.adapter||Ji.adapter;return r(e).then(function(i){return qt(e),i.data=Mt.call(e,i.data,i.headers,e.transformResponse),i},function(i){return zi(i)||(qt(e),i&&i.response&&(i.response.data=Mt.call(e,i.response.data,i.response.headers,e.transformResponse))),Promise.reject(i)})},G=H,Ur=function(e,r){r=r||{};var n={};function i(u,v){return G.isPlainObject(u)&&G.isPlainObject(v)?G.merge(u,v):G.isPlainObject(v)?G.merge({},v):G.isArray(v)?v.slice():v}function s(u){if(G.isUndefined(r[u])){if(!G.isUndefined(e[u]))return i(void 0,e[u])}else return i(e[u],r[u])}function a(u){if(!G.isUndefined(r[u]))return i(void 0,r[u])}function o(u){if(G.isUndefined(r[u])){if(!G.isUndefined(e[u]))return i(void 0,e[u])}else return i(void 0,r[u])}function c(u){if(u in r)return i(e[u],r[u]);if(u in e)return i(void 0,e[u])}var f={url:a,method:a,data:a,baseURL:o,transformRequest:o,transformResponse:o,paramsSerializer:o,timeout:o,timeoutMessage:o,withCredentials:o,adapter:o,responseType:o,xsrfCookieName:o,xsrfHeaderName:o,onUploadProgress:o,onDownloadProgress:o,decompress:o,maxContentLength:o,maxBodyLength:o,transport:o,httpAgent:o,httpsAgent:o,cancelToken:o,socketPath:o,responseEncoding:o,validateStatus:c};return G.forEach(Object.keys(e).concat(Object.keys(r)),function(v){var d=f[v]||s,l=d(v);G.isUndefined(l)&&d!==c||(n[v]=l)}),n},Dr={version:"0.26.1"},Ki=Dr.version,Bt={};["object","boolean","number","function","string","symbol"].forEach(function(t,e){Bt[t]=function(n){return typeof n===t||"a"+(e<1?"n ":" ")+t}});var jr={};Bt.transitional=function(e,r,n){function i(s,a){return"[Axios v"+Ki+"] Transitional option '"+s+"'"+a+(n?". "+n:"")}return function(s,a,o){if(e===!1)throw new Error(i(a," has been removed"+(r?" in "+r:"")));return r&&!jr[a]&&(jr[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 Xi(t,e,r){if(typeof t!="object")throw new TypeError("options must be an object");for(var n=Object.keys(t),i=n.length;i-- >0;){var s=n[i],a=e[s];if(a){var o=t[s],c=o===void 0||a(o,s,t);if(c!==!0)throw new TypeError("option "+s+" must be "+c);continue}if(r!==!0)throw Error("Unknown option "+s)}}var Qi={assertOptions:Xi,validators:Bt},$r=H,Zi=xr,Lr=pi,Mr=Yi,rt=Ur,qr=Qi,ye=qr.validators;function ke(t){this.defaults=t,this.interceptors={request:new Lr,response:new Lr}}ke.prototype.request=function(e,r){typeof e=="string"?(r=r||{},r.url=e):r=e||{},r=rt(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&&qr.assertOptions(n,{silentJSONParsing:ye.transitional(ye.boolean),forcedJSONParsing:ye.transitional(ye.boolean),clarifyTimeoutError:ye.transitional(ye.boolean)},!1);var i=[],s=!0;this.interceptors.request.forEach(function(l){typeof l.runWhen=="function"&&l.runWhen(r)===!1||(s=s&&l.synchronous,i.unshift(l.fulfilled,l.rejected))});var a=[];this.interceptors.response.forEach(function(l){a.push(l.fulfilled,l.rejected)});var o;if(!s){var c=[Mr,void 0];for(Array.prototype.unshift.apply(c,i),c=c.concat(a),o=Promise.resolve(r);c.length;)o=o.then(c.shift(),c.shift());return o}for(var f=r;i.length;){var u=i.shift(),v=i.shift();try{f=u(f)}catch(d){v(d);break}}try{o=Mr(f)}catch(d){return Promise.reject(d)}for(;a.length;)o=o.then(a.shift(),a.shift());return o},ke.prototype.getUri=function(e){return e=rt(this.defaults,e),Zi(e.url,e.params,e.paramsSerializer).replace(/^\?/,"")},$r.forEach(["delete","get","head","options"],function(e){ke.prototype[e]=function(r,n){return this.request(rt(n||{},{method:e,url:r,data:(n||{}).data}))}}),$r.forEach(["post","put","patch"],function(e){ke.prototype[e]=function(r,n,i){return this.request(rt(i||{},{method:e,url:r,data:n}))}});var es=ke,ts=Ze;function ge(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 ts(i),e(r.reason))})}ge.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},ge.prototype.subscribe=function(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]},ge.prototype.unsubscribe=function(e){if(!!this._listeners){var r=this._listeners.indexOf(e);r!==-1&&this._listeners.splice(r,1)}},ge.source=function(){var e,r=new ge(function(i){e=i});return{token:r,cancel:e}};var rs=ge,ns=function(e){return function(n){return e.apply(null,n)}},is=H,ss=function(e){return is.isObject(e)&&e.isAxiosError===!0},Br=H,as=wr,nt=es,os=Ur,us=Lt;function Fr(t){var e=new nt(t),r=as(nt.prototype.request,e);return Br.extend(r,nt.prototype,e),Br.extend(r,e),r.create=function(i){return Fr(os(t,i))},r}var Q=Fr(us);Q.Axios=nt,Q.Cancel=Ze,Q.CancelToken=rs,Q.isCancel=Pr,Q.VERSION=Dr.version,Q.all=function(e){return Promise.all(e)},Q.spread=ns,Q.isAxiosError=ss,Nt.exports=Q,Nt.exports.default=Q;var it=Nt.exports;/*! js-cookie v3.0.1 | MIT */function st(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 cs={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 Ft(t,e){function r(i,s,a){if(typeof document!="undefined"){a=st({},e,a),typeof a.expires=="number"&&(a.expires=new Date(Date.now()+a.expires*864e5)),a.expires&&(a.expires=a.expires.toUTCString()),i=encodeURIComponent(i).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var o="";for(var c in a)!a[c]||(o+="; "+c,a[c]!==!0&&(o+="="+a[c].split(";")[0]));return document.cookie=i+"="+t.write(s,i)+o}}function n(i){if(!(typeof document=="undefined"||arguments.length&&!i)){for(var s=document.cookie?document.cookie.split("; "):[],a={},o=0;o<s.length;o++){var c=s[o].split("="),f=c.slice(1).join("=");try{var u=decodeURIComponent(c[0]);if(a[u]=t.read(f,u),i===u)break}catch{}}return i?a[i]:a}}return Object.create({set:r,get:n,remove:function(i,s){r(i,"",st({},s,{expires:-1}))},withAttributes:function(i){return Ft(this.converter,st({},this.attributes,i))},withConverter:function(i){return Ft(st({},this.converter,i),this.attributes)}},{attributes:{value:Object.freeze(e)},converter:{value:Object.freeze(t)}})}var Ht=Ft(cs,{path:"/"}),ls=Object.defineProperty,fs=Object.defineProperties,ds=Object.getOwnPropertyDescriptors,at=Object.getOwnPropertySymbols,Hr=Object.prototype.hasOwnProperty,Gr=Object.prototype.propertyIsEnumerable,Vr=(t,e,r)=>e in t?ls(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Y=(t,e)=>{for(var r in e||(e={}))Hr.call(e,r)&&Vr(t,r,e[r]);if(at)for(var r of at(e))Gr.call(e,r)&&Vr(t,r,e[r]);return t},K=(t,e)=>fs(t,ds(e)),Gt=(t,e)=>{var r={};for(var n in t)Hr.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&at)for(var n of at(t))e.indexOf(n)<0&&Gr.call(t,n)&&(r[n]=t[n]);return r};const Vt="nhostRefreshToken",zt="nhostRefreshTokenExpiresAt",hs=3,vs=300,ps=5,ys=0,me=10,gs=20,ot={status:me,error:"invalid-email",message:"Email is incorrectly formatted"},Jt={status:me,error:"invalid-password",message:"Password is incorrectly formatted"},ms={status:me,error:"invalid-phone-number",message:"Phone number is incorrectly formatted"},ws={status:me,error:"no-mfa-ticket",message:"No MFA ticket has been provided"},Es={status:me,error:"no-refresh-token",message:"No refresh token has been provided"},Ss={status:gs,error:"refresher-already-running",message:"The token refresher is already running. You must wait until is has finished before submitting a new token."},Pe=t=>{const e=it.create({baseURL:t});return e.interceptors.response.use(r=>r,r=>{var n,i,s,a,o,c,f,u,v,d;return Promise.reject({error:{message:(o=(a=(s=(i=(n=r.response)==null?void 0:n.data)==null?void 0:i.message)!=null?s:r.message)!=null?a:r.request.responseText)!=null?o:JSON.stringify(r),status:(v=(u=(c=r.response)==null?void 0:c.status)!=null?u:(f=r.response)==null?void 0:f.data.statusCode)!=null?v:ys,error:((d=r.response)==null?void 0:d.data.error)||r.request.statusText||"network"}})}),e},ut=typeof window!="undefined",ct=new Map,Ts=t=>{var e;return ut&&typeof localStorage!="undefined"?localStorage.getItem(t):(e=ct.get(t))!=null?e:null},bs=(t,e)=>{ut&&typeof localStorage!="undefined"?e?localStorage.setItem(t,e):localStorage.removeItem(t):e?ct.set(t,e):ct.has(t)&&ct.delete(t)},xs=(t,e)=>{if(t==="localStorage"||t==="web")return Ts;if(t==="cookie")return r=>{var n;return ut&&(n=Ht.get(r))!=null?n:null};if(!e)throw Error(`clientStorageType is set to '${t}' but no clienStorage 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 getItem or getItemAsync property")}throw Error(`Unknown storage type: ${t}`)},Os=(t,e)=>{if(t==="localStorage"||t==="web")return bs;if(t==="cookie")return(r,n)=>{ut&&(n?Ht.set(r,n):Ht.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}`)},_s=(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},se=(t,e)=>{var r;return e!=null&&e.redirectTo?K(Y({},e),{redirectTo:(r=e==null?void 0:e.redirectTo)!=null&&r.startsWith("/")?t+e.redirectTo:e==null?void 0:e.redirectTo}):e};function lt(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 zr(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 Wt=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,}))$/),Jr=t=>!!t&&typeof t=="string"&&t.length>=hs,As=t=>!!t&&typeof t=="string",Wr={user:null,mfa:null,accessToken:{value:null,expiresAt:null},refreshTimer:{startedAt:null,attempts:0,lastAttempt:null},refreshToken:{value:null},errors:{}},Is=({backendUrl:t,clientUrl:e,interpreter:r})=>{const n=Pe(t);return Ne({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:P({error:i=>ot}),saveRequestError:P({error:(i,{data:{error:s}})=>s}),reportError:J(i=>({type:"ERROR",error:i.error})),reportSuccess:J("SUCCESS")},guards:{invalidEmail:(i,{email:s})=>!Wt(s)},services:{requestChange:async(i,{email:s,options:a})=>(await n.post("/user/email/change",{newEmail:s,options:se(e,a)},{headers:{authorization:`Bearer ${r==null?void 0:r.state.context.accessToken.value}`}})).data}})},Rs=({backendUrl:t,interpreter:e})=>{const r=Pe(t);return Ne({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:P({error:n=>Jt}),saveRequestError:P({error:(n,{data:{error:i}})=>(console.log(i),i)}),reportError:J(n=>({type:"ERROR",error:n.error})),reportSuccess:J("SUCCESS")},guards:{invalidPassword:(n,{password:i})=>!Jr(i)},services:{requestChange:(n,{password:i})=>r.post("/user/password",{newPassword:i},{headers:{authorization:`Bearer ${e==null?void 0:e.state.context.accessToken.value}`}})}})},Ns=({backendUrl:t,clientUrl:e})=>{const r=Pe(t);return Ne({schema:{context:{},events:{}},tsTypes:{},preserveActionOrder:!0,id:"changePassword",initial:"idle",context:{error:null},states:{idle:{on:{REQUEST:"requesting"},initial:"initial",states:{initial:{},success:{},error:{}}},requesting:{invoke:{src:"requestChange",id:"requestChange",onDone:{target:"idle.success",actions:"reportSuccess"},onError:{actions:["saveRequestError","reportError"],target:"idle.error"}}}}},{actions:{saveRequestError:P({error:(n,{data:{error:i}})=>(console.log(i),i)}),reportError:J(n=>({type:"ERROR",error:n.error})),reportSuccess:J("SUCCESS")},services:{requestChange:(n,{email:i,options:s})=>r.post("/user/password/reset",{email:i,options:se(e,s)})}})},ks=({backendUrl:t,clientUrl:e,interpreter:r})=>{const n=Pe(t);return Ne({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:P({error:i=>ot}),saveRequestError:P({error:(i,{data:{error:s}})=>s}),reportError:J(i=>({type:"ERROR",error:i.error})),reportSuccess:J("SUCCESS")},guards:{invalidEmail:(i,{email:s})=>!Wt(s)},services:{request:async(i,{email:s,options:a})=>(await n.post("/user/email/send-verification-email",{email:s,options:se(e,a)})).data}})},Ps=({backendUrl:t,clientUrl:e,clientStorageGetter:r,clientStorageSetter:n,clientStorageType:i="web",clientStorage:s,refreshIntervalTime:a,autoRefreshToken:o=!0,autoSignIn:c=!0})=>{const f=r||xs(i,s),u=n||Os(i,s),v=Pe(t),d=async(l,h,p)=>(await v.post(l,h,p)).data;return Ne({schema:{context:{},events:{}},tsTypes:{},context:Wr,preserveActionOrder:!0,id:"nhost",type:"parallel",states:{authentication:{initial:"starting",on:{SESSION_UPDATE:[{cond:"hasSession",actions:["saveSession","resetTimer","reportTokenChanged"],target:".signedIn"}]},states:{starting:{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:{exit:"resetAuthenticationError",initial:"server",states:{server:{},validation:{states:{password:{},email:{},phoneNumber:{}}}}},signingOut:{entry:["clearContextExceptRefreshToken"],exit:["destroyRefreshToken","reportTokenChanged"],invoke:{src:"signout",id:"signingOut",onDone:{target:"success"},onError:{target:"failed.server"}}}},on:{SIGNIN_PASSWORD:[{cond:"invalidEmail",actions:["saveInvalidEmail"],target:".failed.validation.email"},{cond:"invalidPassword",actions:["saveInvalidPassword"],target:".failed.validation.password"},"#nhost.authentication.authenticating.password"],SIGNIN_PASSWORDLESS_EMAIL:[{cond:"invalidEmail",actions:"saveInvalidEmail",target:".failed.validation.email"},"#nhost.authentication.authenticating.passwordlessEmail"],SIGNIN_PASSWORDLESS_SMS:[{cond:"invalidPhoneNumber",actions:"saveInvalidPhoneNumber",target:".failed.validation.phoneNumber"},"#nhost.authentication.authenticating.passwordlessSms"],SIGNIN_PASSWORDLESS_SMS_OTP:[{cond:"invalidPhoneNumber",actions:"saveInvalidPhoneNumber",target:".failed.validation.phoneNumber"},"#nhost.authentication.authenticating.passwordlessSmsOtp"],SIGNUP_EMAIL_PASSWORD:[{cond:"invalidEmail",actions:"saveInvalidSignUpEmail",target:".failed.validation.email"},{cond:"invalidPassword",actions:"saveInvalidSignUpPassword",target:".failed.validation.password"},"#nhost.authentication.registering"],SIGNIN_ANONYMOUS:"#nhost.authentication.authenticating.anonymous",SIGNIN_MFA_TOTP:[{cond:"noMfaTicket",actions:["saveNoMfaTicketError"],target:".failed"},"#nhost.authentication.authenticating.mfa.totp"]}},authenticating:{states:{passwordlessEmail:{invoke:{src:"signInPasswordlessEmail",id:"authenticatePasswordlessEmail",onDone:{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:"resetSignUpError",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:"saveRegisrationError",target:"signedOut.failed.server"}]}},signedIn:{type:"parallel",entry:["reportSignedIn","cleanUrl","broadcastToken"],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"},{target:["#nhost.authentication.signedOut","idle.error"]}]}}}},email:{initial:"awaitingVerification",on:{SIGNED_IN:[{cond:"needsVerification",target:".awaitingVerification"},".valid"],SIGNOUT:".awaitingVerification",AWAIT_EMAIL_VERIFICATION:".awaitingVerification"},states:{awaitingVerification:{},valid:{}}}}},{actions:{reportSignedIn:J("SIGNED_IN"),reportSignedOut:J("SIGNED_OUT"),reportAwaitEmailVerification:J("AWAIT_EMAIL_VERIFICATION"),reportTokenChanged:J("TOKEN_CHANGED"),clearContextExceptRefreshToken:P(({refreshToken:{value:l}})=>(u(zt,null),K(Y({},Wr),{refreshToken:{value:l}}))),saveSession:P({user:(l,{data:h})=>{var p;return(p=h==null?void 0:h.session)==null?void 0:p.user},accessToken:(l,{data:h})=>{var p,y;if(h.session.accessTokenExpiresIn){const E=new Date(Date.now()+h.session.accessTokenExpiresIn*1e3).toISOString();u(zt,E)}else u(zt,null);return{value:(p=h==null?void 0:h.session)==null?void 0:p.accessToken,expiresAt:new Date(Date.now()+((y=h==null?void 0:h.session)==null?void 0:y.accessTokenExpiresIn)*1e3)}},refreshToken:(l,{data:h})=>{var p;return u(Vt,h.session.refreshToken),{value:(p=h==null?void 0:h.session)==null?void 0:p.refreshToken}}}),saveMfaTicket:P({mfa:(l,h)=>{var p,y;return(y=(p=h.data)==null?void 0:p.mfa)!=null?y:null}}),resetTimer:P({refreshTimer:(l,h)=>({startedAt:new Date,attempts:0,lastAttempt:null})}),saveRefreshAttempt:P({refreshTimer:(l,h)=>({startedAt:l.refreshTimer.startedAt,attempts:l.refreshTimer.attempts+1,lastAttempt:new Date})}),saveAuthenticationError:P({errors:({errors:l},{data:{error:h}})=>K(Y({},l),{authentication:h})}),resetAuthenticationError:P({errors:l=>{var{errors:h}=l,p=h,y=Gt(p,["authentication"]);return y}}),saveInvalidEmail:P({errors:({errors:l})=>K(Y({},l),{authentication:ot})}),saveInvalidPassword:P({errors:({errors:l})=>K(Y({},l),{authentication:Jt})}),saveInvalidPhoneNumber:P({errors:({errors:l})=>K(Y({},l),{authentication:ms})}),saveRegisrationError:P({errors:({errors:l},{data:{error:h}})=>K(Y({},l),{registration:h})}),resetSignUpError:P({errors:l=>{var{errors:h}=l,p=h,y=Gt(p,["registration"]);return y}}),saveInvalidSignUpPassword:P({errors:({errors:l})=>K(Y({},l),{registration:Jt})}),saveInvalidSignUpEmail:P({errors:({errors:l})=>K(Y({},l),{registration:ot})}),saveNoMfaTicketError:P({errors:({errors:l})=>K(Y({},l),{registration:ws})}),destroyRefreshToken:P({refreshToken:l=>(u(Vt,null),{value:null})}),cleanUrl:()=>{c&<("refreshToken")&&(zr("refreshToken"),zr("type"))},broadcastToken:l=>{if(c)try{new BroadcastChannel("nhost").postMessage(l.refreshToken.value)}catch{}}},guards:{needsVerification:(l,h)=>!l.user||l.user.isAnonymous,isSignedIn:l=>!!l.user&&!!l.refreshToken.value&&!!l.accessToken.value,noToken:l=>!l.refreshToken.value,noMfaTicket:(l,{ticket:h})=>{var p;return!h&&!((p=l.mfa)!=null&&p.ticket)},hasRefreshToken:l=>!!l.refreshToken.value,isAutoRefreshDisabled:()=>!o,refreshTimerShouldRefresh:l=>{var h;const{expiresAt:p}=l.accessToken;return p?l.refreshTimer.lastAttempt?Date.now()-l.refreshTimer.lastAttempt.getTime()>ps*1e3:a&&Date.now()-(((h=l.refreshTimer.startedAt)==null?void 0:h.getTime())||0)>a*1e3?!0:p.getTime()-Date.now()-1e3*vs<=0:!1},unverified:(l,{data:{error:h}})=>h.status===401&&h.message==="Email is not verified",hasSession:(l,h)=>{var p;return!!((p=h.data)!=null&&p.session)},hasMfaTicket:(l,h)=>{var p;return!!((p=h.data)!=null&&p.mfa)},invalidEmail:(l,{email:h})=>!Wt(h),invalidPassword:(l,{password:h})=>!Jr(h),invalidPhoneNumber:(l,{phoneNumber:h})=>!As(h)},services:{signInPassword:(l,{email:h,password:p})=>d("/signin/email-password",{email:h,password:p}),signInPasswordlessSms:(l,{phoneNumber:h,options:p})=>d("/signin/passwordless/sms",{phoneNumber:h,options:se(e,p)}),signInPasswordlessSmsOtp:(l,{phoneNumber:h,otp:p})=>d("/signin/passwordless/sms/otp",{phoneNumber:h,otp:p}),signInPasswordlessEmail:(l,{email:h,options:p})=>d("/signin/passwordless/email",{email:h,options:se(e,p)}),signInAnonymous:l=>d("/signin/anonymous"),signInMfaTotp:(l,{ticket:h,otp:p})=>{var y;return d("/signin/mfa/totp",{ticket:h||((y=l.mfa)==null?void 0:y.ticket),otp:p})},refreshToken:async(l,h)=>{const p=h.type==="TRY_TOKEN"?h.token:l.refreshToken.value;return{session:await d("/token",{refreshToken:p})}},signout:(l,h)=>d("/signout",{refreshToken:l.refreshToken.value,all:!!h.all}),registerUser:(l,{email:h,password:p,options:y})=>d("/signup/email-password",{email:h,password:p,options:se(e,y)}),importRefreshToken:async()=>{let l=null;if(c){const p=lt("refreshToken")||null;if(p)try{return{session:await d("/token",{refreshToken:p})}}catch(y){l=y.error}else{const y=lt("error");if(y)return Promise.reject({error:{status:me,error:y,message:lt("errorDescription")||y}})}}const h=await f(Vt);if(h)try{return{session:await d("/token",{refreshToken:h})}}catch(p){l=p.error}return Promise.reject({error:l})}}})};class Cs{constructor(e){var r=e,{clientStorageType:n="web",autoSignIn:i=!0,autoRefreshToken:s=!0,start:a=!0,backendUrl:o,clientUrl:c}=r,f=Gt(r,["clientStorageType","autoSignIn","autoRefreshToken","start","backendUrl","clientUrl"]);if(this._subscriptions=new Set,this.backendUrl=o,this.clientUrl=c,this.machine=Ps(K(Y({},f),{backendUrl:o,clientUrl:c,clientStorageType:n,autoSignIn:i,autoRefreshToken:s})),a&&(this.interpreter=fe(this.machine),this.interpreter.start()),typeof window!="undefined"&&i)try{this._channel=new BroadcastChannel("nhost"),this._channel.addEventListener("message",u=>{var v;const d=(v=this.interpreter)==null?void 0:v.state.context.refreshToken.value;this.interpreter&&u.data!==d&&this.interpreter.send({type:"TRY_TOKEN",token:u.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 Yr=Object.getOwnPropertySymbols,Us=Object.prototype.hasOwnProperty,Ds=Object.prototype.propertyIsEnumerable,js=(t,e)=>{var r={};for(var n in t)Us.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&Yr)for(var n of Yr(t))e.indexOf(n)<0&&Ds.call(t,n)&&(r[n]=t[n]);return r};const $s=()=>typeof window!="undefined",re=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},Kr={message:"User is already signed in",status:100},Ls={message:"User is not authenticated",status:101},Ms={message:"User is not anonymous",status:101},qs={message:"Email needs verification",status:102};class Bs{constructor({url:e,autoRefreshToken:r=!0,autoSignIn:n=!0,autoLogin:i,clientStorage:s,clientStorageType:a,clientStorageGetter:o,clientStorageSetter:c,refreshIntervalTime:f,start:u=!0}){var v;this._client=new Cs({backendUrl:e,clientUrl:typeof window!="undefined"&&((v=window.location)==null?void 0:v.origin)||"",autoRefreshToken:r,autoSignIn:typeof i=="boolean"?i:n,start:u,clientStorage:s,clientStorageType:a,clientStorageGetter:o,clientStorageSetter:c,refreshIntervalTime:f})}async signUp(e){const r=await this.waitUntilReady(),{email:n,password:i,options:s}=e;return this.isAuthenticated()?{session:null,error:Kr}:new Promise(a=>{r.send("SIGNUP_EMAIL_PASSWORD",{email:n,password:i,options:s}),r.onTransition(o=>{if(o.matches({authentication:{signedOut:"noErrors"},email:"awaitingVerification"}))return a({session:null,error:null});if(o.matches({authentication:{signedOut:"failed"}}))return a({session:null,error:o.context.errors.registration||null});if(o.matches({authentication:"signedIn"}))return a({session:re(o.context),error:null})})})}async signIn(e){const r=await this.waitUntilReady();if(this.isAuthenticated())return{session:null,mfa:null,error:Kr};if("provider"in e){const{provider:i,options:s}=e,a=_s(`${this._client.backendUrl}/signin/provider/${i}`,se(this._client.clientUrl,s));return $s()&&(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=>{r.send("SIGNIN_PASSWORD",e),r.onTransition(s=>{s.matches({authentication:"signedIn"})?i({session:re(s.context),mfa:null,error:null}):s.matches({authentication:{signedOut:"noErrors"},email:"awaitingVerification"})?i({session:null,mfa:null,error:qs}):s.matches({authentication:{signedOut:"needsMfa"}})?i({session:null,mfa:s.context.mfa,error:null}):s.matches({authentication:{signedOut:"failed"}})&&i({session:null,mfa:null,error:s.context.errors.authentication||null})})});if("email"in e&&!("otp"in e))return new Promise(i=>{r.send("SIGNIN_PASSWORDLESS_EMAIL",e),r.onTransition(s=>{s.matches({authentication:{signedOut:"noErrors"},email:"awaitingVerification"})?i({session:null,mfa:null,error:null}):s.matches({authentication:{signedOut:"failed"}})&&i({session:null,mfa:null,error:s.context.errors.authentication||null})})});if("phoneNumber"in e&&!("otp"in e))return new Promise(i=>{r.send("SIGNIN_PASSWORDLESS_SMS",e),r.onTransition(s=>{s.matches({authentication:{signedOut:"needsSmsOtp"}})?i({session:null,mfa:null,error:null}):s.matches({authentication:{signedOut:"failed"}})&&i({session:null,mfa:null,error:s.context.errors.authentication||null})})});if("otp"in e)return new Promise(i=>{r.send("SIGNIN_PASSWORDLESS_SMS_OTP",e),r.onTransition(s=>{s.matches({authentication:"signedIn"})?i({session:re(s.context),mfa:null,error:null}):s.matches({authentication:{signedOut:"failed"}})&&i({session:null,mfa:null,error:s.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:re(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:{message:"already signed in",status:1}}}async signOut(e){const r=await this.waitUntilReady();return this.isAuthenticated()?new Promise(n=>{r.send("SIGNOUT",{all:e==null?void 0:e.all}),r.onTransition(i=>{i.matches({authentication:{signedOut:"success"}})?n({error:null}):i.matches({authentication:{signedOut:{failed:"server"}}})&&n({error:i.context.errors.signout||null})})}):{error:Ls}}async resetPassword({email:e,options:r}){return new Promise(n=>{const i=fe(Ns(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=fe(Rs(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=fe(ks(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=fe(Is(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:Ms};const s=e,{signInMethod:a,connection:o}=s,c=js(s,["signInMethod","connection"]);r.send("DEANONYMIZE",{signInMethod:a,connection:o,options:c}),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(re(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,re(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?an(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 r.state.matches({token:"idle"})?new Promise(n=>{const i=e||r.state.context.refreshToken.value;if(!i)return n({session:null,error:Es});r.send("TRY_TOKEN",{token:i}),r==null||r.onTransition(s=>{s.matches({token:{idle:"error"}})?n({session:null,error:{status:400,message:"Invalid refresh token"}}):s.event.type==="TOKEN_CHANGED"&&n({session:re(s.context),error:null})})}):{session:null,error:Ss}}catch(r){return{session:null,error:r.message}}}getSession(){var e,r;return re((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 Fs=Object.defineProperty,Hs=Object.defineProperties,Gs=Object.getOwnPropertyDescriptors,Xr=Object.getOwnPropertySymbols,Vs=Object.prototype.hasOwnProperty,zs=Object.prototype.propertyIsEnumerable,Qr=(t,e,r)=>e in t?Fs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ce=(t,e)=>{for(var r in e||(e={}))Vs.call(e,r)&&Qr(t,r,e[r]);if(Xr)for(var r of Xr(e))zs.call(e,r)&&Qr(t,r,e[r]);return t},Js=(t,e)=>Hs(t,Gs(e));class Ws{constructor({url:e}){this.url=e,this.httpClient=it.create({baseURL:this.url})}async upload(e){try{return{fileMetadata:(await this.httpClient.post("/files",e.file,{headers:Ce(Ce({},this.generateUploadHeaders(e)),this.generateAuthHeaders())})).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:Ce({},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:Ce({},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 Ys{constructor({url:e}){this.url=e,this.api=new Ws({url:e})}async upload(e){const r=new FormData;r.append("file",e.file);const{fileMetadata:n,error:i}=await this.api.upload(Js(Ce({},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 Zr{constructor(e){const{url:r}=e;this.accessToken=null,this.instance=it.create({baseURL:r})}async call(e,r,n){const i=ae(ae({},this.generateAccessTokenHeaders()),n==null?void 0:n.headers);let s;try{s=await this.instance.post(e,r,Yt(ae({},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 en{constructor(e){const{url:r}=e;this.url=r,this.accessToken=null,this.instance=it.create({baseURL:r})}async request(e,r,n){const i=ae(ae({},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},Yt(ae({},n),{headers:i}))).data,{data:c}=o;return o.errors?{data:null,error:o.errors}:typeof c!="object"||Array.isArray(c)||c===null?{data:null,error:new Error("incorrect response data from GraphQL server")}:{data:c,error:null}}catch(s){return s instanceof Error?{data:null,error:s}:(console.error(s),{data:null,error:new Error("Unable to get do GraphQL request")})}}getUrl(){return this.url}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){if(!!this.accessToken)return{Authorization:`Bearer ${this.accessToken}`}}}class tn{constructor({backendUrl:e,refreshIntervalTime:r,clientStorageGetter:n,clientStorageSetter:i,clientStorage:s,clientStorageType:a,autoRefreshToken:o,autoSignIn:c,start:f=!0}){var u;if(!e)throw new Error("Please specify a `backendUrl`. Docs: [todo]!");this.auth=new Bs({url:`${e}/v1/auth`,refreshIntervalTime:r,clientStorageGetter:n,clientStorageSetter:i,clientStorage:s,clientStorageType:a,autoRefreshToken:o,autoSignIn:c,start:f}),this.storage=new Ys({url:`${e}/v1/storage`}),this.functions=new Zr({url:`${e}/v1/functions`}),this.graphql=new en({url:`${e}/v1/graphql`}),this.storage.setAccessToken(this.auth.getAccessToken()),this.functions.setAccessToken(this.auth.getAccessToken()),this.graphql.setAccessToken(this.auth.getAccessToken()),(u=this.auth.client)==null||u.onStart(()=>{this.auth.onAuthStateChanged((v,d)=>{v==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(v=>{this.storage.setAccessToken(v==null?void 0:v.accessToken),this.functions.setAccessToken(v==null?void 0:v.accessToken),this.graphql.setAccessToken(v==null?void 0:v.accessToken)})})}}const Ks=t=>new tn(t);D.NhostClient=tn,D.NhostFunctionsClient=Zr,D.NhostGraphqlClient=en,D.createClient=Ks,Object.defineProperties(D,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
19
|
+
//# sourceMappingURL=nhost-js.umd.js.map
|