@teamhanko/hanko-frontend-sdk 0.8.0 → 0.8.2
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/README.md +13 -0
- package/dist/Hanko.d.ts +20 -2
- package/dist/lib/Cookie.d.ts +13 -0
- package/dist/lib/Session.d.ts +15 -1
- package/dist/lib/client/Client.d.ts +3 -3
- package/dist/lib/client/HttpClient.d.ts +16 -2
- package/dist/lib/client/PasscodeClient.d.ts +2 -1
- package/dist/lib/client/PasswordClient.d.ts +2 -1
- package/dist/lib/client/ThirdPartyClient.d.ts +0 -1
- package/dist/lib/client/TokenClient.d.ts +0 -1
- package/dist/lib/client/WebauthnClient.d.ts +2 -1
- package/dist/lib/events/Dispatcher.d.ts +13 -0
- package/dist/lib/events/Relay.d.ts +15 -1
- package/dist/lib/state/session/SessionState.d.ts +12 -2
- package/dist/lib/state/users/UserState.d.ts +0 -1
- package/dist/sdk.cjs +1 -1
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.modern.js +1 -1
- package/dist/sdk.modern.js.map +1 -1
- package/dist/sdk.module.js +1 -1
- package/dist/sdk.module.js.map +1 -1
- package/dist/sdk.umd.js +1 -1
- package/dist/sdk.umd.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -37,6 +37,19 @@ With a script tag via CDN:
|
|
|
37
37
|
</script>
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
### Options
|
|
41
|
+
|
|
42
|
+
You can pass certain options, when creating a new `Hanko` instance:
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
const defaultOptions = {
|
|
46
|
+
timeout: 13000, // The timeout (in ms) for the HTTP requests.
|
|
47
|
+
cookieName: "hanko", // The cookie name under which the session token is set.
|
|
48
|
+
localStorageKey: "hanko" // The prefix / name of the localStorage keys.
|
|
49
|
+
};
|
|
50
|
+
const hanko = new Hanko("http://localhost:3000", defaultOptions);
|
|
51
|
+
```
|
|
52
|
+
|
|
40
53
|
## Documentation
|
|
41
54
|
|
|
42
55
|
To see the latest documentation, please click [here](https://docs.hanko.io/jsdoc/hanko-frontend-sdk).
|
package/dist/Hanko.d.ts
CHANGED
|
@@ -9,12 +9,25 @@ import { TokenClient } from "./lib/client/TokenClient";
|
|
|
9
9
|
import { Listener } from "./lib/events/Listener";
|
|
10
10
|
import { Relay } from "./lib/events/Relay";
|
|
11
11
|
import { Session } from "./lib/Session";
|
|
12
|
+
/**
|
|
13
|
+
* The options for the Hanko class
|
|
14
|
+
*
|
|
15
|
+
* @interface
|
|
16
|
+
* @property {number=} timeout - The http request timeout in milliseconds. Defaults to 13000ms
|
|
17
|
+
* @property {string=} cookieName - The name of the session cookie set from the SDK. Defaults to "hanko"
|
|
18
|
+
* @property {string=} localStorageKey - The prefix / name of the local storage keys. Defaults to "hanko"
|
|
19
|
+
*/
|
|
20
|
+
export interface HankoOptions {
|
|
21
|
+
timeout?: number;
|
|
22
|
+
cookieName?: string;
|
|
23
|
+
localStorageKey?: string;
|
|
24
|
+
}
|
|
12
25
|
/**
|
|
13
26
|
* A class that bundles all available SDK functions.
|
|
14
27
|
*
|
|
15
28
|
* @extends {Listener}
|
|
16
29
|
* @param {string} api - The URL of your Hanko API instance
|
|
17
|
-
* @param {
|
|
30
|
+
* @param {HankoOptions=} options - The options that can be used
|
|
18
31
|
*/
|
|
19
32
|
declare class Hanko extends Listener {
|
|
20
33
|
api: string;
|
|
@@ -28,6 +41,11 @@ declare class Hanko extends Listener {
|
|
|
28
41
|
token: TokenClient;
|
|
29
42
|
relay: Relay;
|
|
30
43
|
session: Session;
|
|
31
|
-
constructor(api: string,
|
|
44
|
+
constructor(api: string, options?: HankoOptions);
|
|
45
|
+
}
|
|
46
|
+
export interface InternalOptions {
|
|
47
|
+
timeout: number;
|
|
48
|
+
cookieName: string;
|
|
49
|
+
localStorageKey: string;
|
|
32
50
|
}
|
|
33
51
|
export { Hanko };
|
package/dist/lib/Cookie.d.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for Cookie
|
|
3
|
+
*
|
|
4
|
+
* @category SDK
|
|
5
|
+
* @subcategory Internal
|
|
6
|
+
* @property {string} cookieName - The name of the session cookie set from the SDK.
|
|
7
|
+
*/
|
|
8
|
+
interface CookieOptions {
|
|
9
|
+
cookieName: string;
|
|
10
|
+
}
|
|
1
11
|
/**
|
|
2
12
|
* A class to manage cookies.
|
|
3
13
|
*
|
|
4
14
|
* @category SDK
|
|
5
15
|
* @subcategory Internal
|
|
16
|
+
* @param {CookieOptions} options - The options that can be used
|
|
6
17
|
*/
|
|
7
18
|
export declare class Cookie {
|
|
8
19
|
authCookieName: string;
|
|
20
|
+
constructor(options: CookieOptions);
|
|
9
21
|
/**
|
|
10
22
|
* Returns the authentication token that was stored in the cookie.
|
|
11
23
|
*
|
|
@@ -24,3 +36,4 @@ export declare class Cookie {
|
|
|
24
36
|
*/
|
|
25
37
|
removeAuthCookie(): void;
|
|
26
38
|
}
|
|
39
|
+
export {};
|
package/dist/lib/Session.d.ts
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
import { SessionDetail } from "./events/CustomEvents";
|
|
2
2
|
import { SessionState } from "./state/session/SessionState";
|
|
3
3
|
import { Cookie } from "./Cookie";
|
|
4
|
+
/**
|
|
5
|
+
* Options for Session
|
|
6
|
+
*
|
|
7
|
+
* @category SDK
|
|
8
|
+
* @subcategory Internal
|
|
9
|
+
* @property {string} cookieName - The name of the session cookie set from the SDK.
|
|
10
|
+
* @property {string} localStorageKey - The prefix / name of the local storage keys.
|
|
11
|
+
*/
|
|
12
|
+
interface SessionOptions {
|
|
13
|
+
cookieName: string;
|
|
14
|
+
localStorageKey: string;
|
|
15
|
+
}
|
|
4
16
|
/**
|
|
5
17
|
A class representing a session.
|
|
6
18
|
|
|
7
19
|
@category SDK
|
|
8
20
|
@subcategory Session
|
|
21
|
+
@param {SessionOptions} options - The options that can be used
|
|
9
22
|
*/
|
|
10
23
|
export declare class Session {
|
|
11
24
|
_sessionState: SessionState;
|
|
12
25
|
_cookie: Cookie;
|
|
13
|
-
constructor();
|
|
26
|
+
constructor(options: SessionOptions);
|
|
14
27
|
/**
|
|
15
28
|
Retrieves the session details.
|
|
16
29
|
|
|
@@ -45,3 +58,4 @@ export declare class Session {
|
|
|
45
58
|
*/
|
|
46
59
|
private static validate;
|
|
47
60
|
}
|
|
61
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HttpClient } from "./HttpClient";
|
|
1
|
+
import { HttpClient, HttpClientOptions } from "./HttpClient";
|
|
2
2
|
/**
|
|
3
3
|
* A class to be extended by the other client classes.
|
|
4
4
|
*
|
|
@@ -6,10 +6,10 @@ import { HttpClient } from "./HttpClient";
|
|
|
6
6
|
* @category SDK
|
|
7
7
|
* @subcategory Internal
|
|
8
8
|
* @param {string} api - The URL of your Hanko API instance
|
|
9
|
-
* @param {
|
|
9
|
+
* @param {HttpClientOptions} options - The options that can be used
|
|
10
10
|
*/
|
|
11
11
|
declare abstract class Client {
|
|
12
12
|
client: HttpClient;
|
|
13
|
-
constructor(api: string,
|
|
13
|
+
constructor(api: string, options: HttpClientOptions);
|
|
14
14
|
}
|
|
15
15
|
export { Client };
|
|
@@ -53,6 +53,20 @@ declare class Response {
|
|
|
53
53
|
*/
|
|
54
54
|
parseNumericHeader(name: string): number;
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Options for the HttpClient
|
|
58
|
+
*
|
|
59
|
+
* @category SDK
|
|
60
|
+
* @subcategory Internal
|
|
61
|
+
* @property {number} timeout - The http request timeout in milliseconds.
|
|
62
|
+
* @property {string} cookieName - The name of the session cookie set from the SDK.
|
|
63
|
+
* @property {string} localStorageKey - The prefix / name of the local storage keys.
|
|
64
|
+
*/
|
|
65
|
+
export interface HttpClientOptions {
|
|
66
|
+
timeout: number;
|
|
67
|
+
cookieName: string;
|
|
68
|
+
localStorageKey: string;
|
|
69
|
+
}
|
|
56
70
|
/**
|
|
57
71
|
* Internally used for communication with the Hanko API. It also handles authorization tokens to enable authorized
|
|
58
72
|
* requests.
|
|
@@ -65,7 +79,7 @@ declare class Response {
|
|
|
65
79
|
* @category SDK
|
|
66
80
|
* @subcategory Internal
|
|
67
81
|
* @param {string} api - The URL of your Hanko API instance
|
|
68
|
-
* @param {
|
|
82
|
+
* @param {HttpClientOptions} options - The options the HttpClient must be provided
|
|
69
83
|
*/
|
|
70
84
|
declare class HttpClient {
|
|
71
85
|
timeout: number;
|
|
@@ -74,7 +88,7 @@ declare class HttpClient {
|
|
|
74
88
|
passcodeState: PasscodeState;
|
|
75
89
|
dispatcher: Dispatcher;
|
|
76
90
|
cookie: Cookie;
|
|
77
|
-
constructor(api: string,
|
|
91
|
+
constructor(api: string, options: HttpClientOptions);
|
|
78
92
|
_fetch(path: string, options: RequestInit, xhr?: XMLHttpRequest): Promise<Response>;
|
|
79
93
|
/**
|
|
80
94
|
* Processes the response headers on login and extracts the JWT and expiration time. Also, the passcode state will be
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PasscodeState } from "../state/users/PasscodeState";
|
|
2
2
|
import { Passcode } from "../Dto";
|
|
3
3
|
import { Client } from "./Client";
|
|
4
|
+
import { HttpClientOptions } from "./HttpClient";
|
|
4
5
|
/**
|
|
5
6
|
* A class to handle passcodes.
|
|
6
7
|
*
|
|
@@ -11,7 +12,7 @@ import { Client } from "./Client";
|
|
|
11
12
|
*/
|
|
12
13
|
declare class PasscodeClient extends Client {
|
|
13
14
|
state: PasscodeState;
|
|
14
|
-
constructor(api: string,
|
|
15
|
+
constructor(api: string, options: HttpClientOptions);
|
|
15
16
|
/**
|
|
16
17
|
* Causes the API to send a new passcode to the user's email address.
|
|
17
18
|
*
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PasswordState } from "../state/users/PasswordState";
|
|
2
2
|
import { PasscodeState } from "../state/users/PasscodeState";
|
|
3
3
|
import { Client } from "./Client";
|
|
4
|
+
import { HttpClientOptions } from "./HttpClient";
|
|
4
5
|
/**
|
|
5
6
|
* A class to handle passwords.
|
|
6
7
|
*
|
|
@@ -12,7 +13,7 @@ import { Client } from "./Client";
|
|
|
12
13
|
declare class PasswordClient extends Client {
|
|
13
14
|
passwordState: PasswordState;
|
|
14
15
|
passcodeState: PasscodeState;
|
|
15
|
-
constructor(api: string,
|
|
16
|
+
constructor(api: string, options: HttpClientOptions);
|
|
16
17
|
/**
|
|
17
18
|
* Logs in a user with a password.
|
|
18
19
|
*
|
|
@@ -10,7 +10,6 @@ import { ThirdPartyError } from "../Errors";
|
|
|
10
10
|
* @extends {Client}
|
|
11
11
|
*/
|
|
12
12
|
export declare class ThirdPartyClient extends Client {
|
|
13
|
-
constructor(api: string, timeout?: number);
|
|
14
13
|
/**
|
|
15
14
|
* Performs a request to the Hanko API that redirects to the given
|
|
16
15
|
* third party provider.
|
|
@@ -8,7 +8,6 @@ import { Client } from "./Client";
|
|
|
8
8
|
* @extends {Client}
|
|
9
9
|
*/
|
|
10
10
|
export declare class TokenClient extends Client {
|
|
11
|
-
constructor(api: string, timeout?: number);
|
|
12
11
|
/**
|
|
13
12
|
* Validate a one time token to retrieve a session JWT. Does nothing
|
|
14
13
|
* if the current window location does not contain a 'hanko_token' in the
|
|
@@ -3,6 +3,7 @@ import { Client } from "./Client";
|
|
|
3
3
|
import { PasscodeState } from "../state/users/PasscodeState";
|
|
4
4
|
import { WebauthnState } from "../state/users/WebauthnState";
|
|
5
5
|
import { User, WebauthnCredentials, WebauthnFinalized } from "../Dto";
|
|
6
|
+
import { HttpClientOptions } from "./HttpClient";
|
|
6
7
|
/**
|
|
7
8
|
* A class that handles WebAuthn authentication and registration.
|
|
8
9
|
*
|
|
@@ -17,7 +18,7 @@ declare class WebauthnClient extends Client {
|
|
|
17
18
|
controller: AbortController;
|
|
18
19
|
_getCredential: typeof getWebauthnCredential;
|
|
19
20
|
_createCredential: typeof createWebauthnCredential;
|
|
20
|
-
constructor(api: string,
|
|
21
|
+
constructor(api: string, options: HttpClientOptions);
|
|
21
22
|
/**
|
|
22
23
|
* Performs a WebAuthn authentication ceremony. When 'userID' is specified, the API provides a list of
|
|
23
24
|
* allowed credentials and the browser is able to present a list of suitable credentials to the user.
|
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
import { SessionDetail, AuthFlowCompletedDetail } from "./CustomEvents";
|
|
2
2
|
import { SessionState } from "../state/session/SessionState";
|
|
3
|
+
/**
|
|
4
|
+
* Options for Dispatcher
|
|
5
|
+
*
|
|
6
|
+
* @category SDK
|
|
7
|
+
* @subcategory Internal
|
|
8
|
+
* @property {string} localStorageKey - The prefix / name of the local storage keys.
|
|
9
|
+
*/
|
|
10
|
+
interface DispatcherOptions {
|
|
11
|
+
localStorageKey: string;
|
|
12
|
+
}
|
|
3
13
|
/**
|
|
4
14
|
* A class that dispatches custom events.
|
|
5
15
|
*
|
|
6
16
|
* @category SDK
|
|
7
17
|
* @subcategory Internal
|
|
18
|
+
* @param {DispatcherOptions} options - The options that can be used
|
|
8
19
|
*/
|
|
9
20
|
export declare class Dispatcher {
|
|
10
21
|
_dispatchEvent: any;
|
|
11
22
|
_sessionState: SessionState;
|
|
23
|
+
constructor(options: DispatcherOptions);
|
|
12
24
|
/**
|
|
13
25
|
* Dispatches a custom event.
|
|
14
26
|
*
|
|
@@ -42,3 +54,4 @@ export declare class Dispatcher {
|
|
|
42
54
|
*/
|
|
43
55
|
dispatchAuthFlowCompletedEvent(detail: AuthFlowCompletedDetail): void;
|
|
44
56
|
}
|
|
57
|
+
export {};
|
|
@@ -2,18 +2,31 @@ import { Listener } from "./Listener";
|
|
|
2
2
|
import { Scheduler } from "./Scheduler";
|
|
3
3
|
import { Dispatcher } from "./Dispatcher";
|
|
4
4
|
import { Session } from "../Session";
|
|
5
|
+
/**
|
|
6
|
+
* Options for Relay
|
|
7
|
+
*
|
|
8
|
+
* @category SDK
|
|
9
|
+
* @subcategory Internal
|
|
10
|
+
* @property {string} cookieName - The name of the session cookie set from the SDK.
|
|
11
|
+
* @property {string} localStorageKey - The prefix / name of the local storage keys.
|
|
12
|
+
*/
|
|
13
|
+
interface RelayOptions {
|
|
14
|
+
cookieName: string;
|
|
15
|
+
localStorageKey: string;
|
|
16
|
+
}
|
|
5
17
|
/**
|
|
6
18
|
* A class that dispatches events and scheduled events, based on other events.
|
|
7
19
|
*
|
|
8
20
|
* @category SDK
|
|
9
21
|
* @subcategory Internal
|
|
10
22
|
* @extends Dispatcher
|
|
23
|
+
* @param {RelayOptions} options - The options that can be used
|
|
11
24
|
*/
|
|
12
25
|
export declare class Relay extends Dispatcher {
|
|
13
26
|
_listener: Listener;
|
|
14
27
|
_scheduler: Scheduler;
|
|
15
28
|
_session: Session;
|
|
16
|
-
constructor();
|
|
29
|
+
constructor(options: RelayOptions);
|
|
17
30
|
/**
|
|
18
31
|
* Removes the scheduled "hanko-session-expired" event and re-schedules a new event with updated expirationSeconds, to
|
|
19
32
|
* ensure the "hanko-session-expired" event won't be triggered too early.
|
|
@@ -45,3 +58,4 @@ export declare class Relay extends Dispatcher {
|
|
|
45
58
|
*/
|
|
46
59
|
private listenEventDependencies;
|
|
47
60
|
}
|
|
61
|
+
export {};
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { State } from "../State";
|
|
2
|
+
/**
|
|
3
|
+
* Options for SessionState
|
|
4
|
+
*
|
|
5
|
+
* @category SDK
|
|
6
|
+
* @subcategory Internal
|
|
7
|
+
* @property {string} localStorageKey - The prefix / name of the local storage keys.
|
|
8
|
+
*/
|
|
9
|
+
interface SessionStateOptions {
|
|
10
|
+
localStorageKey: string;
|
|
11
|
+
}
|
|
2
12
|
/**
|
|
3
13
|
* @interface
|
|
4
14
|
* @category SDK
|
|
@@ -14,12 +24,12 @@ export interface LocalStorageSession {
|
|
|
14
24
|
* A class to read and write local storage contents regarding sessions.
|
|
15
25
|
*
|
|
16
26
|
* @extends State
|
|
17
|
-
* @param {
|
|
27
|
+
* @param {SessionStateOptions} options - The options that can be used
|
|
18
28
|
* @category SDK
|
|
19
29
|
* @subcategory Internal
|
|
20
30
|
*/
|
|
21
31
|
declare class SessionState extends State {
|
|
22
|
-
constructor();
|
|
32
|
+
constructor(options: SessionStateOptions);
|
|
23
33
|
/**
|
|
24
34
|
* Reads the current state.
|
|
25
35
|
*
|
package/dist/sdk.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,r(e,t)}function t(e){return t=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},t(e)}function r(e,t){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},r(e,t)}function n(e,t,i){return n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}()?Reflect.construct.bind():function(e,t,n){var i=[null];i.push.apply(i,t);var o=new(Function.bind.apply(e,i));return n&&r(o,n.prototype),o},n.apply(null,arguments)}function i(e){var o="function"==typeof Map?new Map:void 0;return i=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==o){if(o.has(e))return o.get(e);o.set(e,i)}function i(){return n(e,arguments,t(this).constructor)}return i.prototype=Object.create(e.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),r(i,e)},i(e)}function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var s=/*#__PURE__*/function(t){function r(e,n,i){var s;return(s=t.call(this,e)||this).code=void 0,s.cause=void 0,s.code=n,s.cause=i,Object.setPrototypeOf(o(s),r.prototype),s}return e(r,t),r}(/*#__PURE__*/i(Error)),a=/*#__PURE__*/function(t){function r(e){var n;return n=t.call(this,"Technical error","somethingWentWrong",e)||this,Object.setPrototypeOf(o(n),r.prototype),n}return e(r,t),r}(s),c=/*#__PURE__*/function(t){function r(e,n){var i;return i=t.call(this,"Conflict error","conflict",n)||this,Object.setPrototypeOf(o(i),r.prototype),i}return e(r,t),r}(s),u=/*#__PURE__*/function(t){function r(e){var n;return n=t.call(this,"Request timed out error","requestTimeout",e)||this,Object.setPrototypeOf(o(n),r.prototype),n}return e(r,t),r}(s),h=/*#__PURE__*/function(t){function r(e){var n;return n=t.call(this,"Request cancelled error","requestCancelled",e)||this,Object.setPrototypeOf(o(n),r.prototype),n}return e(r,t),r}(s),d=/*#__PURE__*/function(t){function r(e){var n;return n=t.call(this,"Invalid password error","invalidPassword",e)||this,Object.setPrototypeOf(o(n),r.prototype),n}return e(r,t),r}(s),l=/*#__PURE__*/function(t){function r(e){var n;return n=t.call(this,"Invalid Passcode error","invalidPasscode",e)||this,Object.setPrototypeOf(o(n),r.prototype),n}return e(r,t),r}(s),p=/*#__PURE__*/function(t){function r(e){var n;return n=t.call(this,"Invalid WebAuthn credential error","invalidWebauthnCredential",e)||this,Object.setPrototypeOf(o(n),r.prototype),n}return e(r,t),r}(s),f=/*#__PURE__*/function(t){function r(e){var n;return n=t.call(this,"Passcode expired error","passcodeExpired",e)||this,Object.setPrototypeOf(o(n),r.prototype),n}return e(r,t),r}(s),v=/*#__PURE__*/function(t){function r(e){var n;return n=t.call(this,"Maximum number of Passcode attempts reached error","passcodeAttemptsReached",e)||this,Object.setPrototypeOf(o(n),r.prototype),n}return e(r,t),r}(s),w=/*#__PURE__*/function(t){function r(e){var n;return n=t.call(this,"Not found error","notFound",e)||this,Object.setPrototypeOf(o(n),r.prototype),n}return e(r,t),r}(s),m=/*#__PURE__*/function(t){function r(e,n){var i;return(i=t.call(this,"Too many requests error","tooManyRequests",n)||this).retryAfter=void 0,i.retryAfter=e,Object.setPrototypeOf(o(i),r.prototype),i}return e(r,t),r}(s),y=/*#__PURE__*/function(t){function r(e){var n;return n=t.call(this,"Unauthorized error","unauthorized",e)||this,Object.setPrototypeOf(o(n),r.prototype),n}return e(r,t),r}(s),g=/*#__PURE__*/function(t){function r(e){var n;return n=t.call(this,"User verification error","userVerification",e)||this,Object.setPrototypeOf(o(n),r.prototype),n}return e(r,t),r}(s),E=/*#__PURE__*/function(t){function r(e){var n;return n=t.call(this,"Maximum number of email addresses reached error","maxNumOfEmailAddressesReached",e)||this,Object.setPrototypeOf(o(n),r.prototype),n}return e(r,t),r}(s),S=/*#__PURE__*/function(t){function r(e){var n;return n=t.call(this,"The email address already exists","emailAddressAlreadyExistsError",e)||this,Object.setPrototypeOf(o(n),r.prototype),n}return e(r,t),r}(s),P=/*#__PURE__*/function(t){function r(e,n){var i;return i=t.call(this,"An error occurred during third party sign up/sign in",e,n)||this,Object.setPrototypeOf(o(i),r.prototype),i}return e(r,t),r}(s),b=/*#__PURE__*/function(){function e(e){this.key=void 0,this.ls=void 0,this.key=e,this.ls={}}var t=e.prototype;return t.read=function(){var e;try{var t=localStorage.getItem(this.key),r=decodeURIComponent(decodeURI(window.atob(t)));e=JSON.parse(r)}catch(e){return this.ls={},this}return this.ls=e,this},t.write=function(){var e=JSON.stringify(this.ls),t=window.btoa(encodeURI(encodeURIComponent(e)));return localStorage.setItem(this.key,t),this},e.timeToRemainingSeconds=function(e){return void 0===e&&(e=0),e-Math.floor(Date.now()/1e3)},e.remainingSecondsToTime=function(e){return void 0===e&&(e=0),Math.floor(Date.now()/1e3)+e},e}(),x=/*#__PURE__*/function(t){function r(){return t.call(this,"hanko_session")||this}e(r,t);var n=r.prototype;return n.read=function(){return t.prototype.read.call(this),this},n.getState=function(){var e;return(e=this.ls).session||(e.session={expiry:0,userID:"",authFlowCompleted:!1}),this.ls.session},n.getExpirationSeconds=function(){return b.timeToRemainingSeconds(this.getState().expiry)},n.setExpirationSeconds=function(e){return this.getState().expiry=b.remainingSecondsToTime(e),this},n.getUserID=function(){return this.getState().userID},n.setUserID=function(e){return this.getState().userID=e,this},n.getAuthFlowCompleted=function(){return this.getState().authFlowCompleted},n.setAuthFlowCompleted=function(e){return this.getState().authFlowCompleted=e,this},n.reset=function(){var e=this.getState();return delete e.expiry,delete e.userID,this},r}(b),C=/*#__PURE__*/function(t){function r(){return t.call(this,"hanko")||this}return e(r,t),r.prototype.getUserState=function(e){var t;return(t=this.ls).users||(t.users={}),Object.prototype.hasOwnProperty.call(this.ls.users,e)||(this.ls.users[e]={}),this.ls.users[e]},r}(b),k=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}e(r,t);var n=r.prototype;return n.getState=function(e){var r;return(r=t.prototype.getUserState.call(this,e)).passcode||(r.passcode={})},n.read=function(){return t.prototype.read.call(this),this},n.getActiveID=function(e){return this.getState(e).id},n.setActiveID=function(e,t){return this.getState(e).id=t,this},n.getEmailID=function(e){return this.getState(e).emailID},n.setEmailID=function(e,t){return this.getState(e).emailID=t,this},n.reset=function(e){var t=this.getState(e);return delete t.id,delete t.ttl,delete t.resendAfter,delete t.emailID,this},n.getTTL=function(e){return b.timeToRemainingSeconds(this.getState(e).ttl)},n.setTTL=function(e,t){return this.getState(e).ttl=b.remainingSecondsToTime(t),this},n.getResendAfter=function(e){return b.timeToRemainingSeconds(this.getState(e).resendAfter)},n.setResendAfter=function(e,t){return this.getState(e).resendAfter=b.remainingSecondsToTime(t),this},r}(C),_="hanko-session-created",A="hanko-session-expired",O="hanko-user-logged-out",T="hanko-user-deleted",j="hanko-auth-flow-completed",R=/*#__PURE__*/function(t){function r(e,r){return t.call(this,e,{detail:r})||this}return e(r,t),r}(/*#__PURE__*/i(CustomEvent)),I=/*#__PURE__*/function(){function e(){this._dispatchEvent=document.dispatchEvent.bind(document),this._sessionState=new x}var t=e.prototype;return t.dispatch=function(e,t){this._dispatchEvent(new R(e,t))},t.dispatchSessionCreatedEvent=function(e){this.dispatch(_,e)},t.dispatchSessionExpiredEvent=function(){this.dispatch(A,null)},t.dispatchUserLoggedOutEvent=function(){this.dispatch(O,null)},t.dispatchUserDeletedEvent=function(){this.dispatch(T,null)},t.dispatchAuthFlowCompletedEvent=function(e){this._sessionState.read().setAuthFlowCompleted(!0).write(),this.dispatch(j,e)},e}();function D(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)e[n]=r[n]}return e}var L=function e(t,r){function n(e,n,i){if("undefined"!=typeof document){"number"==typeof(i=D({},r,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var o="";for(var s in i)i[s]&&(o+="; "+s,!0!==i[s]&&(o+="="+i[s].split(";")[0]));return document.cookie=e+"="+t.write(n,e)+o}}return Object.create({set:n,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var r=document.cookie?document.cookie.split("; "):[],n={},i=0;i<r.length;i++){var o=r[i].split("="),s=o.slice(1).join("=");try{var a=decodeURIComponent(o[0]);if(n[a]=t.read(s,a),e===a)break}catch(e){}}return e?n[e]:n}},remove:function(e,t){n(e,"",D({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,D({},this.attributes,t))},withConverter:function(t){return e(D({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"}),U=/*#__PURE__*/function(){function e(){this.authCookieName="hanko"}var t=e.prototype;return t.getAuthCookie=function(){return L.get(this.authCookieName)},t.setAuthCookie=function(e,t){void 0===t&&(t=!0),L.set(this.authCookieName,e,{secure:t})},t.removeAuthCookie=function(){L.remove(this.authCookieName)},e}(),N=/*#__PURE__*/function(){function e(e){this._xhr=void 0,this._xhr=e}return e.prototype.getResponseHeader=function(e){return this._xhr.getResponseHeader(e)},e}(),H=/*#__PURE__*/function(){function e(e){this.headers=void 0,this.ok=void 0,this.status=void 0,this.statusText=void 0,this.url=void 0,this._decodedJSON=void 0,this.xhr=void 0,this.headers=new N(e),this.ok=e.status>=200&&e.status<=299,this.status=e.status,this.statusText=e.statusText,this.url=e.responseURL,this.xhr=e}var t=e.prototype;return t.json=function(){return this._decodedJSON||(this._decodedJSON=JSON.parse(this.xhr.response)),this._decodedJSON},t.parseNumericHeader=function(e){var t=parseInt(this.headers.getResponseHeader(e),10);return isNaN(t)?0:t},e}(),W=/*#__PURE__*/function(){function e(e,t){void 0===t&&(t=13e3),this.timeout=void 0,this.api=void 0,this.sessionState=void 0,this.passcodeState=void 0,this.dispatcher=void 0,this.cookie=void 0,this.api=e,this.timeout=t,this.sessionState=new x,this.passcodeState=new k,this.dispatcher=new I,this.cookie=new U}var t=e.prototype;return t._fetch=function(e,t,r){void 0===r&&(r=new XMLHttpRequest);var n=this.api+e,i=this.timeout,o=this.cookie.getAuthCookie();return new Promise(function(e,s){r.open(t.method,n,!0),r.setRequestHeader("Accept","application/json"),r.setRequestHeader("Content-Type","application/json"),o&&r.setRequestHeader("Authorization","Bearer "+o),r.timeout=i,r.withCredentials=!0,r.onload=function(){var t=new H(r);e(t)},r.onerror=function(){s(new a)},r.ontimeout=function(){s(new u)},r.send(t.body?t.body.toString():null)})},t.processResponseHeadersOnLogin=function(e,t){var r="",n=0;if(t.xhr.getAllResponseHeaders().split("\r\n").forEach(function(e){var i=e.toLowerCase();i.startsWith("x-auth-token")?r=t.headers.getResponseHeader("X-Auth-Token"):i.startsWith("x-session-lifetime")&&(n=parseInt(t.headers.getResponseHeader("X-Session-Lifetime"),10))}),r){var i=!!this.api.match("^https://");this.cookie.setAuthCookie(r,i)}this.passcodeState.read().reset(e).write(),n>0&&(this.sessionState.read(),this.sessionState.setExpirationSeconds(n),this.sessionState.setUserID(e),this.sessionState.setAuthFlowCompleted(!1),this.sessionState.write(),this.dispatcher.dispatchSessionCreatedEvent({jwt:r,userID:e,expirationSeconds:n}))},t.get=function(e){return this._fetch(e,{method:"GET"})},t.post=function(e,t){return this._fetch(e,{method:"POST",body:JSON.stringify(t)})},t.put=function(e,t){return this._fetch(e,{method:"PUT",body:JSON.stringify(t)})},t.patch=function(e,t){return this._fetch(e,{method:"PATCH",body:JSON.stringify(t)})},t.delete=function(e){return this._fetch(e,{method:"DELETE"})},e}(),F=function(e,t){void 0===t&&(t=13e3),this.client=void 0,this.client=new W(e,t)},q=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}return e(r,t),r.prototype.get=function(){try{return Promise.resolve(this.client.get("/.well-known/config")).then(function(e){if(!e.ok)throw new a;return e.json()})}catch(e){return Promise.reject(e)}},r}(F),M=/*#__PURE__*/function(t){function r(e,r){var n;return void 0===r&&(r=13e3),(n=t.call(this,e,r)||this).state=void 0,n.state=new k,n}e(r,t);var n=r.prototype;return n.initialize=function(e,t,r){try{var n=this;n.state.read();var i=n.state.getTTL(e),o=n.state.getActiveID(e),s=n.state.getEmailID(e),c=n.state.getResendAfter(e);if(c>0)throw new m(c);if(!r&&i>0&&t===s)return Promise.resolve({id:o,ttl:i});var u={user_id:e};return t&&(u.email_id=t),Promise.resolve(n.client.post("/passcode/login/initialize",u)).then(function(r){if(429===r.status)throw c=r.parseNumericHeader("Retry-After"),n.state.setResendAfter(e,c).write(),new m(c);if(!r.ok)throw new a;var i=r.json();return n.state.setActiveID(e,i.id).setTTL(e,i.ttl),t&&n.state.setEmailID(e,t),n.state.write(),i})}catch(e){return Promise.reject(e)}},n.finalize=function(e,t){try{var r=this,n=r.state.read().getActiveID(e);if(r.state.getTTL(e)<=0)throw new f;return Promise.resolve(r.client.post("/passcode/login/finalize",{id:n,code:t})).then(function(t){if(401===t.status)throw new l;if(410===t.status)throw r.state.reset(e).write(),new v;if(!t.ok)throw new a;r.client.processResponseHeadersOnLogin(e,t)})}catch(e){return Promise.reject(e)}},n.getTTL=function(e){return this.state.read().getTTL(e)},n.getResendAfter=function(e){return this.state.read().getResendAfter(e)},r}(F),K=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}e(r,t);var n=r.prototype;return n.getState=function(e){var r;return(r=t.prototype.getUserState.call(this,e)).password||(r.password={})},n.read=function(){return t.prototype.read.call(this),this},n.getRetryAfter=function(e){return b.timeToRemainingSeconds(this.getState(e).retryAfter)},n.setRetryAfter=function(e,t){return this.getState(e).retryAfter=b.remainingSecondsToTime(t),this},r}(C),z=/*#__PURE__*/function(t){function r(e,r){var n;return void 0===r&&(r=13e3),(n=t.call(this,e,r)||this).passwordState=void 0,n.passcodeState=void 0,n.passwordState=new K,n.passcodeState=new k,n}e(r,t);var n=r.prototype;return n.login=function(e,t){try{var r=this;return Promise.resolve(r.client.post("/password/login",{user_id:e,password:t})).then(function(t){if(401===t.status)throw new d;if(429===t.status){var n=t.parseNumericHeader("Retry-After");throw r.passwordState.read().setRetryAfter(e,n).write(),new m(n)}if(!t.ok)throw new a;r.client.processResponseHeadersOnLogin(e,t)})}catch(e){return Promise.reject(e)}},n.update=function(e,t){try{var r=this;return Promise.resolve(r.client.put("/password",{user_id:e,password:t})).then(function(e){if(401===e.status)throw r.client.dispatcher.dispatchSessionExpiredEvent(),new y;if(!e.ok)throw new a})}catch(e){return Promise.reject(e)}},n.getRetryAfter=function(e){return this.passwordState.read().getRetryAfter(e)},r}(F),J=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}e(r,t);var n=r.prototype;return n.getInfo=function(e){try{return Promise.resolve(this.client.post("/user",{email:e})).then(function(e){if(404===e.status)throw new w;if(!e.ok)throw new a;return e.json()})}catch(e){return Promise.reject(e)}},n.create=function(e){try{var t=this;return Promise.resolve(t.client.post("/users",{email:e})).then(function(e){if(409===e.status)throw new c;if(!e.ok)throw new a;var r=e.json();return r&&r.user_id&&t.client.processResponseHeadersOnLogin(r.user_id,e),r})}catch(e){return Promise.reject(e)}},n.getCurrent=function(){try{var e=this;return Promise.resolve(e.client.get("/me")).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new y;if(!t.ok)throw new a;var r=t.json();return Promise.resolve(e.client.get("/users/"+r.id)).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new y;if(!t.ok)throw new a;return t.json()})})}catch(e){return Promise.reject(e)}},n.delete=function(){try{var e=this;return Promise.resolve(e.client.delete("/user")).then(function(t){if(t.ok)return e.client.cookie.removeAuthCookie(),e.client.sessionState.reset().write(),void e.client.dispatcher.dispatchUserDeletedEvent();if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new y;throw new a})}catch(e){return Promise.reject(e)}},n.logout=function(){try{var e=this;return Promise.resolve(e.client.post("/logout")).then(function(t){if(e.client.cookie.removeAuthCookie(),e.client.sessionState.reset().write(),e.client.dispatcher.dispatchUserLoggedOutEvent(),401===t.status);else if(!t.ok)throw new a})}catch(e){return Promise.reject(e)}},r}(F);function B(e){const t="==".slice(0,(4-e.length%4)%4),r=e.replace(/-/g,"+").replace(/_/g,"/")+t,n=atob(r),i=new ArrayBuffer(n.length),o=new Uint8Array(i);for(let e=0;e<n.length;e++)o[e]=n.charCodeAt(e);return i}function V(e){const t=new Uint8Array(e);let r="";for(const e of t)r+=String.fromCharCode(e);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var X="copy",G="convert";function $(e,t,r){if(t===X)return r;if(t===G)return e(r);if(t instanceof Array)return r.map(r=>$(e,t[0],r));if(t instanceof Object){const n={};for(const[i,o]of Object.entries(t)){if(o.derive){const e=o.derive(r);void 0!==e&&(r[i]=e)}if(i in r)n[i]=null!=r[i]?$(e,o.schema,r[i]):null;else if(o.required)throw new Error(`Missing key: ${i}`)}return n}}function Q(e,t){return{required:!0,schema:e,derive:t}}function Y(e){return{required:!0,schema:e}}function Z(e){return{required:!1,schema:e}}var ee={type:Y(X),id:Y(G),transports:Z(X)},te={appid:Z(X),appidExclude:Z(X),credProps:Z(X)},re={appid:Z(X),appidExclude:Z(X),credProps:Z(X)},ne={publicKey:Y({rp:Y(X),user:Y({id:Y(G),name:Y(X),displayName:Y(X)}),challenge:Y(G),pubKeyCredParams:Y(X),timeout:Z(X),excludeCredentials:Z([ee]),authenticatorSelection:Z(X),attestation:Z(X),extensions:Z(te)}),signal:Z(X)},ie={type:Y(X),id:Y(X),rawId:Y(G),authenticatorAttachment:Z(X),response:Y({clientDataJSON:Y(G),attestationObject:Y(G),transports:Q(X,e=>{var t;return(null==(t=e.getTransports)?void 0:t.call(e))||[]})}),clientExtensionResults:Q(re,e=>e.getClientExtensionResults())},oe={mediation:Z(X),publicKey:Y({challenge:Y(G),timeout:Z(X),rpId:Z(X),allowCredentials:Z([ee]),userVerification:Z(X),extensions:Z(te)}),signal:Z(X)},se={type:Y(X),id:Y(X),rawId:Y(G),authenticatorAttachment:Z(X),response:Y({clientDataJSON:Y(G),authenticatorData:Y(G),signature:Y(G),userHandle:Y(G)}),clientExtensionResults:Q(re,e=>e.getClientExtensionResults())};async function ae(e){const t=await navigator.credentials.create(function(e){return $(B,ne,e)}(e));return function(e){return $(V,ie,e)}(t)}async function ce(e){const t=await navigator.credentials.get(function(e){return $(B,oe,e)}(e));return function(e){return $(V,se,e)}(t)}var ue=/*#__PURE__*/function(){function e(){}return e.supported=function(){return!!(navigator.credentials&&navigator.credentials.create&&navigator.credentials.get&&window.PublicKeyCredential)},e.isPlatformAuthenticatorAvailable=function(){try{return this.supported()&&window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?Promise.resolve(window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()):Promise.resolve(!1)}catch(e){return Promise.reject(e)}},e.isSecurityKeySupported=function(){try{return void 0!==window.PublicKeyCredential&&window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported?Promise.resolve(window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported()):Promise.resolve(this.supported())}catch(e){return Promise.reject(e)}},e.isConditionalMediationAvailable=function(){try{return window.PublicKeyCredential&&window.PublicKeyCredential.isConditionalMediationAvailable?Promise.resolve(window.PublicKeyCredential.isConditionalMediationAvailable()):Promise.resolve(!1)}catch(e){return Promise.reject(e)}},e}(),he=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}e(r,t);var n=r.prototype;return n.getState=function(e){var r;return(r=t.prototype.getUserState.call(this,e)).webauthn||(r.webauthn={})},n.read=function(){return t.prototype.read.call(this),this},n.getCredentials=function(e){var t;return(t=this.getState(e)).credentials||(t.credentials=[])},n.addCredential=function(e,t){return this.getCredentials(e).push(t),this},n.matchCredentials=function(e,t){return this.getCredentials(e).filter(function(e){return t.find(function(t){return t.id===e})}).map(function(e){return{id:e}})},r}(C);function de(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var le=/*#__PURE__*/function(t){function r(e,r){var n;return void 0===r&&(r=13e3),(n=t.call(this,e,r)||this).webauthnState=void 0,n.passcodeState=void 0,n.controller=void 0,n._getCredential=ce,n._createCredential=ae,n.webauthnState=new he,n.passcodeState=new k,n}e(r,t);var n=r.prototype;return n.login=function(e,t){try{var r=this;return Promise.resolve(r.client.post("/webauthn/login/initialize",{user_id:e})).then(function(e){var n;function i(e){return n?e:Promise.resolve(r.client.post("/webauthn/login/finalize",o)).then(function(e){if(400===e.status||401===e.status)throw new p;if(!e.ok)throw new a;var t=e.json();return r.webauthnState.read().addCredential(t.user_id,t.credential_id).write(),r.client.processResponseHeadersOnLogin(t.user_id,e),t})}if(!e.ok)throw new a;var o,s=e.json();s.signal=r._createAbortSignal(),t&&(s.mediation="conditional");var c=de(function(){return Promise.resolve(r._getCredential(s)).then(function(e){o=e})},function(e){throw new h(e)});return c&&c.then?c.then(i):i(c)})}catch(e){return Promise.reject(e)}},n.register=function(){try{var e=this;return Promise.resolve(e.client.post("/webauthn/registration/initialize")).then(function(t){function r(t){return n.transports=n.response.transports,Promise.resolve(e.client.post("/webauthn/registration/finalize",n)).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new y;if(422===t.status)throw new g;if(!t.ok)throw new a;var r=t.json();e.webauthnState.read().addCredential(r.user_id,r.credential_id).write()})}if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new y;if(!t.ok)throw new a;var n,i=t.json();i.signal=e._createAbortSignal();var o=de(function(){return Promise.resolve(e._createCredential(i)).then(function(e){n=e})},function(e){throw new h(e)});return o&&o.then?o.then(r):r()})}catch(e){return Promise.reject(e)}},n.listCredentials=function(){try{var e=this;return Promise.resolve(e.client.get("/webauthn/credentials")).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new y;if(!t.ok)throw new a;return t.json()})}catch(e){return Promise.reject(e)}},n.updateCredential=function(e,t){try{var r=this;return Promise.resolve(r.client.patch("/webauthn/credentials/"+e,{name:t})).then(function(e){if(401===e.status)throw r.client.dispatcher.dispatchSessionExpiredEvent(),new y;if(!e.ok)throw new a})}catch(e){return Promise.reject(e)}},n.deleteCredential=function(e){try{var t=this;return Promise.resolve(t.client.delete("/webauthn/credentials/"+e)).then(function(e){if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new y;if(!e.ok)throw new a})}catch(e){return Promise.reject(e)}},n.shouldRegister=function(e){try{var t=ue.supported();if(!e.webauthn_credentials||!e.webauthn_credentials.length)return Promise.resolve(t);var r=this.webauthnState.read().matchCredentials(e.id,e.webauthn_credentials);return Promise.resolve(t&&!r.length)}catch(e){return Promise.reject(e)}},n._createAbortSignal=function(){return this.controller&&this.controller.abort(),this.controller=new AbortController,this.controller.signal},r}(F),pe=/*#__PURE__*/function(t){function r(){return t.apply(this,arguments)||this}e(r,t);var n=r.prototype;return n.list=function(){try{var e=this;return Promise.resolve(e.client.get("/emails")).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new y;if(!t.ok)throw new a;return t.json()})}catch(e){return Promise.reject(e)}},n.create=function(e){try{var t=this;return Promise.resolve(t.client.post("/emails",{address:e})).then(function(e){if(e.ok)return e.json();if(400===e.status)throw new S;if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new y;if(409===e.status)throw new E;throw new a})}catch(e){return Promise.reject(e)}},n.setPrimaryEmail=function(e){try{var t=this;return Promise.resolve(t.client.post("/emails/"+e+"/set_primary")).then(function(e){if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new y;if(!e.ok)throw new a})}catch(e){return Promise.reject(e)}},n.delete=function(e){try{var t=this;return Promise.resolve(t.client.delete("/emails/"+e)).then(function(e){if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new y;if(!e.ok)throw new a})}catch(e){return Promise.reject(e)}},r}(F),fe=/*#__PURE__*/function(t){function r(e,r){return void 0===r&&(r=13e3),t.call(this,e,r)||this}e(r,t);var n=r.prototype;return n.auth=function(e,t){try{var r=new URL("/thirdparty/auth",this.client.api);if(!e)throw new P("somethingWentWrong",new Error("provider missing from request"));if(!t)throw new P("somethingWentWrong",new Error("redirectTo missing from request"));return r.searchParams.append("provider",e),r.searchParams.append("redirect_to",t),window.location.assign(r.href),Promise.resolve()}catch(e){return Promise.reject(e)}},n.getError=function(){var e=new URLSearchParams(window.location.search),t=e.get("error"),r=e.get("error_description");if(t){var n="";switch(t){case"access_denied":n="thirdPartyAccessDenied";break;case"user_conflict":n="emailAddressAlreadyExistsError";break;case"multiple_accounts":n="thirdPartyMultipleAccounts";break;case"unverified_email":n="thirdPartyUnverifiedEmail";break;case"email_maxnum":n="maxNumOfEmailAddressesReached";break;default:n="somethingWentWrong"}return new P(n,new Error(r))}},r}(F),ve=/*#__PURE__*/function(t){function r(e,r){return void 0===r&&(r=13e3),t.call(this,e,r)||this}return e(r,t),r.prototype.validate=function(){try{var e=this,t=new URLSearchParams(window.location.search).get("hanko_token");return t?(window.history.replaceState(null,null,window.location.pathname),Promise.resolve(e.client.post("/token",{value:t})).then(function(t){if(!t.ok)throw new a;var r=t.json();e.client.processResponseHeadersOnLogin(r.user_id,t)})):Promise.resolve()}catch(e){return Promise.reject(e)}},r}(F),we=/*#__PURE__*/function(){function e(){}return e.throttle=function(e,t,r){void 0===r&&(r={});var n,i,o,s=r.leading,a=void 0===s||s,c=r.trailing,u=void 0===c||c,h=0,d=function(){h=!1===a?0:Date.now(),o=null,e.apply(n,i)};return function(){var r=Date.now();h||!1!==a||(h=r);var s=t-(r-h);n=this,i=[].slice.call(arguments),s<=0||s>t?(o&&(window.clearTimeout(o),o=null),h=r,e.apply(n,i)):o||!1===u||(o=window.setTimeout(d,s))}},e}(),me=/*#__PURE__*/function(){function e(){this.throttleLimit=1e3,this._addEventListener=document.addEventListener.bind(document),this._removeEventListener=document.removeEventListener.bind(document),this._throttle=we.throttle}var t=e.prototype;return t.wrapCallback=function(e,t){var r=function(t){e(t.detail)};return t?this._throttle(r,this.throttleLimit,{leading:!0,trailing:!1}):r},t.addEventListenerWithType=function(e){var t=this,r=e.type,n=e.once,i=void 0!==n&&n,o=e.throttle,s=this.wrapCallback(e.callback,void 0!==o&&o);return this._addEventListener(r,s,{once:i}),function(){return t._removeEventListener(r,s)}},e.mapAddEventListenerParams=function(e,t,r){return{type:e,callback:t.callback,once:t.once,throttle:r}},t.addEventListener=function(t,r,n){return this.addEventListenerWithType(e.mapAddEventListenerParams(t,r,n))},t.onSessionCreated=function(e,t){return this.addEventListener(_,{callback:e,once:t},!0)},t.onSessionExpired=function(e,t){return this.addEventListener(A,{callback:e,once:t},!0)},t.onUserLoggedOut=function(e,t){return this.addEventListener(O,{callback:e,once:t})},t.onUserDeleted=function(e,t){return this.addEventListener(T,{callback:e,once:t})},t.onAuthFlowCompleted=function(e,t){return this.addEventListener(j,{callback:e,once:t})},e}(),ye=/*#__PURE__*/function(){function e(){this._tasks=[]}var t=e.prototype;return t.removeTask=function(e){window.clearTimeout(e.timeoutID),this._tasks=this._tasks.filter(function(t){return t!==e})},t.removeTasksWithType=function(e){var t=this;this._tasks.filter(function(t){return t.type===e}).forEach(function(e){return t.removeTask(e)})},t.scheduleTask=function(e,t,r){var n=this,i={timeoutID:window.setTimeout(function(){t(),n.removeTask(i)},1e3*r),type:e,func:t};this._tasks.push(i)},e}(),ge=/*#__PURE__*/function(){function e(){this._sessionState=void 0,this._cookie=void 0,this._sessionState=new x,this._cookie=new U}var t=e.prototype;return t.get=function(){var t=this._get();return e.validate(t)?t:null},t.isValid=function(){var t=this._get();return e.validate(t)},t._get=function(){return this._sessionState.read(),{userID:this._sessionState.getUserID(),expirationSeconds:this._sessionState.getExpirationSeconds(),jwt:this._cookie.getAuthCookie()}},t.isAuthFlowCompleted=function(){return this._sessionState.read(),this._sessionState.getAuthFlowCompleted()},e.validate=function(e){var t;return!!(e.expirationSeconds>0&&null!=(t=e.userID)&&t.length)},e}(),Ee=/*#__PURE__*/function(t){function r(){var e;return(e=t.call(this)||this)._listener=new me,e._scheduler=new ye,e._session=new ge,e.scheduleSessionExpiredEvent=function(t){e._scheduler.removeTasksWithType(A),e._scheduler.scheduleTask(A,function(){return e.dispatchSessionExpiredEvent()},t.expirationSeconds)},e.cancelSessionExpiredEvent=function(){e._scheduler.removeTasksWithType(A)},e.handleStorageEvent=function(t){if("hanko_session"===t.key){var r=e._session.get();r?e._session.isAuthFlowCompleted()?e.dispatchAuthFlowCompletedEvent({userID:r.userID}):e.dispatchSessionCreatedEvent(r):e.dispatchSessionExpiredEvent()}},e.listenEventDependencies(),e}return e(r,t),r.prototype.listenEventDependencies=function(){this._listener.onSessionCreated(this.scheduleSessionExpiredEvent),this._listener.onSessionExpired(this.cancelSessionExpiredEvent),this._listener.onUserDeleted(this.cancelSessionExpiredEvent),this._listener.onUserLoggedOut(this.cancelSessionExpiredEvent),window.addEventListener("storage",this.handleStorageEvent);var e=this._session.get();e&&this.scheduleSessionExpiredEvent(e)},r}(I),Se=/*#__PURE__*/function(t){function r(e,r){var n;return void 0===r&&(r=13e3),(n=t.call(this)||this).api=void 0,n.config=void 0,n.user=void 0,n.webauthn=void 0,n.password=void 0,n.passcode=void 0,n.email=void 0,n.thirdParty=void 0,n.token=void 0,n.relay=void 0,n.session=void 0,n.api=e,n.config=new q(e,r),n.user=new J(e,r),n.webauthn=new le(e,r),n.password=new z(e,r),n.passcode=new M(e,r),n.email=new pe(e,r),n.thirdParty=new fe(e,r),n.token=new ve(e,r),n.relay=new Ee,n.session=new ge,n}return e(r,t),r}(me);exports.ConfigClient=q,exports.ConflictError=c,exports.CustomEventWithDetail=R,exports.EmailAddressAlreadyExistsError=S,exports.EmailClient=pe,exports.Hanko=Se,exports.HankoError=s,exports.InvalidPasscodeError=l,exports.InvalidPasswordError=d,exports.InvalidWebauthnCredentialError=p,exports.MaxNumOfEmailAddressesReachedError=E,exports.MaxNumOfPasscodeAttemptsReachedError=v,exports.NotFoundError=w,exports.PasscodeClient=M,exports.PasscodeExpiredError=f,exports.PasswordClient=z,exports.RequestTimeoutError=u,exports.TechnicalError=a,exports.ThirdPartyClient=fe,exports.ThirdPartyError=P,exports.TokenClient=ve,exports.TooManyRequestsError=m,exports.UnauthorizedError=y,exports.UserClient=J,exports.UserVerificationError=g,exports.WebauthnClient=le,exports.WebauthnRequestCancelledError=h,exports.WebauthnSupport=ue,exports.authFlowCompletedType=j,exports.sessionCreatedType=_,exports.sessionExpiredType=A,exports.userDeletedType=T,exports.userLoggedOutType=O;
|
|
1
|
+
function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},e.apply(this,arguments)}function t(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,n(e,t)}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function i(e,t,r){return i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}()?Reflect.construct.bind():function(e,t,r){var i=[null];i.push.apply(i,t);var o=new(Function.bind.apply(e,i));return r&&n(o,r.prototype),o},i.apply(null,arguments)}function o(e){var t="function"==typeof Map?new Map:void 0;return o=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,o)}function o(){return i(e,arguments,r(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,e)},o(e)}function s(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var a=/*#__PURE__*/function(e){function r(t,n,i){var o;return(o=e.call(this,t)||this).code=void 0,o.cause=void 0,o.code=n,o.cause=i,Object.setPrototypeOf(s(o),r.prototype),o}return t(r,e),r}(/*#__PURE__*/o(Error)),c=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Technical error","somethingWentWrong",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),u=/*#__PURE__*/function(e){function r(t,n){var i;return i=e.call(this,"Conflict error","conflict",n)||this,Object.setPrototypeOf(s(i),r.prototype),i}return t(r,e),r}(a),h=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Request timed out error","requestTimeout",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),d=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Request cancelled error","requestCancelled",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),l=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Invalid password error","invalidPassword",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),p=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Invalid Passcode error","invalidPasscode",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),f=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Invalid WebAuthn credential error","invalidWebauthnCredential",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),v=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Passcode expired error","passcodeExpired",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),w=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Maximum number of Passcode attempts reached error","passcodeAttemptsReached",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),m=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Not found error","notFound",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),y=/*#__PURE__*/function(e){function r(t,n){var i;return(i=e.call(this,"Too many requests error","tooManyRequests",n)||this).retryAfter=void 0,i.retryAfter=t,Object.setPrototypeOf(s(i),r.prototype),i}return t(r,e),r}(a),g=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Unauthorized error","unauthorized",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),S=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"User verification error","userVerification",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),E=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Maximum number of email addresses reached error","maxNumOfEmailAddressesReached",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),P=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"The email address already exists","emailAddressAlreadyExistsError",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),b=/*#__PURE__*/function(e){function r(t,n){var i;return i=e.call(this,"An error occurred during third party sign up/sign in",t,n)||this,Object.setPrototypeOf(s(i),r.prototype),i}return t(r,e),r}(a),x=/*#__PURE__*/function(){function e(e){this.key=void 0,this.ls=void 0,this.key=e,this.ls={}}var t=e.prototype;return t.read=function(){var e;try{var t=localStorage.getItem(this.key),r=decodeURIComponent(decodeURI(window.atob(t)));e=JSON.parse(r)}catch(e){return this.ls={},this}return this.ls=e,this},t.write=function(){var e=JSON.stringify(this.ls),t=window.btoa(encodeURI(encodeURIComponent(e)));return localStorage.setItem(this.key,t),this},e.timeToRemainingSeconds=function(e){return void 0===e&&(e=0),e-Math.floor(Date.now()/1e3)},e.remainingSecondsToTime=function(e){return void 0===e&&(e=0),Math.floor(Date.now()/1e3)+e},e}(),k=/*#__PURE__*/function(e){function r(t){return e.call(this,t.localStorageKey+"_session")||this}t(r,e);var n=r.prototype;return n.read=function(){return e.prototype.read.call(this),this},n.getState=function(){var e;return(e=this.ls).session||(e.session={expiry:0,userID:"",authFlowCompleted:!1}),this.ls.session},n.getExpirationSeconds=function(){return x.timeToRemainingSeconds(this.getState().expiry)},n.setExpirationSeconds=function(e){return this.getState().expiry=x.remainingSecondsToTime(e),this},n.getUserID=function(){return this.getState().userID},n.setUserID=function(e){return this.getState().userID=e,this},n.getAuthFlowCompleted=function(){return this.getState().authFlowCompleted},n.setAuthFlowCompleted=function(e){return this.getState().authFlowCompleted=e,this},n.reset=function(){var e=this.getState();return delete e.expiry,delete e.userID,this},r}(x),C=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}return t(r,e),r.prototype.getUserState=function(e){var t;return(t=this.ls).users||(t.users={}),Object.prototype.hasOwnProperty.call(this.ls.users,e)||(this.ls.users[e]={}),this.ls.users[e]},r}(x),_=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.getState=function(t){var r;return(r=e.prototype.getUserState.call(this,t)).passcode||(r.passcode={})},n.read=function(){return e.prototype.read.call(this),this},n.getActiveID=function(e){return this.getState(e).id},n.setActiveID=function(e,t){return this.getState(e).id=t,this},n.getEmailID=function(e){return this.getState(e).emailID},n.setEmailID=function(e,t){return this.getState(e).emailID=t,this},n.reset=function(e){var t=this.getState(e);return delete t.id,delete t.ttl,delete t.resendAfter,delete t.emailID,this},n.getTTL=function(e){return x.timeToRemainingSeconds(this.getState(e).ttl)},n.setTTL=function(e,t){return this.getState(e).ttl=x.remainingSecondsToTime(t),this},n.getResendAfter=function(e){return x.timeToRemainingSeconds(this.getState(e).resendAfter)},n.setResendAfter=function(e,t){return this.getState(e).resendAfter=x.remainingSecondsToTime(t),this},r}(C),A="hanko-session-created",O="hanko-session-expired",j="hanko-user-logged-out",T="hanko-user-deleted",R="hanko-auth-flow-completed",I=/*#__PURE__*/function(e){function r(t,r){return e.call(this,t,{detail:r})||this}return t(r,e),r}(/*#__PURE__*/o(CustomEvent)),D=/*#__PURE__*/function(){function t(t){this._dispatchEvent=document.dispatchEvent.bind(document),this._sessionState=void 0,this._sessionState=new k(e({},t))}var r=t.prototype;return r.dispatch=function(e,t){this._dispatchEvent(new I(e,t))},r.dispatchSessionCreatedEvent=function(e){this.dispatch(A,e)},r.dispatchSessionExpiredEvent=function(){this.dispatch(O,null)},r.dispatchUserLoggedOutEvent=function(){this.dispatch(j,null)},r.dispatchUserDeletedEvent=function(){this.dispatch(T,null)},r.dispatchAuthFlowCompletedEvent=function(e){this._sessionState.read().setAuthFlowCompleted(!0).write(),this.dispatch(R,e)},t}();function L(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)e[n]=r[n]}return e}var U=function e(t,r){function n(e,n,i){if("undefined"!=typeof document){"number"==typeof(i=L({},r,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var o="";for(var s in i)i[s]&&(o+="; "+s,!0!==i[s]&&(o+="="+i[s].split(";")[0]));return document.cookie=e+"="+t.write(n,e)+o}}return Object.create({set:n,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var r=document.cookie?document.cookie.split("; "):[],n={},i=0;i<r.length;i++){var o=r[i].split("="),s=o.slice(1).join("=");try{var a=decodeURIComponent(o[0]);if(n[a]=t.read(s,a),e===a)break}catch(e){}}return e?n[e]:n}},remove:function(e,t){n(e,"",L({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,L({},this.attributes,t))},withConverter:function(t){return e(L({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"}),N=/*#__PURE__*/function(){function e(e){this.authCookieName=void 0,this.authCookieName=e.cookieName}var t=e.prototype;return t.getAuthCookie=function(){return U.get(this.authCookieName)},t.setAuthCookie=function(e,t){void 0===t&&(t=!0),U.set(this.authCookieName,e,{secure:t})},t.removeAuthCookie=function(){U.remove(this.authCookieName)},e}(),H=/*#__PURE__*/function(){function e(e){this._xhr=void 0,this._xhr=e}return e.prototype.getResponseHeader=function(e){return this._xhr.getResponseHeader(e)},e}(),W=/*#__PURE__*/function(){function e(e){this.headers=void 0,this.ok=void 0,this.status=void 0,this.statusText=void 0,this.url=void 0,this._decodedJSON=void 0,this.xhr=void 0,this.headers=new H(e),this.ok=e.status>=200&&e.status<=299,this.status=e.status,this.statusText=e.statusText,this.url=e.responseURL,this.xhr=e}var t=e.prototype;return t.json=function(){return this._decodedJSON||(this._decodedJSON=JSON.parse(this.xhr.response)),this._decodedJSON},t.parseNumericHeader=function(e){var t=parseInt(this.headers.getResponseHeader(e),10);return isNaN(t)?0:t},e}(),F=/*#__PURE__*/function(){function t(t,r){this.timeout=void 0,this.api=void 0,this.sessionState=void 0,this.passcodeState=void 0,this.dispatcher=void 0,this.cookie=void 0,this.api=t,this.timeout=r.timeout,this.sessionState=new k(e({},r)),this.passcodeState=new _(r.cookieName),this.dispatcher=new D(e({},r)),this.cookie=new N(e({},r))}var r=t.prototype;return r._fetch=function(e,t,r){void 0===r&&(r=new XMLHttpRequest);var n=this.api+e,i=this.timeout,o=this.cookie.getAuthCookie();return new Promise(function(e,s){r.open(t.method,n,!0),r.setRequestHeader("Accept","application/json"),r.setRequestHeader("Content-Type","application/json"),o&&r.setRequestHeader("Authorization","Bearer "+o),r.timeout=i,r.withCredentials=!0,r.onload=function(){var t=new W(r);e(t)},r.onerror=function(){s(new c)},r.ontimeout=function(){s(new h)},r.send(t.body?t.body.toString():null)})},r.processResponseHeadersOnLogin=function(e,t){var r="",n=0;if(t.xhr.getAllResponseHeaders().split("\r\n").forEach(function(e){var i=e.toLowerCase();i.startsWith("x-auth-token")?r=t.headers.getResponseHeader("X-Auth-Token"):i.startsWith("x-session-lifetime")&&(n=parseInt(t.headers.getResponseHeader("X-Session-Lifetime"),10))}),r){var i=!!this.api.match("^https://");this.cookie.setAuthCookie(r,i)}this.passcodeState.read().reset(e).write(),n>0&&(this.sessionState.read(),this.sessionState.setExpirationSeconds(n),this.sessionState.setUserID(e),this.sessionState.setAuthFlowCompleted(!1),this.sessionState.write(),this.dispatcher.dispatchSessionCreatedEvent({jwt:r,userID:e,expirationSeconds:n}))},r.get=function(e){return this._fetch(e,{method:"GET"})},r.post=function(e,t){return this._fetch(e,{method:"POST",body:JSON.stringify(t)})},r.put=function(e,t){return this._fetch(e,{method:"PUT",body:JSON.stringify(t)})},r.patch=function(e,t){return this._fetch(e,{method:"PATCH",body:JSON.stringify(t)})},r.delete=function(e){return this._fetch(e,{method:"DELETE"})},t}(),K=function(e,t){this.client=void 0,this.client=new F(e,t)},q=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}return t(r,e),r.prototype.get=function(){try{return Promise.resolve(this.client.get("/.well-known/config")).then(function(e){if(!e.ok)throw new c;return e.json()})}catch(e){return Promise.reject(e)}},r}(K),M=/*#__PURE__*/function(e){function r(t,r){var n;return(n=e.call(this,t,r)||this).state=void 0,n.state=new _(r.cookieName),n}t(r,e);var n=r.prototype;return n.initialize=function(e,t,r){try{var n=this;n.state.read();var i=n.state.getTTL(e),o=n.state.getActiveID(e),s=n.state.getEmailID(e),a=n.state.getResendAfter(e);if(a>0)throw new y(a);if(!r&&i>0&&t===s)return Promise.resolve({id:o,ttl:i});var u={user_id:e};return t&&(u.email_id=t),Promise.resolve(n.client.post("/passcode/login/initialize",u)).then(function(r){if(429===r.status)throw a=r.parseNumericHeader("Retry-After"),n.state.setResendAfter(e,a).write(),new y(a);if(!r.ok)throw new c;var i=r.json();return n.state.setActiveID(e,i.id).setTTL(e,i.ttl),t&&n.state.setEmailID(e,t),n.state.write(),i})}catch(e){return Promise.reject(e)}},n.finalize=function(e,t){try{var r=this,n=r.state.read().getActiveID(e);if(r.state.getTTL(e)<=0)throw new v;return Promise.resolve(r.client.post("/passcode/login/finalize",{id:n,code:t})).then(function(t){if(401===t.status)throw new p;if(410===t.status)throw r.state.reset(e).write(),new w;if(!t.ok)throw new c;r.client.processResponseHeadersOnLogin(e,t)})}catch(e){return Promise.reject(e)}},n.getTTL=function(e){return this.state.read().getTTL(e)},n.getResendAfter=function(e){return this.state.read().getResendAfter(e)},r}(K),z=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.getState=function(t){var r;return(r=e.prototype.getUserState.call(this,t)).password||(r.password={})},n.read=function(){return e.prototype.read.call(this),this},n.getRetryAfter=function(e){return x.timeToRemainingSeconds(this.getState(e).retryAfter)},n.setRetryAfter=function(e,t){return this.getState(e).retryAfter=x.remainingSecondsToTime(t),this},r}(C),J=/*#__PURE__*/function(e){function r(t,r){var n;return(n=e.call(this,t,r)||this).passwordState=void 0,n.passcodeState=void 0,n.passwordState=new z(r.cookieName),n.passcodeState=new _(r.cookieName),n}t(r,e);var n=r.prototype;return n.login=function(e,t){try{var r=this;return Promise.resolve(r.client.post("/password/login",{user_id:e,password:t})).then(function(t){if(401===t.status)throw new l;if(429===t.status){var n=t.parseNumericHeader("Retry-After");throw r.passwordState.read().setRetryAfter(e,n).write(),new y(n)}if(!t.ok)throw new c;r.client.processResponseHeadersOnLogin(e,t)})}catch(e){return Promise.reject(e)}},n.update=function(e,t){try{var r=this;return Promise.resolve(r.client.put("/password",{user_id:e,password:t})).then(function(e){if(401===e.status)throw r.client.dispatcher.dispatchSessionExpiredEvent(),new g;if(!e.ok)throw new c})}catch(e){return Promise.reject(e)}},n.getRetryAfter=function(e){return this.passwordState.read().getRetryAfter(e)},r}(K),B=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.getInfo=function(e){try{return Promise.resolve(this.client.post("/user",{email:e})).then(function(e){if(404===e.status)throw new m;if(!e.ok)throw new c;return e.json()})}catch(e){return Promise.reject(e)}},n.create=function(e){try{var t=this;return Promise.resolve(t.client.post("/users",{email:e})).then(function(e){if(409===e.status)throw new u;if(!e.ok)throw new c;var r=e.json();return r&&r.user_id&&t.client.processResponseHeadersOnLogin(r.user_id,e),r})}catch(e){return Promise.reject(e)}},n.getCurrent=function(){try{var e=this;return Promise.resolve(e.client.get("/me")).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new g;if(!t.ok)throw new c;var r=t.json();return Promise.resolve(e.client.get("/users/"+r.id)).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new g;if(!t.ok)throw new c;return t.json()})})}catch(e){return Promise.reject(e)}},n.delete=function(){try{var e=this;return Promise.resolve(e.client.delete("/user")).then(function(t){if(t.ok)return e.client.cookie.removeAuthCookie(),e.client.sessionState.reset().write(),void e.client.dispatcher.dispatchUserDeletedEvent();if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new g;throw new c})}catch(e){return Promise.reject(e)}},n.logout=function(){try{var e=this;return Promise.resolve(e.client.post("/logout")).then(function(t){if(e.client.cookie.removeAuthCookie(),e.client.sessionState.reset().write(),e.client.dispatcher.dispatchUserLoggedOutEvent(),401===t.status);else if(!t.ok)throw new c})}catch(e){return Promise.reject(e)}},r}(K);function V(e){const t="==".slice(0,(4-e.length%4)%4),r=e.replace(/-/g,"+").replace(/_/g,"/")+t,n=atob(r),i=new ArrayBuffer(n.length),o=new Uint8Array(i);for(let e=0;e<n.length;e++)o[e]=n.charCodeAt(e);return i}function X(e){const t=new Uint8Array(e);let r="";for(const e of t)r+=String.fromCharCode(e);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var G="copy",$="convert";function Q(e,t,r){if(t===G)return r;if(t===$)return e(r);if(t instanceof Array)return r.map(r=>Q(e,t[0],r));if(t instanceof Object){const n={};for(const[i,o]of Object.entries(t)){if(o.derive){const e=o.derive(r);void 0!==e&&(r[i]=e)}if(i in r)n[i]=null!=r[i]?Q(e,o.schema,r[i]):null;else if(o.required)throw new Error(`Missing key: ${i}`)}return n}}function Y(e,t){return{required:!0,schema:e,derive:t}}function Z(e){return{required:!0,schema:e}}function ee(e){return{required:!1,schema:e}}var te={type:Z(G),id:Z($),transports:ee(G)},re={appid:ee(G),appidExclude:ee(G),credProps:ee(G)},ne={appid:ee(G),appidExclude:ee(G),credProps:ee(G)},ie={publicKey:Z({rp:Z(G),user:Z({id:Z($),name:Z(G),displayName:Z(G)}),challenge:Z($),pubKeyCredParams:Z(G),timeout:ee(G),excludeCredentials:ee([te]),authenticatorSelection:ee(G),attestation:ee(G),extensions:ee(re)}),signal:ee(G)},oe={type:Z(G),id:Z(G),rawId:Z($),authenticatorAttachment:ee(G),response:Z({clientDataJSON:Z($),attestationObject:Z($),transports:Y(G,e=>{var t;return(null==(t=e.getTransports)?void 0:t.call(e))||[]})}),clientExtensionResults:Y(ne,e=>e.getClientExtensionResults())},se={mediation:ee(G),publicKey:Z({challenge:Z($),timeout:ee(G),rpId:ee(G),allowCredentials:ee([te]),userVerification:ee(G),extensions:ee(re)}),signal:ee(G)},ae={type:Z(G),id:Z(G),rawId:Z($),authenticatorAttachment:ee(G),response:Z({clientDataJSON:Z($),authenticatorData:Z($),signature:Z($),userHandle:Z($)}),clientExtensionResults:Y(ne,e=>e.getClientExtensionResults())};async function ce(e){const t=await navigator.credentials.create(function(e){return Q(V,ie,e)}(e));return function(e){return Q(X,oe,e)}(t)}async function ue(e){const t=await navigator.credentials.get(function(e){return Q(V,se,e)}(e));return function(e){return Q(X,ae,e)}(t)}var he=/*#__PURE__*/function(){function e(){}return e.supported=function(){return!!(navigator.credentials&&navigator.credentials.create&&navigator.credentials.get&&window.PublicKeyCredential)},e.isPlatformAuthenticatorAvailable=function(){try{return this.supported()&&window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?Promise.resolve(window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()):Promise.resolve(!1)}catch(e){return Promise.reject(e)}},e.isSecurityKeySupported=function(){try{return void 0!==window.PublicKeyCredential&&window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported?Promise.resolve(window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported()):Promise.resolve(this.supported())}catch(e){return Promise.reject(e)}},e.isConditionalMediationAvailable=function(){try{return window.PublicKeyCredential&&window.PublicKeyCredential.isConditionalMediationAvailable?Promise.resolve(window.PublicKeyCredential.isConditionalMediationAvailable()):Promise.resolve(!1)}catch(e){return Promise.reject(e)}},e}(),de=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.getState=function(t){var r;return(r=e.prototype.getUserState.call(this,t)).webauthn||(r.webauthn={})},n.read=function(){return e.prototype.read.call(this),this},n.getCredentials=function(e){var t;return(t=this.getState(e)).credentials||(t.credentials=[])},n.addCredential=function(e,t){return this.getCredentials(e).push(t),this},n.matchCredentials=function(e,t){return this.getCredentials(e).filter(function(e){return t.find(function(t){return t.id===e})}).map(function(e){return{id:e}})},r}(C);function le(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var pe=/*#__PURE__*/function(e){function r(t,r){var n;return(n=e.call(this,t,r)||this).webauthnState=void 0,n.passcodeState=void 0,n.controller=void 0,n._getCredential=ue,n._createCredential=ce,n.webauthnState=new de(r.cookieName),n.passcodeState=new _(r.cookieName),n}t(r,e);var n=r.prototype;return n.login=function(e,t){try{var r=this;return Promise.resolve(r.client.post("/webauthn/login/initialize",{user_id:e})).then(function(e){var n;function i(e){return n?e:Promise.resolve(r.client.post("/webauthn/login/finalize",o)).then(function(e){if(400===e.status||401===e.status)throw new f;if(!e.ok)throw new c;var t=e.json();return r.webauthnState.read().addCredential(t.user_id,t.credential_id).write(),r.client.processResponseHeadersOnLogin(t.user_id,e),t})}if(!e.ok)throw new c;var o,s=e.json();s.signal=r._createAbortSignal(),t&&(s.mediation="conditional");var a=le(function(){return Promise.resolve(r._getCredential(s)).then(function(e){o=e})},function(e){throw new d(e)});return a&&a.then?a.then(i):i(a)})}catch(e){return Promise.reject(e)}},n.register=function(){try{var e=this;return Promise.resolve(e.client.post("/webauthn/registration/initialize")).then(function(t){function r(t){return n.transports=n.response.transports,Promise.resolve(e.client.post("/webauthn/registration/finalize",n)).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new g;if(422===t.status)throw new S;if(!t.ok)throw new c;var r=t.json();e.webauthnState.read().addCredential(r.user_id,r.credential_id).write()})}if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new g;if(!t.ok)throw new c;var n,i=t.json();i.signal=e._createAbortSignal();var o=le(function(){return Promise.resolve(e._createCredential(i)).then(function(e){n=e})},function(e){throw new d(e)});return o&&o.then?o.then(r):r()})}catch(e){return Promise.reject(e)}},n.listCredentials=function(){try{var e=this;return Promise.resolve(e.client.get("/webauthn/credentials")).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new g;if(!t.ok)throw new c;return t.json()})}catch(e){return Promise.reject(e)}},n.updateCredential=function(e,t){try{var r=this;return Promise.resolve(r.client.patch("/webauthn/credentials/"+e,{name:t})).then(function(e){if(401===e.status)throw r.client.dispatcher.dispatchSessionExpiredEvent(),new g;if(!e.ok)throw new c})}catch(e){return Promise.reject(e)}},n.deleteCredential=function(e){try{var t=this;return Promise.resolve(t.client.delete("/webauthn/credentials/"+e)).then(function(e){if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new g;if(!e.ok)throw new c})}catch(e){return Promise.reject(e)}},n.shouldRegister=function(e){try{var t=he.supported();if(!e.webauthn_credentials||!e.webauthn_credentials.length)return Promise.resolve(t);var r=this.webauthnState.read().matchCredentials(e.id,e.webauthn_credentials);return Promise.resolve(t&&!r.length)}catch(e){return Promise.reject(e)}},n._createAbortSignal=function(){return this.controller&&this.controller.abort(),this.controller=new AbortController,this.controller.signal},r}(K),fe=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.list=function(){try{var e=this;return Promise.resolve(e.client.get("/emails")).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new g;if(!t.ok)throw new c;return t.json()})}catch(e){return Promise.reject(e)}},n.create=function(e){try{var t=this;return Promise.resolve(t.client.post("/emails",{address:e})).then(function(e){if(e.ok)return e.json();if(400===e.status)throw new P;if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new g;if(409===e.status)throw new E;throw new c})}catch(e){return Promise.reject(e)}},n.setPrimaryEmail=function(e){try{var t=this;return Promise.resolve(t.client.post("/emails/"+e+"/set_primary")).then(function(e){if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new g;if(!e.ok)throw new c})}catch(e){return Promise.reject(e)}},n.delete=function(e){try{var t=this;return Promise.resolve(t.client.delete("/emails/"+e)).then(function(e){if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new g;if(!e.ok)throw new c})}catch(e){return Promise.reject(e)}},r}(K),ve=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.auth=function(e,t){try{var r=new URL("/thirdparty/auth",this.client.api);if(!e)throw new b("somethingWentWrong",new Error("provider missing from request"));if(!t)throw new b("somethingWentWrong",new Error("redirectTo missing from request"));return r.searchParams.append("provider",e),r.searchParams.append("redirect_to",t),window.location.assign(r.href),Promise.resolve()}catch(e){return Promise.reject(e)}},n.getError=function(){var e=new URLSearchParams(window.location.search),t=e.get("error"),r=e.get("error_description");if(t){var n="";switch(t){case"access_denied":n="thirdPartyAccessDenied";break;case"user_conflict":n="emailAddressAlreadyExistsError";break;case"multiple_accounts":n="thirdPartyMultipleAccounts";break;case"unverified_email":n="thirdPartyUnverifiedEmail";break;case"email_maxnum":n="maxNumOfEmailAddressesReached";break;default:n="somethingWentWrong"}return new b(n,new Error(r))}},r}(K),we=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}return t(r,e),r.prototype.validate=function(){try{var e=this,t=new URLSearchParams(window.location.search).get("hanko_token");return t?(window.history.replaceState(null,null,window.location.pathname),Promise.resolve(e.client.post("/token",{value:t})).then(function(t){if(!t.ok)throw new c;var r=t.json();e.client.processResponseHeadersOnLogin(r.user_id,t)})):Promise.resolve()}catch(e){return Promise.reject(e)}},r}(K),me=/*#__PURE__*/function(){function e(){}return e.throttle=function(e,t,r){void 0===r&&(r={});var n,i,o,s=r.leading,a=void 0===s||s,c=r.trailing,u=void 0===c||c,h=0,d=function(){h=!1===a?0:Date.now(),o=null,e.apply(n,i)};return function(){var r=Date.now();h||!1!==a||(h=r);var s=t-(r-h);n=this,i=[].slice.call(arguments),s<=0||s>t?(o&&(window.clearTimeout(o),o=null),h=r,e.apply(n,i)):o||!1===u||(o=window.setTimeout(d,s))}},e}(),ye=/*#__PURE__*/function(){function e(){this.throttleLimit=1e3,this._addEventListener=document.addEventListener.bind(document),this._removeEventListener=document.removeEventListener.bind(document),this._throttle=me.throttle}var t=e.prototype;return t.wrapCallback=function(e,t){var r=function(t){e(t.detail)};return t?this._throttle(r,this.throttleLimit,{leading:!0,trailing:!1}):r},t.addEventListenerWithType=function(e){var t=this,r=e.type,n=e.once,i=void 0!==n&&n,o=e.throttle,s=this.wrapCallback(e.callback,void 0!==o&&o);return this._addEventListener(r,s,{once:i}),function(){return t._removeEventListener(r,s)}},e.mapAddEventListenerParams=function(e,t,r){return{type:e,callback:t.callback,once:t.once,throttle:r}},t.addEventListener=function(t,r,n){return this.addEventListenerWithType(e.mapAddEventListenerParams(t,r,n))},t.onSessionCreated=function(e,t){return this.addEventListener(A,{callback:e,once:t},!0)},t.onSessionExpired=function(e,t){return this.addEventListener(O,{callback:e,once:t},!0)},t.onUserLoggedOut=function(e,t){return this.addEventListener(j,{callback:e,once:t})},t.onUserDeleted=function(e,t){return this.addEventListener(T,{callback:e,once:t})},t.onAuthFlowCompleted=function(e,t){return this.addEventListener(R,{callback:e,once:t})},e}(),ge=/*#__PURE__*/function(){function e(){this._tasks=[]}var t=e.prototype;return t.removeTask=function(e){window.clearTimeout(e.timeoutID),this._tasks=this._tasks.filter(function(t){return t!==e})},t.removeTasksWithType=function(e){var t=this;this._tasks.filter(function(t){return t.type===e}).forEach(function(e){return t.removeTask(e)})},t.scheduleTask=function(e,t,r){var n=this,i={timeoutID:window.setTimeout(function(){t(),n.removeTask(i)},1e3*r),type:e,func:t};this._tasks.push(i)},e}(),Se=/*#__PURE__*/function(){function t(t){this._sessionState=void 0,this._cookie=void 0,this._sessionState=new k(e({},t)),this._cookie=new N(e({},t))}var r=t.prototype;return r.get=function(){var e=this._get();return t.validate(e)?e:null},r.isValid=function(){var e=this._get();return t.validate(e)},r._get=function(){return this._sessionState.read(),{userID:this._sessionState.getUserID(),expirationSeconds:this._sessionState.getExpirationSeconds(),jwt:this._cookie.getAuthCookie()}},r.isAuthFlowCompleted=function(){return this._sessionState.read(),this._sessionState.getAuthFlowCompleted()},t.validate=function(e){var t;return!!(e.expirationSeconds>0&&null!=(t=e.userID)&&t.length)},t}(),Ee=/*#__PURE__*/function(r){function n(t){var n;return(n=r.call(this,e({},t))||this)._listener=new ye,n._scheduler=new ge,n._session=void 0,n.scheduleSessionExpiredEvent=function(e){n._scheduler.removeTasksWithType(O),n._scheduler.scheduleTask(O,function(){return n.dispatchSessionExpiredEvent()},e.expirationSeconds)},n.cancelSessionExpiredEvent=function(){n._scheduler.removeTasksWithType(O)},n.handleStorageEvent=function(e){if("hanko_session"===e.key){var t=n._session.get();t?n._session.isAuthFlowCompleted()?n.dispatchAuthFlowCompletedEvent({userID:t.userID}):n.dispatchSessionCreatedEvent(t):n.dispatchSessionExpiredEvent()}},n._session=new Se(e({},t)),n.listenEventDependencies(),n}return t(n,r),n.prototype.listenEventDependencies=function(){this._listener.onSessionCreated(this.scheduleSessionExpiredEvent),this._listener.onSessionExpired(this.cancelSessionExpiredEvent),this._listener.onUserDeleted(this.cancelSessionExpiredEvent),this._listener.onUserLoggedOut(this.cancelSessionExpiredEvent),window.addEventListener("storage",this.handleStorageEvent);var e=this._session.get();e&&this.scheduleSessionExpiredEvent(e)},n}(D),Pe=/*#__PURE__*/function(r){function n(t,n){var i;(i=r.call(this)||this).api=void 0,i.config=void 0,i.user=void 0,i.webauthn=void 0,i.password=void 0,i.passcode=void 0,i.email=void 0,i.thirdParty=void 0,i.token=void 0,i.relay=void 0,i.session=void 0;var o={timeout:13e3,cookieName:"hanko",localStorageKey:"hanko"};return void 0!==(null==n?void 0:n.cookieName)&&(o.cookieName=n.cookieName),void 0!==(null==n?void 0:n.timeout)&&(o.timeout=n.timeout),void 0!==(null==n?void 0:n.localStorageKey)&&(o.localStorageKey=n.localStorageKey),i.api=t,i.config=new q(t,o),i.user=new B(t,o),i.webauthn=new pe(t,o),i.password=new J(t,o),i.passcode=new M(t,o),i.email=new fe(t,o),i.thirdParty=new ve(t,o),i.token=new we(t,o),i.relay=new Ee(e({},o)),i.session=new Se(e({},o)),i}return t(n,r),n}(ye);exports.ConfigClient=q,exports.ConflictError=u,exports.CustomEventWithDetail=I,exports.EmailAddressAlreadyExistsError=P,exports.EmailClient=fe,exports.Hanko=Pe,exports.HankoError=a,exports.InvalidPasscodeError=p,exports.InvalidPasswordError=l,exports.InvalidWebauthnCredentialError=f,exports.MaxNumOfEmailAddressesReachedError=E,exports.MaxNumOfPasscodeAttemptsReachedError=w,exports.NotFoundError=m,exports.PasscodeClient=M,exports.PasscodeExpiredError=v,exports.PasswordClient=J,exports.RequestTimeoutError=h,exports.TechnicalError=c,exports.ThirdPartyClient=ve,exports.ThirdPartyError=b,exports.TokenClient=we,exports.TooManyRequestsError=y,exports.UnauthorizedError=g,exports.UserClient=B,exports.UserVerificationError=S,exports.WebauthnClient=pe,exports.WebauthnRequestCancelledError=d,exports.WebauthnSupport=he,exports.authFlowCompletedType=R,exports.sessionCreatedType=A,exports.sessionExpiredType=O,exports.userDeletedType=T,exports.userLoggedOutType=j;
|
|
2
2
|
//# sourceMappingURL=sdk.cjs.map
|