@teamhanko/hanko-frontend-sdk 1.5.1 → 1.5.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/dist/Hanko.d.ts +5 -1
- package/dist/lib/SessionStorage.d.ts +38 -0
- package/dist/lib/client/HttpClient.d.ts +18 -0
- package/dist/lib/events/Relay.d.ts +14 -0
- 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 +1 -1
package/dist/Hanko.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ import { Listener } from "./lib/events/Listener";
|
|
|
7
7
|
import { Relay } from "./lib/events/Relay";
|
|
8
8
|
import { CookieSameSite } from "./lib/Cookie";
|
|
9
9
|
import { Flow } from "./lib/flow-api/Flow";
|
|
10
|
-
import {
|
|
10
|
+
import { Session, SessionClient } from "./lib/client/SessionClient";
|
|
11
|
+
import { SessionTokenLocation } from "./lib/client/HttpClient";
|
|
11
12
|
/**
|
|
12
13
|
* The options for the Hanko class
|
|
13
14
|
*
|
|
@@ -25,6 +26,7 @@ import { SessionClient, Session } from "./lib/client/SessionClient";
|
|
|
25
26
|
* reflected in the payload of the token contained in the webhook request.
|
|
26
27
|
* @property {number=} sessionCheckInterval - Interval for session validity checks in milliseconds. Must be greater than 3000 (3s), defaults to 3000 otherwise.
|
|
27
28
|
* @property {string=} sessionCheckChannelName - The broadcast channel name for inter-tab communication.
|
|
29
|
+
* @property {string=} sessionTokenLocation - The location where the session token is stored.
|
|
28
30
|
*/
|
|
29
31
|
export interface HankoOptions {
|
|
30
32
|
timeout?: number;
|
|
@@ -35,6 +37,7 @@ export interface HankoOptions {
|
|
|
35
37
|
lang?: string;
|
|
36
38
|
sessionCheckInterval?: number;
|
|
37
39
|
sessionCheckChannelName?: string;
|
|
40
|
+
sessionTokenLocation?: SessionTokenLocation;
|
|
38
41
|
}
|
|
39
42
|
/**
|
|
40
43
|
* A class that bundles all available SDK functions.
|
|
@@ -74,5 +77,6 @@ export interface InternalOptions {
|
|
|
74
77
|
lang?: string;
|
|
75
78
|
sessionCheckInterval?: number;
|
|
76
79
|
sessionCheckChannelName?: string;
|
|
80
|
+
sessionTokenLocation: SessionTokenLocation;
|
|
77
81
|
}
|
|
78
82
|
export { Hanko };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for SessionStorage
|
|
3
|
+
*
|
|
4
|
+
* @category SDK
|
|
5
|
+
* @subcategory Internal
|
|
6
|
+
* @property {string} keyName - The name of the sessionStorage session token entry set from the SDK.
|
|
7
|
+
*/
|
|
8
|
+
interface SessionStorageOptions {
|
|
9
|
+
keyName: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A class to manage sessionStorage.
|
|
13
|
+
*
|
|
14
|
+
* @category SDK
|
|
15
|
+
* @subcategory Internal
|
|
16
|
+
* @param {SessionStorageOptions} options - The options that can be used.
|
|
17
|
+
*/
|
|
18
|
+
export declare class SessionStorage {
|
|
19
|
+
keyName: string;
|
|
20
|
+
constructor(options: SessionStorageOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Return the session token that was stored in the sessionStorage.
|
|
23
|
+
*
|
|
24
|
+
* @return {string}
|
|
25
|
+
*/
|
|
26
|
+
getSessionToken(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Stores the session token in the sessionStorage.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} token - The session token to be stored.
|
|
31
|
+
*/
|
|
32
|
+
setSessionToken(token: string): void;
|
|
33
|
+
/**
|
|
34
|
+
* Removes the session token used for authentication.
|
|
35
|
+
*/
|
|
36
|
+
removeSessionToken(): void;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Dispatcher } from "../events/Dispatcher";
|
|
2
2
|
import { Cookie } from "../Cookie";
|
|
3
|
+
import { SessionStorage } from "../SessionStorage";
|
|
4
|
+
export type SessionTokenLocation = "cookie" | "sessionStorage";
|
|
3
5
|
/**
|
|
4
6
|
* This class wraps an XMLHttpRequest to maintain compatibility with the fetch API.
|
|
5
7
|
*
|
|
@@ -69,6 +71,7 @@ export interface HttpClientOptions {
|
|
|
69
71
|
cookieDomain?: string;
|
|
70
72
|
localStorageKey: string;
|
|
71
73
|
lang?: string;
|
|
74
|
+
sessionTokenLocation: SessionTokenLocation;
|
|
72
75
|
}
|
|
73
76
|
/**
|
|
74
77
|
* Internally used for communication with the Hanko API. It also handles authorization tokens to enable authorized
|
|
@@ -89,7 +92,9 @@ declare class HttpClient {
|
|
|
89
92
|
api: string;
|
|
90
93
|
dispatcher: Dispatcher;
|
|
91
94
|
cookie: Cookie;
|
|
95
|
+
sessionTokenStorage: SessionStorage;
|
|
92
96
|
lang: string;
|
|
97
|
+
sessionTokenLocation: SessionTokenLocation;
|
|
93
98
|
constructor(api: string, options: HttpClientOptions);
|
|
94
99
|
_fetch(path: string, options: RequestInit, xhr?: XMLHttpRequest): Promise<Response>;
|
|
95
100
|
_fetch_blocking(path: string, options: RequestInit, xhr?: XMLHttpRequest): string;
|
|
@@ -147,5 +152,18 @@ declare class HttpClient {
|
|
|
147
152
|
* @throws {TechnicalError}
|
|
148
153
|
*/
|
|
149
154
|
delete(path: string): Promise<Response>;
|
|
155
|
+
/**
|
|
156
|
+
* Returns the session token either from the cookie or the sessionStorage.
|
|
157
|
+
* @private
|
|
158
|
+
* @return {string}
|
|
159
|
+
*/
|
|
160
|
+
private getAuthToken;
|
|
161
|
+
/**
|
|
162
|
+
* Stores the session token either in a cookie or in the sessionStorage depending on the configuration.
|
|
163
|
+
* @param {string} token - The session token to be stored.
|
|
164
|
+
* @param {CookieAttributes} options - Options for setting the auth cookie.
|
|
165
|
+
* @private
|
|
166
|
+
*/
|
|
167
|
+
private setAuthToken;
|
|
150
168
|
}
|
|
151
169
|
export { Headers, Response, HttpClient };
|
|
@@ -63,4 +63,18 @@ export declare class Relay extends Dispatcher {
|
|
|
63
63
|
* @private
|
|
64
64
|
*/
|
|
65
65
|
private onChannelLeadershipRequested;
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves or generates the session check channel name based on the session token storage location.
|
|
68
|
+
*
|
|
69
|
+
* - If the `sessionTokenLocation` is `"cookie"`, the provided `sessionCheckChannelName` is returned as-is.
|
|
70
|
+
* - If the `sessionTokenLocation` is `"sessionStorage"`, the function attempts to retrieve the channel name from
|
|
71
|
+
* `sessionStorage`. If none is found, a new name is generated with the value of `sessionCheckChannelName` as a prefix and a random number,
|
|
72
|
+
* then stored in `sessionStorage` for future use.
|
|
73
|
+
*
|
|
74
|
+
* @param sessionTokenLocation - Indicates where the session token is stored, either `"cookie"` or `"sessionStorage"`.
|
|
75
|
+
* @param sessionCheckChannelName - The name or prefix used for the session check channel.
|
|
76
|
+
* @returns The resolved session check channel name, or `undefined` if not applicable.
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
private getSessionCheckChannelName;
|
|
66
80
|
}
|
package/dist/sdk.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},e.apply(this,arguments)}function t(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,r(e,t)}function n(e){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},n(e)}function r(e,t){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},r(e,t)}function i(e,t,n){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,n){var i=[null];i.push.apply(i,t);var o=new(Function.bind.apply(e,i));return n&&r(o,n.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,n(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),r(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=0;function c(e){return"__private_"+a+++"_"+e}function u(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var h=/*#__PURE__*/function(e){function n(t,r,i){var o;return(o=e.call(this,t)||this).code=void 0,o.cause=void 0,o.code=r,o.cause=i,Object.setPrototypeOf(s(o),n.prototype),o}return t(n,e),n}(/*#__PURE__*/o(Error)),l=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Technical error","somethingWentWrong",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),d=/*#__PURE__*/function(e){function n(t,r){var i;return i=e.call(this,"Conflict error","conflict",r)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),p=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Request timed out error","requestTimeout",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),f=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Request cancelled error","requestCancelled",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),v=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Invalid password error","invalidPassword",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),m=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Invalid Passcode error","invalidPasscode",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),y=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Invalid WebAuthn credential error","invalidWebauthnCredential",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),w=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Passcode expired error","passcodeExpired",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),g=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Maximum number of Passcode attempts reached error","passcodeAttemptsReached",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),k=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Not found error","notFound",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),E=/*#__PURE__*/function(e){function n(t,r){var i;return(i=e.call(this,"Too many requests error","tooManyRequests",r)||this).retryAfter=void 0,i.retryAfter=t,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),x=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Unauthorized error","unauthorized",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),b=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Forbidden error","forbidden",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),P=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"User verification error","userVerification",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),C=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Maximum number of email addresses reached error","maxNumOfEmailAddressesReached",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),S=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"The email address already exists","emailAddressAlreadyExistsError",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),O=/*#__PURE__*/function(e){function n(t,r){var i;return i=e.call(this,"An error occurred during third party sign up/sign in",t,r)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),j="hanko-session-created",_="hanko-session-expired",I="hanko-user-logged-out",A="hanko-user-deleted",L=/*#__PURE__*/function(e){function n(t,n){return e.call(this,t,{detail:n})||this}return t(n,e),n}(/*#__PURE__*/o(CustomEvent)),R=/*#__PURE__*/function(){function e(){this._dispatchEvent=document.dispatchEvent.bind(document)}var t=e.prototype;return t.dispatch=function(e,t){this._dispatchEvent(new L(e,t))},t.dispatchSessionCreatedEvent=function(e){this.dispatch(j,e)},t.dispatchSessionExpiredEvent=function(){this.dispatch(_,null)},t.dispatchUserLoggedOutEvent=function(){this.dispatch(I,null)},t.dispatchUserDeletedEvent=function(){this.dispatch(A,null)},e}();function D(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}var N,T=function e(t,n){function r(e,r,i){if("undefined"!=typeof document){"number"==typeof(i=D({},n,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(r,e)+o}}return Object.create({set:r,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var n=document.cookie?document.cookie.split("; "):[],r={},i=0;i<n.length;i++){var o=n[i].split("="),s=o.slice(1).join("=");try{var a=decodeURIComponent(o[0]);if(r[a]=t.read(s,a),e===a)break}catch(e){}}return e?r[e]:r}},remove:function(e,t){r(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(n)},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:"/"}),q=/*#__PURE__*/function(){function t(e){var t;this.authCookieName=void 0,this.authCookieDomain=void 0,this.authCookieSameSite=void 0,this.authCookieName=e.cookieName,this.authCookieDomain=e.cookieDomain,this.authCookieSameSite=null!=(t=e.cookieSameSite)?t:"lax"}var n=t.prototype;return n.getAuthCookie=function(){return T.get(this.authCookieName)},n.setAuthCookie=function(t,n){var r={secure:!0,sameSite:this.authCookieSameSite};void 0!==this.authCookieDomain&&(r.domain=this.authCookieDomain);var i=e({},r,n);if(("none"===i.sameSite||"None"===i.sameSite)&&!1===i.secure)throw new l(new Error("Secure attribute must be set when SameSite=None"));T.set(this.authCookieName,t,i)},n.removeAuthCookie=function(){T.remove(this.authCookieName)},t}(),U=/*#__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 U(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}(),M=/*#__PURE__*/function(){function t(t,n){this.timeout=void 0,this.api=void 0,this.dispatcher=void 0,this.cookie=void 0,this.lang=void 0,this.api=t,this.timeout=n.timeout,this.dispatcher=new R,this.cookie=new q(e({},n)),this.lang=n.lang}var n=t.prototype;return n._fetch=function(e,t,n){void 0===n&&(n=new XMLHttpRequest);var r=this,i=this.api+e,o=this.timeout,s=this.cookie.getAuthCookie(),a=this.lang;return new Promise(function(e,c){n.open(t.method,i,!0),n.setRequestHeader("Accept","application/json"),n.setRequestHeader("Content-Type","application/json"),n.setRequestHeader("X-Language",a),s&&n.setRequestHeader("Authorization","Bearer "+s),n.timeout=o,n.withCredentials=!0,n.onload=function(){r.processHeaders(n),e(new W(n))},n.onerror=function(){c(new l)},n.ontimeout=function(){c(new p)},n.send(t.body?t.body.toString():null)})},n._fetch_blocking=function(e,t,n){void 0===n&&(n=new XMLHttpRequest);var r=this.api+e,i=this.cookie.getAuthCookie();return n.open(t.method,r,!1),n.setRequestHeader("Accept","application/json"),n.setRequestHeader("Content-Type","application/json"),i&&n.setRequestHeader("Authorization","Bearer "+i),n.withCredentials=!0,n.send(t.body?t.body.toString():null),n.responseText},n.processHeaders=function(e){var t="",n=0,r="";if(e.getAllResponseHeaders().split("\r\n").forEach(function(i){var o=i.toLowerCase();o.startsWith("x-auth-token")?t=e.getResponseHeader("X-Auth-Token"):o.startsWith("x-session-lifetime")?n=parseInt(e.getResponseHeader("X-Session-Lifetime"),10):o.startsWith("x-session-retention")&&(r=e.getResponseHeader("X-Session-Retention"))}),t){var i=new RegExp("^https://"),o=!!this.api.match(i)&&!!window.location.href.match(i),s="session"===r?void 0:new Date((new Date).getTime()+1e3*n);this.cookie.setAuthCookie(t,{secure:o,expires:s})}},n.get=function(e){return this._fetch(e,{method:"GET"})},n.post=function(e,t){return this._fetch(e,{method:"POST",body:JSON.stringify(t)})},n.put=function(e,t){return this._fetch(e,{method:"PUT",body:JSON.stringify(t)})},n.patch=function(e,t){return this._fetch(e,{method:"PATCH",body:JSON.stringify(t)})},n.delete=function(e){return this._fetch(e,{method:"DELETE"})},t}(),H=function(e,t){this.client=void 0,this.client=new M(e,t)},K=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var r=n.prototype;return r.getDomain=function(e){if(!e)throw new O("somethingWentWrong",new Error("email missing from request"));var t=e.split("@");if(2!==t.length)throw new O("somethingWentWrong",new Error("email is not in a valid email format."));var n=t[1].trim();if(""===n)throw new O("somethingWentWrong",new Error("email is not in a valid email format."));return n},r.hasProvider=function(e){try{var t=this.getDomain(e);return Promise.resolve(this.client.get("/saml/provider?domain="+t).then(function(e){if(404==e.status)throw new k(new Error("provider not found"));if(!e.ok)throw new l(new Error("unable to fetch provider"));return e.ok}))}catch(e){return Promise.reject(e)}},r.auth=function(e,t){var n=new URL("/saml/auth",this.client.api),r=this.getDomain(e);if(!t)throw new O("somethingWentWrong",new Error("redirectTo missing from request"));n.searchParams.append("domain",r),n.searchParams.append("redirect_to",t),window.location.assign(n.href)},r.getError=function(){var e=new URLSearchParams(window.location.search),t=e.get("error"),n=e.get("error_description");if(t){var r;switch(t){case"access_denied":r="enterpriseAccessDenied";break;case"user_conflict":r="emailAddressAlreadyExistsError";break;case"multiple_accounts":r="enterpriseMultipleAccounts";break;case"unverified_email":r="enterpriseUnverifiedEmail";break;case"email_maxnum":r="maxNumOfEmailAddressesReached";break;default:r="somethingWentWrong"}return new O(r,new Error(n))}},n}(H),F=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var r=n.prototype;return r.getInfo=function(e){try{return Promise.resolve(this.client.post("/user",{email:e})).then(function(e){if(404===e.status)throw new k;if(!e.ok)throw new l;return e.json()})}catch(e){return Promise.reject(e)}},r.create=function(e){try{return Promise.resolve(this.client.post("/users",{email:e})).then(function(e){if(409===e.status)throw new d;if(403===e.status)throw new b;if(!e.ok)throw new l;return e.json()})}catch(e){return Promise.reject(e)}},r.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 x;if(!t.ok)throw new l;var n=t.json();return Promise.resolve(e.client.get("/users/"+n.id)).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new x;if(!t.ok)throw new l;return t.json()})})}catch(e){return Promise.reject(e)}},r.delete=function(){try{var e=this;return Promise.resolve(e.client.delete("/user")).then(function(t){if(t.ok)return e.client.cookie.removeAuthCookie(),void e.client.dispatcher.dispatchUserDeletedEvent();if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new x;throw new l})}catch(e){return Promise.reject(e)}},r.logout=function(){try{var e=this;return Promise.resolve(e.client.post("/logout")).then(function(t){if(e.client.cookie.removeAuthCookie(),e.client.dispatcher.dispatchUserLoggedOutEvent(),401===t.status);else if(!t.ok)throw new l})}catch(e){return Promise.reject(e)}},n}(H),J=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var r=n.prototype;return r.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 x;if(!t.ok)throw new l;return t.json()})}catch(e){return Promise.reject(e)}},r.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 x;if(409===e.status)throw new C;throw new l})}catch(e){return Promise.reject(e)}},r.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 x;if(!e.ok)throw new l})}catch(e){return Promise.reject(e)}},r.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 x;if(!e.ok)throw new l})}catch(e){return Promise.reject(e)}},n}(H),B=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var r=n.prototype;return r.auth=function(e,t){try{var n=new URL("/thirdparty/auth",this.client.api);if(!e)throw new O("somethingWentWrong",new Error("provider missing from request"));if(!t)throw new O("somethingWentWrong",new Error("redirectTo missing from request"));return n.searchParams.append("provider",e),n.searchParams.append("redirect_to",t),window.location.assign(n.href),Promise.resolve()}catch(e){return Promise.reject(e)}},r.getError=function(){var e=new URLSearchParams(window.location.search),t=e.get("error"),n=e.get("error_description");if(t){var r="";switch(t){case"access_denied":r="thirdPartyAccessDenied";break;case"user_conflict":r="emailAddressAlreadyExistsError";break;case"multiple_accounts":r="thirdPartyMultipleAccounts";break;case"unverified_email":r="thirdPartyUnverifiedEmail";break;case"email_maxnum":r="maxNumOfEmailAddressesReached";break;case"signup_disabled":r="signupDisabled";break;default:r="somethingWentWrong"}return new O(r,new Error(n))}},n}(H),z=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n.prototype.validate=function(){try{var e=new URLSearchParams(window.location.search).get("hanko_token");return e?(window.history.replaceState(null,null,window.location.pathname),Promise.resolve(this.client.post("/token",{value:e})).then(function(e){if(!e.ok)throw new l;return e.json()})):Promise.resolve()}catch(e){return Promise.reject(e)}},n}(H),V=/*#__PURE__*/function(){function e(){}return e.throttle=function(e,t,n){void 0===n&&(n={});var r,i,o,s=n.leading,a=void 0===s||s,c=n.trailing,u=void 0===c||c,h=0,l=function(){h=!1===a?0:Date.now(),o=null,e.apply(r,i)};return function(){var n=Date.now();h||!1!==a||(h=n);var s=t-(n-h);r=this,i=[].slice.call(arguments),s<=0||s>t?(o&&(window.clearTimeout(o),o=null),h=n,e.apply(r,i)):o||!1===u||(o=window.setTimeout(l,s))}},e}(),X=/*#__PURE__*/function(){function e(){this.throttleLimit=1e3,this._addEventListener=document.addEventListener.bind(document),this._removeEventListener=document.removeEventListener.bind(document),this._throttle=V.throttle}var t=e.prototype;return t.wrapCallback=function(e,t){var n=function(t){e(t.detail)};return t?this._throttle(n,this.throttleLimit,{leading:!0,trailing:!1}):n},t.addEventListenerWithType=function(e){var t=this,n=e.type,r=e.once,i=void 0!==r&&r,o=e.throttle,s=this.wrapCallback(e.callback,void 0!==o&&o);return this._addEventListener(n,s,{once:i}),function(){return t._removeEventListener(n,s)}},e.mapAddEventListenerParams=function(e,t,n){return{type:e,callback:t.callback,once:t.once,throttle:n}},t.addEventListener=function(t,n,r){return this.addEventListenerWithType(e.mapAddEventListenerParams(t,n,r))},t.onSessionCreated=function(e,t){return this.addEventListener(j,{callback:e,once:t},!0)},t.onSessionExpired=function(e,t){return this.addEventListener(_,{callback:e,once:t},!0)},t.onUserLoggedOut=function(e,t){return this.addEventListener(I,{callback:e,once:t})},t.onUserDeleted=function(e,t){return this.addEventListener(A,{callback:e,once:t})},e}(),G=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n.prototype.validate=function(){try{return Promise.resolve(this.client.get("/sessions/validate")).then(function(e){if(!e.ok)throw new l;return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}},n}(H),Q=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n.prototype.isValid=function(){var e;try{var t=this.client._fetch_blocking("/sessions/validate",{method:"GET"});e=JSON.parse(t)}catch(e){throw new l(e)}return!!e&&e.is_valid},n}(H),Y=/*#__PURE__*/function(){function e(e){this.storageKey=void 0,this.defaultState={expiration:0,lastCheck:0},this.storageKey=e}var t=e.prototype;return t.load=function(){var e=window.localStorage.getItem(this.storageKey);return null==e?this.defaultState:JSON.parse(e)},t.save=function(e){window.localStorage.setItem(this.storageKey,JSON.stringify(e||this.defaultState))},e}(),Z=function(e,t){var n=this;this.onActivityCallback=void 0,this.onInactivityCallback=void 0,this.handleFocus=function(){n.onActivityCallback()},this.handleBlur=function(){n.onInactivityCallback()},this.handleVisibilityChange=function(){"visible"===document.visibilityState?n.onActivityCallback():n.onInactivityCallback()},this.hasFocus=function(){return document.hasFocus()},this.onActivityCallback=e,this.onInactivityCallback=t,window.addEventListener("focus",this.handleFocus),window.addEventListener("blur",this.handleBlur),document.addEventListener("visibilitychange",this.handleVisibilityChange)},$=/*#__PURE__*/function(){function e(e,t,n){this.intervalID=null,this.timeoutID=null,this.checkInterval=void 0,this.checkSession=void 0,this.onSessionExpired=void 0,this.checkInterval=e,this.checkSession=t,this.onSessionExpired=n}var t=e.prototype;return t.scheduleSessionExpiry=function(e){var t=this;this.stop(),this.timeoutID=setTimeout(function(){try{return t.stop(),t.onSessionExpired(),Promise.resolve()}catch(e){return Promise.reject(e)}},e)},t.start=function(e,t){var n=this;void 0===e&&(e=0),void 0===t&&(t=0);var r=this.calcTimeToNextCheck(e);this.sessionExpiresSoon(t)?this.scheduleSessionExpiry(r):this.timeoutID=setTimeout(function(){try{return Promise.resolve(n.checkSession()).then(function(e){if(e.is_valid){if(n.sessionExpiresSoon(e.expiration))return void n.scheduleSessionExpiry(e.expiration-Date.now());n.intervalID=setInterval(function(){try{return Promise.resolve(n.checkSession()).then(function(t){(e=t).is_valid?n.sessionExpiresSoon(e.expiration)&&n.scheduleSessionExpiry(e.expiration-Date.now()):n.stop()})}catch(e){return Promise.reject(e)}},n.checkInterval)}else n.stop()})}catch(e){return Promise.reject(e)}},r)},t.stop=function(){this.timeoutID&&(clearTimeout(this.timeoutID),this.timeoutID=null),this.intervalID&&(clearInterval(this.intervalID),this.intervalID=null)},t.isRunning=function(){return null!==this.timeoutID||null!==this.intervalID},t.sessionExpiresSoon=function(e){return e>0&&e-Date.now()<=this.checkInterval},t.calcTimeToNextCheck=function(e){var t=Date.now()-e;return this.checkInterval>=t?this.checkInterval-t%this.checkInterval:0},e}(),ee=/*#__PURE__*/function(){function e(e,t,n,r){var i=this;void 0===e&&(e="hanko_session"),this.channel=void 0,this.onSessionExpired=void 0,this.onSessionCreated=void 0,this.onLeadershipRequested=void 0,this.handleMessage=function(e){var t=e.data;switch(t.action){case"sessionExpired":i.onSessionExpired(t);break;case"sessionCreated":i.onSessionCreated(t);break;case"requestLeadership":i.onLeadershipRequested(t)}},this.onSessionExpired=t,this.onSessionCreated=n,this.onLeadershipRequested=r,this.channel=new BroadcastChannel(e),this.channel.onmessage=this.handleMessage}return e.prototype.post=function(e){this.channel.postMessage(e)},e}(),te=/*#__PURE__*/function(e){function n(t,n){var r;(r=e.call(this)||this).listener=new X,r.checkInterval=3e4,r.client=void 0,r.sessionState=void 0,r.windowActivityManager=void 0,r.scheduler=void 0,r.sessionChannel=void 0,r.isLoggedIn=void 0,r.client=new G(t,n),r.checkInterval=n.sessionCheckInterval,r.sessionState=new Y(n.cookieName+"_session_state"),r.sessionChannel=new ee(n.sessionCheckChannelName,function(){return r.onChannelSessionExpired()},function(e){return r.onChannelSessionCreated(e)},function(){return r.onChannelLeadershipRequested()}),r.scheduler=new $(r.checkInterval,function(){return r.checkSession()},function(){return r.onSessionExpired()}),r.windowActivityManager=new Z(function(){return r.startSessionCheck()},function(){return r.scheduler.stop()});var i=Date.now(),o=r.sessionState.load();return r.isLoggedIn=i<o.expiration,r.initializeEventListeners(),r.startSessionCheck(),r}t(n,e);var r=n.prototype;return r.initializeEventListeners=function(){var e=this;this.listener.onSessionCreated(function(t){var n=t.claims,r=Date.parse(n.expiration),i=Date.now();e.isLoggedIn=!0,e.sessionState.save({expiration:r,lastCheck:i}),e.sessionChannel.post({action:"sessionCreated",claims:n}),e.startSessionCheck()}),this.listener.onUserLoggedOut(function(){e.isLoggedIn=!1,e.sessionChannel.post({action:"sessionExpired"}),e.sessionState.save(null),e.scheduler.stop()}),window.addEventListener("beforeunload",function(){return e.scheduler.stop()})},r.startSessionCheck=function(){if(this.windowActivityManager.hasFocus()&&(this.sessionChannel.post({action:"requestLeadership"}),!this.scheduler.isRunning())){var e=this.sessionState.load();this.isLoggedIn&&this.scheduler.start(e.lastCheck,e.expiration)}},r.checkSession=function(){try{var e=this,t=Date.now();return Promise.resolve(e.client.validate()).then(function(n){var r=n.is_valid,i=n.claims,o=n.expiration_time,s=o?Date.parse(o):0;return!r&&e.isLoggedIn&&e.dispatchSessionExpiredEvent(),r?(e.isLoggedIn=!0,e.sessionState.save({lastCheck:t,expiration:s})):(e.isLoggedIn=!1,e.sessionState.save(null),e.sessionChannel.post({action:"sessionExpired"})),{is_valid:r,claims:i,expiration:s}})}catch(e){return Promise.reject(e)}},r.onSessionExpired=function(){this.isLoggedIn&&(this.isLoggedIn=!1,this.sessionState.save(null),this.sessionChannel.post({action:"sessionExpired"}),this.dispatchSessionExpiredEvent())},r.onChannelSessionExpired=function(){this.isLoggedIn&&(this.isLoggedIn=!1,this.dispatchSessionExpiredEvent())},r.onChannelSessionCreated=function(e){var t=e.claims,n=Date.now(),r=Date.parse(t.expiration)-n;this.isLoggedIn=!0,this.dispatchSessionCreatedEvent({claims:t,expirationSeconds:r})},r.onChannelLeadershipRequested=function(){this.windowActivityManager.hasFocus()||this.scheduler.stop()},n}(R),ne=/*#__PURE__*/c("actionDefinitions"),re=/*#__PURE__*/c("createActionsProxy"),ie=/*#__PURE__*/function(){var e=t.prototype;function t(e,t){var n=e.name,r=e.payload,i=e.error,o=e.status,s=e.actions,a=e.csrf_token;Object.defineProperty(this,re,{value:oe}),this.name=void 0,this.payload=void 0,this.error=void 0,this.status=void 0,this.csrf_token=void 0,Object.defineProperty(this,ne,{writable:!0,value:void 0}),this.actions=void 0,this.fetchNextState=void 0,this.name=n,this.payload=r,this.error=i,this.status=o,this.csrf_token=a,u(this,ne)[ne]=s,this.actions=u(this,re)[re](s,a),this.fetchNextState=t}return e.toJSON=function(){return{name:this.name,payload:this.payload,error:this.error,status:this.status,csrf_token:this.csrf_token,actions:u(this,ne)[ne]}},e.runAction=function(e,t){var n={};if("inputs"in e&&"object"==typeof e.inputs&&null!==e.inputs){var r=e.inputs;for(var i in e.inputs){var o=r[i];o&&"value"in o&&(n[i]=o.value)}}return this.fetchNextState(e.href,{input_data:n,csrf_token:t})},e.validateAction=function(e){if("inputs"in e){var t=function(t){var n=e.inputs[t];function r(e,n,r,i){throw new se({reason:e,inputName:t,wanted:r,actual:i,message:n})}var i=n.value;n.required&&!i&&r(N.Required,"is required"),(null!=n.min_length||null!=n.max_length)&&("length"in i||r(N.InvalidInputDefinition,'has min/max length requirement, but is missing "length" property',"string",typeof i),null!=n.min_length&&i<n.min_length&&r(N.MinLength,"too short (min "+n.min_length+")",n.min_length,i.length),null!=n.max_length&&i>n.max_length&&r(N.MaxLength,"too long (max "+n.max_length+")",n.max_length,i.length))};for(var n in e.inputs)t(n)}},t}();function oe(e,t){var n=this,r=function(e){return n.validateAction(e)};return new Proxy(e,{get:function(e,i){if("symbol"==typeof i)return e[i];var o=e[i];return null==o?null:function(e){var i=Object.assign(JSON.parse(JSON.stringify(o)),{validate:function(){return r(i),i},tryValidate:function(){try{r(i)}catch(e){if(e instanceof se)return e;throw e}},run:function(){return function(e){return n.runAction(e,t)}(i)}});if(null!==i&&"object"==typeof i&&"inputs"in i)for(var s in e){var a=i.inputs;a[s]||(a[s]={name:s,type:""}),a[s].value=e[s]}return i}}})}!function(e){e[e.InvalidInputDefinition=0]="InvalidInputDefinition",e[e.MinLength=1]="MinLength",e[e.MaxLength=2]="MaxLength",e[e.Required=3]="Required"}(N||(N={}));var se=/*#__PURE__*/function(e){function n(t){var n;return(n=e.call(this,'"'+t.inputName+'" '+t.message)||this).reason=void 0,n.inputName=void 0,n.wanted=void 0,n.actual=void 0,n.name="ValidationError",n.reason=t.reason,n.inputName=t.inputName,n.wanted=t.wanted,n.actual=t.actual,n}return t(n,e),n}(/*#__PURE__*/o(Error));function ae(e){return"object"==typeof e&&null!==e&&"status"in e&&"error"in e&&"name"in e&&Boolean(e.name)&&Boolean(e.status)}function ce(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var ue=/*#__PURE__*/function(e){function n(){for(var t,n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];return(t=e.call.apply(e,[this].concat(r))||this).run=function(e,n){try{return Promise.resolve(ce(function(){if(!ae(e))throw new le(e);var r=n[e.name];if(!r)throw new he(e);return Promise.resolve(r(e)).then(function(e){function r(){if(ae(e))return t.run(e,n)}var i=function(){if("object"==typeof(t=e)&&null!==t&&"href"in t&&"inputs"in t)return Promise.resolve(e.run()).then(function(t){e=t});var t}();return i&&i.then?i.then(r):r()})},function(e){if("function"==typeof n.onError)return n.onError(e)}))}catch(e){return Promise.reject(e)}},t}t(n,e);var r=n.prototype;return r.init=function(e,t){var n=this;return Promise.resolve(function e(r,i){try{return Promise.resolve(ce(function(){return Promise.resolve(n.client.post(r,i)).then(function(t){return new ie(t.json(),e)})},function(e){null==t.onError||t.onError(e)}))}catch(e){return Promise.reject(e)}}(e)).then(function(e){return Promise.resolve(n.run(e,t)).then(function(){})})},r.fromString=function(e,t){try{var n=this,r=new ie(JSON.parse(e),function e(r,i){try{return Promise.resolve(ce(function(){return Promise.resolve(n.client.post(r,i)).then(function(t){return new ie(t.json(),e)})},function(e){null==t.onError||t.onError(e)}))}catch(e){return Promise.reject(e)}});return Promise.resolve(n.run(r,t)).then(function(){})}catch(e){return Promise.reject(e)}},n}(H),he=/*#__PURE__*/function(e){function n(t){var r;return(r=e.call(this,"No handler found for state: "+("string"==typeof t.name?'"'+t.name+'"':"("+typeof t.name+")"),"handlerNotFoundError")||this).state=void 0,r.state=t,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),le=/*#__PURE__*/function(e){function n(t){var n;return(n=e.call(this,"Invalid state: "+("string"==typeof t.name?'"'+t.name+'"':"("+typeof t.name+")"))||this).state=void 0,n.state=t,n}return t(n,e),n}(/*#__PURE__*/o(Error)),de=/*#__PURE__*/function(e){function n(t,n){var r;(r=e.call(this)||this).api=void 0,r.user=void 0,r.email=void 0,r.thirdParty=void 0,r.enterprise=void 0,r.token=void 0,r.sessionClient=void 0,r.session=void 0,r.relay=void 0,r.flow=void 0;var i={timeout:13e3,cookieName:"hanko",localStorageKey:"hanko",sessionCheckInterval:3e4,sessionCheckChannelName:"hanko-session-check"};return void 0!==(null==n?void 0:n.cookieName)&&(i.cookieName=n.cookieName),void 0!==(null==n?void 0:n.timeout)&&(i.timeout=n.timeout),void 0!==(null==n?void 0:n.localStorageKey)&&(i.localStorageKey=n.localStorageKey),void 0!==(null==n?void 0:n.cookieDomain)&&(i.cookieDomain=n.cookieDomain),void 0!==(null==n?void 0:n.cookieSameSite)&&(i.cookieSameSite=n.cookieSameSite),void 0!==(null==n?void 0:n.lang)&&(i.lang=n.lang),void 0!==(null==n?void 0:n.sessionCheckInterval)&&(i.sessionCheckInterval=n.sessionCheckInterval<3e3?3e3:n.sessionCheckInterval),void 0!==(null==n?void 0:n.sessionCheckChannelName)&&(i.sessionCheckChannelName=n.sessionCheckChannelName),r.api=t,r.user=new F(t,i),r.email=new J(t,i),r.thirdParty=new B(t,i),r.enterprise=new K(t,i),r.token=new z(t,i),r.sessionClient=new G(t,i),r.session=new Q(t,i),r.relay=new te(t,i),r.flow=new ue(t,i),r}return t(n,e),n.prototype.setLang=function(e){this.flow.client.lang=e},n}(X),pe=/*#__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}();exports.ConflictError=d,exports.CustomEventWithDetail=L,exports.EmailAddressAlreadyExistsError=S,exports.EmailClient=J,exports.EnterpriseClient=K,exports.ForbiddenError=b,exports.Hanko=de,exports.HankoError=h,exports.InvalidPasscodeError=m,exports.InvalidPasswordError=v,exports.InvalidWebauthnCredentialError=y,exports.MaxNumOfEmailAddressesReachedError=C,exports.MaxNumOfPasscodeAttemptsReachedError=g,exports.NotFoundError=k,exports.PasscodeExpiredError=w,exports.RequestTimeoutError=p,exports.SessionClient=G,exports.TechnicalError=l,exports.ThirdPartyClient=B,exports.ThirdPartyError=O,exports.TokenClient=z,exports.TooManyRequestsError=E,exports.UnauthorizedError=x,exports.UserClient=F,exports.UserVerificationError=P,exports.WebauthnRequestCancelledError=f,exports.WebauthnSupport=pe,exports.sessionCreatedType=j,exports.sessionExpiredType=_,exports.userDeletedType=A,exports.userLoggedOutType=I;
|
|
1
|
+
function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},e.apply(this,arguments)}function t(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,i(e,t)}function n(e){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},n(e)}function i(e,t){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},i(e,t)}function r(e,t,n){return r=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 r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&i(o,n.prototype),o},r.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 r(e,arguments,n(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),i(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=0;function c(e){return"__private_"+a+++"_"+e}function u(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var h=/*#__PURE__*/function(e){function n(t,i,r){var o;return(o=e.call(this,t)||this).code=void 0,o.cause=void 0,o.code=i,o.cause=r,Object.setPrototypeOf(s(o),n.prototype),o}return t(n,e),n}(/*#__PURE__*/o(Error)),l=/*#__PURE__*/function(e){function n(t){var i;return i=e.call(this,"Technical error","somethingWentWrong",t)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),d=/*#__PURE__*/function(e){function n(t,i){var r;return r=e.call(this,"Conflict error","conflict",i)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),p=/*#__PURE__*/function(e){function n(t){var i;return i=e.call(this,"Request timed out error","requestTimeout",t)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),f=/*#__PURE__*/function(e){function n(t){var i;return i=e.call(this,"Request cancelled error","requestCancelled",t)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),v=/*#__PURE__*/function(e){function n(t){var i;return i=e.call(this,"Invalid password error","invalidPassword",t)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),m=/*#__PURE__*/function(e){function n(t){var i;return i=e.call(this,"Invalid Passcode error","invalidPasscode",t)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),y=/*#__PURE__*/function(e){function n(t){var i;return i=e.call(this,"Invalid WebAuthn credential error","invalidWebauthnCredential",t)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),w=/*#__PURE__*/function(e){function n(t){var i;return i=e.call(this,"Passcode expired error","passcodeExpired",t)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),g=/*#__PURE__*/function(e){function n(t){var i;return i=e.call(this,"Maximum number of Passcode attempts reached error","passcodeAttemptsReached",t)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),k=/*#__PURE__*/function(e){function n(t){var i;return i=e.call(this,"Not found error","notFound",t)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),E=/*#__PURE__*/function(e){function n(t,i){var r;return(r=e.call(this,"Too many requests error","tooManyRequests",i)||this).retryAfter=void 0,r.retryAfter=t,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),S=/*#__PURE__*/function(e){function n(t){var i;return i=e.call(this,"Unauthorized error","unauthorized",t)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),x=/*#__PURE__*/function(e){function n(t){var i;return i=e.call(this,"Forbidden error","forbidden",t)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),b=/*#__PURE__*/function(e){function n(t){var i;return i=e.call(this,"User verification error","userVerification",t)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),C=/*#__PURE__*/function(e){function n(t){var i;return i=e.call(this,"Maximum number of email addresses reached error","maxNumOfEmailAddressesReached",t)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),P=/*#__PURE__*/function(e){function n(t){var i;return i=e.call(this,"The email address already exists","emailAddressAlreadyExistsError",t)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),O=/*#__PURE__*/function(e){function n(t,i){var r;return r=e.call(this,"An error occurred during third party sign up/sign in",t,i)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),j="hanko-session-created",_="hanko-session-expired",I="hanko-user-logged-out",L="hanko-user-deleted",T=/*#__PURE__*/function(e){function n(t,n){return e.call(this,t,{detail:n})||this}return t(n,e),n}(/*#__PURE__*/o(CustomEvent)),A=/*#__PURE__*/function(){function e(){this._dispatchEvent=document.dispatchEvent.bind(document)}var t=e.prototype;return t.dispatch=function(e,t){this._dispatchEvent(new T(e,t))},t.dispatchSessionCreatedEvent=function(e){this.dispatch(j,e)},t.dispatchSessionExpiredEvent=function(){this.dispatch(_,null)},t.dispatchUserLoggedOutEvent=function(){this.dispatch(I,null)},t.dispatchUserDeletedEvent=function(){this.dispatch(L,null)},e}();function N(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)e[i]=n[i]}return e}var R,D=function e(t,n){function i(e,i,r){if("undefined"!=typeof document){"number"==typeof(r=N({},n,r)).expires&&(r.expires=new Date(Date.now()+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var o="";for(var s in r)r[s]&&(o+="; "+s,!0!==r[s]&&(o+="="+r[s].split(";")[0]));return document.cookie=e+"="+t.write(i,e)+o}}return Object.create({set:i,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var n=document.cookie?document.cookie.split("; "):[],i={},r=0;r<n.length;r++){var o=n[r].split("="),s=o.slice(1).join("=");try{var a=decodeURIComponent(o[0]);if(i[a]=t.read(s,a),e===a)break}catch(e){}}return e?i[e]:i}},remove:function(e,t){i(e,"",N({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,N({},this.attributes,t))},withConverter:function(t){return e(N({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(n)},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:"/"}),q=/*#__PURE__*/function(){function t(e){var t;this.authCookieName=void 0,this.authCookieDomain=void 0,this.authCookieSameSite=void 0,this.authCookieName=e.cookieName,this.authCookieDomain=e.cookieDomain,this.authCookieSameSite=null!=(t=e.cookieSameSite)?t:"lax"}var n=t.prototype;return n.getAuthCookie=function(){return D.get(this.authCookieName)},n.setAuthCookie=function(t,n){var i={secure:!0,sameSite:this.authCookieSameSite};void 0!==this.authCookieDomain&&(i.domain=this.authCookieDomain);var r=e({},i,n);if(("none"===r.sameSite||"None"===r.sameSite)&&!1===r.secure)throw new l(new Error("Secure attribute must be set when SameSite=None"));D.set(this.authCookieName,t,r)},n.removeAuthCookie=function(){D.remove(this.authCookieName)},t}(),M=/*#__PURE__*/function(){function e(e){this.keyName=void 0,this.keyName=e.keyName}var t=e.prototype;return t.getSessionToken=function(){return sessionStorage.getItem(this.keyName)},t.setSessionToken=function(e){sessionStorage.setItem(this.keyName,e)},t.removeSessionToken=function(){sessionStorage.removeItem(this.keyName)},e}(),U=/*#__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 U(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}(),H=/*#__PURE__*/function(){function t(t,n){this.timeout=void 0,this.api=void 0,this.dispatcher=void 0,this.cookie=void 0,this.sessionTokenStorage=void 0,this.lang=void 0,this.sessionTokenLocation=void 0,this.api=t,this.timeout=n.timeout,this.dispatcher=new A,this.cookie=new q(e({},n)),this.sessionTokenStorage=new M({keyName:n.cookieName}),this.lang=n.lang,this.sessionTokenLocation=n.sessionTokenLocation}var n=t.prototype;return n._fetch=function(e,t,n){void 0===n&&(n=new XMLHttpRequest);var i=this,r=this.api+e,o=this.timeout,s=this.getAuthToken(),a=this.lang;return new Promise(function(e,c){n.open(t.method,r,!0),n.setRequestHeader("Accept","application/json"),n.setRequestHeader("Content-Type","application/json"),n.setRequestHeader("X-Language",a),s&&n.setRequestHeader("Authorization","Bearer "+s),n.timeout=o,n.withCredentials=!0,n.onload=function(){i.processHeaders(n),e(new W(n))},n.onerror=function(){c(new l)},n.ontimeout=function(){c(new p)},n.send(t.body?t.body.toString():null)})},n._fetch_blocking=function(e,t,n){void 0===n&&(n=new XMLHttpRequest);var i=this.api+e,r=this.getAuthToken();return n.open(t.method,i,!1),n.setRequestHeader("Accept","application/json"),n.setRequestHeader("Content-Type","application/json"),r&&n.setRequestHeader("Authorization","Bearer "+r),n.withCredentials=!0,n.send(t.body?t.body.toString():null),n.responseText},n.processHeaders=function(e){var t="",n=0,i="";if(e.getAllResponseHeaders().split("\r\n").forEach(function(r){var o=r.toLowerCase();o.startsWith("x-auth-token")?t=e.getResponseHeader("X-Auth-Token"):o.startsWith("x-session-lifetime")?n=parseInt(e.getResponseHeader("X-Session-Lifetime"),10):o.startsWith("x-session-retention")&&(i=e.getResponseHeader("X-Session-Retention"))}),t){var r=new RegExp("^https://"),o=!!this.api.match(r)&&!!window.location.href.match(r),s="session"===i?void 0:new Date((new Date).getTime()+1e3*n);this.setAuthToken(t,{secure:o,expires:s})}},n.get=function(e){return this._fetch(e,{method:"GET"})},n.post=function(e,t){return this._fetch(e,{method:"POST",body:JSON.stringify(t)})},n.put=function(e,t){return this._fetch(e,{method:"PUT",body:JSON.stringify(t)})},n.patch=function(e,t){return this._fetch(e,{method:"PATCH",body:JSON.stringify(t)})},n.delete=function(e){return this._fetch(e,{method:"DELETE"})},n.getAuthToken=function(){var e="";switch(this.sessionTokenLocation){case"cookie":e=this.cookie.getAuthCookie();break;case"sessionStorage":e=this.sessionTokenStorage.getSessionToken()}return e},n.setAuthToken=function(e,t){switch(this.sessionTokenLocation){case"cookie":return this.cookie.setAuthCookie(e,t);case"sessionStorage":return this.sessionTokenStorage.setSessionToken(e)}},t}(),K=function(e,t){this.client=void 0,this.client=new H(e,t)},F=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var i=n.prototype;return i.getDomain=function(e){if(!e)throw new O("somethingWentWrong",new Error("email missing from request"));var t=e.split("@");if(2!==t.length)throw new O("somethingWentWrong",new Error("email is not in a valid email format."));var n=t[1].trim();if(""===n)throw new O("somethingWentWrong",new Error("email is not in a valid email format."));return n},i.hasProvider=function(e){try{var t=this.getDomain(e);return Promise.resolve(this.client.get("/saml/provider?domain="+t).then(function(e){if(404==e.status)throw new k(new Error("provider not found"));if(!e.ok)throw new l(new Error("unable to fetch provider"));return e.ok}))}catch(e){return Promise.reject(e)}},i.auth=function(e,t){var n=new URL("/saml/auth",this.client.api),i=this.getDomain(e);if(!t)throw new O("somethingWentWrong",new Error("redirectTo missing from request"));n.searchParams.append("domain",i),n.searchParams.append("redirect_to",t),window.location.assign(n.href)},i.getError=function(){var e=new URLSearchParams(window.location.search),t=e.get("error"),n=e.get("error_description");if(t){var i;switch(t){case"access_denied":i="enterpriseAccessDenied";break;case"user_conflict":i="emailAddressAlreadyExistsError";break;case"multiple_accounts":i="enterpriseMultipleAccounts";break;case"unverified_email":i="enterpriseUnverifiedEmail";break;case"email_maxnum":i="maxNumOfEmailAddressesReached";break;default:i="somethingWentWrong"}return new O(i,new Error(n))}},n}(K),J=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var i=n.prototype;return i.getInfo=function(e){try{return Promise.resolve(this.client.post("/user",{email:e})).then(function(e){if(404===e.status)throw new k;if(!e.ok)throw new l;return e.json()})}catch(e){return Promise.reject(e)}},i.create=function(e){try{return Promise.resolve(this.client.post("/users",{email:e})).then(function(e){if(409===e.status)throw new d;if(403===e.status)throw new x;if(!e.ok)throw new l;return e.json()})}catch(e){return Promise.reject(e)}},i.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 S;if(!t.ok)throw new l;var n=t.json();return Promise.resolve(e.client.get("/users/"+n.id)).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!t.ok)throw new l;return t.json()})})}catch(e){return Promise.reject(e)}},i.delete=function(){try{var e=this;return Promise.resolve(e.client.delete("/user")).then(function(t){if(t.ok)return e.client.sessionTokenStorage.removeSessionToken(),e.client.cookie.removeAuthCookie(),void e.client.dispatcher.dispatchUserDeletedEvent();if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new S;throw new l})}catch(e){return Promise.reject(e)}},i.logout=function(){try{var e=this;return Promise.resolve(e.client.post("/logout")).then(function(t){if(e.client.sessionTokenStorage.removeSessionToken(),e.client.cookie.removeAuthCookie(),e.client.dispatcher.dispatchUserLoggedOutEvent(),401===t.status);else if(!t.ok)throw new l})}catch(e){return Promise.reject(e)}},n}(K),B=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var i=n.prototype;return i.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 S;if(!t.ok)throw new l;return t.json()})}catch(e){return Promise.reject(e)}},i.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 S;if(409===e.status)throw new C;throw new l})}catch(e){return Promise.reject(e)}},i.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 S;if(!e.ok)throw new l})}catch(e){return Promise.reject(e)}},i.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 S;if(!e.ok)throw new l})}catch(e){return Promise.reject(e)}},n}(K),z=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var i=n.prototype;return i.auth=function(e,t){try{var n=new URL("/thirdparty/auth",this.client.api);if(!e)throw new O("somethingWentWrong",new Error("provider missing from request"));if(!t)throw new O("somethingWentWrong",new Error("redirectTo missing from request"));return n.searchParams.append("provider",e),n.searchParams.append("redirect_to",t),window.location.assign(n.href),Promise.resolve()}catch(e){return Promise.reject(e)}},i.getError=function(){var e=new URLSearchParams(window.location.search),t=e.get("error"),n=e.get("error_description");if(t){var i="";switch(t){case"access_denied":i="thirdPartyAccessDenied";break;case"user_conflict":i="emailAddressAlreadyExistsError";break;case"multiple_accounts":i="thirdPartyMultipleAccounts";break;case"unverified_email":i="thirdPartyUnverifiedEmail";break;case"email_maxnum":i="maxNumOfEmailAddressesReached";break;case"signup_disabled":i="signupDisabled";break;default:i="somethingWentWrong"}return new O(i,new Error(n))}},n}(K),V=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n.prototype.validate=function(){try{var e=new URLSearchParams(window.location.search).get("hanko_token");return e?(window.history.replaceState(null,null,window.location.pathname),Promise.resolve(this.client.post("/token",{value:e})).then(function(e){if(!e.ok)throw new l;return e.json()})):Promise.resolve()}catch(e){return Promise.reject(e)}},n}(K),X=/*#__PURE__*/function(){function e(){}return e.throttle=function(e,t,n){void 0===n&&(n={});var i,r,o,s=n.leading,a=void 0===s||s,c=n.trailing,u=void 0===c||c,h=0,l=function(){h=!1===a?0:Date.now(),o=null,e.apply(i,r)};return function(){var n=Date.now();h||!1!==a||(h=n);var s=t-(n-h);i=this,r=[].slice.call(arguments),s<=0||s>t?(o&&(window.clearTimeout(o),o=null),h=n,e.apply(i,r)):o||!1===u||(o=window.setTimeout(l,s))}},e}(),G=/*#__PURE__*/function(){function e(){this.throttleLimit=1e3,this._addEventListener=document.addEventListener.bind(document),this._removeEventListener=document.removeEventListener.bind(document),this._throttle=X.throttle}var t=e.prototype;return t.wrapCallback=function(e,t){var n=function(t){e(t.detail)};return t?this._throttle(n,this.throttleLimit,{leading:!0,trailing:!1}):n},t.addEventListenerWithType=function(e){var t=this,n=e.type,i=e.once,r=void 0!==i&&i,o=e.throttle,s=this.wrapCallback(e.callback,void 0!==o&&o);return this._addEventListener(n,s,{once:r}),function(){return t._removeEventListener(n,s)}},e.mapAddEventListenerParams=function(e,t,n){return{type:e,callback:t.callback,once:t.once,throttle:n}},t.addEventListener=function(t,n,i){return this.addEventListenerWithType(e.mapAddEventListenerParams(t,n,i))},t.onSessionCreated=function(e,t){return this.addEventListener(j,{callback:e,once:t},!0)},t.onSessionExpired=function(e,t){return this.addEventListener(_,{callback:e,once:t},!0)},t.onUserLoggedOut=function(e,t){return this.addEventListener(I,{callback:e,once:t})},t.onUserDeleted=function(e,t){return this.addEventListener(L,{callback:e,once:t})},e}(),Q=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n.prototype.validate=function(){try{return Promise.resolve(this.client.get("/sessions/validate")).then(function(e){if(!e.ok)throw new l;return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}},n}(K),Y=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n.prototype.isValid=function(){var e;try{var t=this.client._fetch_blocking("/sessions/validate",{method:"GET"});e=JSON.parse(t)}catch(e){throw new l(e)}return!!e&&e.is_valid},n}(K),Z=/*#__PURE__*/function(){function e(e){this.storageKey=void 0,this.defaultState={expiration:0,lastCheck:0},this.storageKey=e}var t=e.prototype;return t.load=function(){var e=window.localStorage.getItem(this.storageKey);return null==e?this.defaultState:JSON.parse(e)},t.save=function(e){window.localStorage.setItem(this.storageKey,JSON.stringify(e||this.defaultState))},e}(),$=function(e,t){var n=this;this.onActivityCallback=void 0,this.onInactivityCallback=void 0,this.handleFocus=function(){n.onActivityCallback()},this.handleBlur=function(){n.onInactivityCallback()},this.handleVisibilityChange=function(){"visible"===document.visibilityState?n.onActivityCallback():n.onInactivityCallback()},this.hasFocus=function(){return document.hasFocus()},this.onActivityCallback=e,this.onInactivityCallback=t,window.addEventListener("focus",this.handleFocus),window.addEventListener("blur",this.handleBlur),document.addEventListener("visibilitychange",this.handleVisibilityChange)},ee=/*#__PURE__*/function(){function e(e,t,n){this.intervalID=null,this.timeoutID=null,this.checkInterval=void 0,this.checkSession=void 0,this.onSessionExpired=void 0,this.checkInterval=e,this.checkSession=t,this.onSessionExpired=n}var t=e.prototype;return t.scheduleSessionExpiry=function(e){var t=this;this.stop(),this.timeoutID=setTimeout(function(){try{return t.stop(),t.onSessionExpired(),Promise.resolve()}catch(e){return Promise.reject(e)}},e)},t.start=function(e,t){var n=this;void 0===e&&(e=0),void 0===t&&(t=0);var i=this.calcTimeToNextCheck(e);this.sessionExpiresSoon(t)?this.scheduleSessionExpiry(i):this.timeoutID=setTimeout(function(){try{return Promise.resolve(n.checkSession()).then(function(e){if(e.is_valid){if(n.sessionExpiresSoon(e.expiration))return void n.scheduleSessionExpiry(e.expiration-Date.now());n.intervalID=setInterval(function(){try{return Promise.resolve(n.checkSession()).then(function(t){(e=t).is_valid?n.sessionExpiresSoon(e.expiration)&&n.scheduleSessionExpiry(e.expiration-Date.now()):n.stop()})}catch(e){return Promise.reject(e)}},n.checkInterval)}else n.stop()})}catch(e){return Promise.reject(e)}},i)},t.stop=function(){this.timeoutID&&(clearTimeout(this.timeoutID),this.timeoutID=null),this.intervalID&&(clearInterval(this.intervalID),this.intervalID=null)},t.isRunning=function(){return null!==this.timeoutID||null!==this.intervalID},t.sessionExpiresSoon=function(e){return e>0&&e-Date.now()<=this.checkInterval},t.calcTimeToNextCheck=function(e){var t=Date.now()-e;return this.checkInterval>=t?this.checkInterval-t%this.checkInterval:0},e}(),te=/*#__PURE__*/function(){function e(e,t,n,i){var r=this;void 0===e&&(e="hanko_session"),this.channel=void 0,this.onSessionExpired=void 0,this.onSessionCreated=void 0,this.onLeadershipRequested=void 0,this.handleMessage=function(e){var t=e.data;switch(t.action){case"sessionExpired":r.onSessionExpired(t);break;case"sessionCreated":r.onSessionCreated(t);break;case"requestLeadership":r.onLeadershipRequested(t)}},this.onSessionExpired=t,this.onSessionCreated=n,this.onLeadershipRequested=i,this.channel=new BroadcastChannel(e),this.channel.onmessage=this.handleMessage}return e.prototype.post=function(e){this.channel.postMessage(e)},e}(),ne=/*#__PURE__*/function(e){function n(t,n){var i;(i=e.call(this)||this).listener=new G,i.checkInterval=3e4,i.client=void 0,i.sessionState=void 0,i.windowActivityManager=void 0,i.scheduler=void 0,i.sessionChannel=void 0,i.isLoggedIn=void 0,i.client=new Q(t,n),i.checkInterval=n.sessionCheckInterval,i.sessionState=new Z(n.cookieName+"_session_state"),i.sessionChannel=new te(i.getSessionCheckChannelName(n.sessionTokenLocation,n.sessionCheckChannelName),function(){return i.onChannelSessionExpired()},function(e){return i.onChannelSessionCreated(e)},function(){return i.onChannelLeadershipRequested()}),i.scheduler=new ee(i.checkInterval,function(){return i.checkSession()},function(){return i.onSessionExpired()}),i.windowActivityManager=new $(function(){return i.startSessionCheck()},function(){return i.scheduler.stop()});var r=Date.now(),o=i.sessionState.load();return i.isLoggedIn=r<o.expiration,i.initializeEventListeners(),i.startSessionCheck(),i}t(n,e);var i=n.prototype;return i.initializeEventListeners=function(){var e=this;this.listener.onSessionCreated(function(t){var n=t.claims,i=Date.parse(n.expiration),r=Date.now();e.isLoggedIn=!0,e.sessionState.save({expiration:i,lastCheck:r}),e.sessionChannel.post({action:"sessionCreated",claims:n}),e.startSessionCheck()}),this.listener.onUserLoggedOut(function(){e.isLoggedIn=!1,e.sessionChannel.post({action:"sessionExpired"}),e.sessionState.save(null),e.scheduler.stop()}),window.addEventListener("beforeunload",function(){return e.scheduler.stop()})},i.startSessionCheck=function(){if(this.windowActivityManager.hasFocus()&&(this.sessionChannel.post({action:"requestLeadership"}),!this.scheduler.isRunning())){var e=this.sessionState.load();this.isLoggedIn&&this.scheduler.start(e.lastCheck,e.expiration)}},i.checkSession=function(){try{var e=this,t=Date.now();return Promise.resolve(e.client.validate()).then(function(n){var i=n.is_valid,r=n.claims,o=n.expiration_time,s=o?Date.parse(o):0;return!i&&e.isLoggedIn&&e.dispatchSessionExpiredEvent(),i?(e.isLoggedIn=!0,e.sessionState.save({lastCheck:t,expiration:s})):(e.isLoggedIn=!1,e.sessionState.save(null),e.sessionChannel.post({action:"sessionExpired"})),{is_valid:i,claims:r,expiration:s}})}catch(e){return Promise.reject(e)}},i.onSessionExpired=function(){this.isLoggedIn&&(this.isLoggedIn=!1,this.sessionState.save(null),this.sessionChannel.post({action:"sessionExpired"}),this.dispatchSessionExpiredEvent())},i.onChannelSessionExpired=function(){this.isLoggedIn&&(this.isLoggedIn=!1,this.dispatchSessionExpiredEvent())},i.onChannelSessionCreated=function(e){var t=e.claims,n=Date.now(),i=Date.parse(t.expiration)-n;this.isLoggedIn=!0,this.dispatchSessionCreatedEvent({claims:t,expirationSeconds:i})},i.onChannelLeadershipRequested=function(){this.windowActivityManager.hasFocus()||this.scheduler.stop()},i.getSessionCheckChannelName=function(e,t){if("cookie"==e)return t;var n=sessionStorage.getItem("sessionCheckChannelName");return null!=n&&""!==n||(n=t+"-"+(Math.floor(100*Math.random())+1),sessionStorage.setItem("sessionCheckChannelName",n)),n},n}(A),ie=/*#__PURE__*/c("actionDefinitions"),re=/*#__PURE__*/c("createActionsProxy"),oe=/*#__PURE__*/function(){var e=t.prototype;function t(e,t){var n=e.name,i=e.payload,r=e.error,o=e.status,s=e.actions,a=e.csrf_token;Object.defineProperty(this,re,{value:se}),this.name=void 0,this.payload=void 0,this.error=void 0,this.status=void 0,this.csrf_token=void 0,Object.defineProperty(this,ie,{writable:!0,value:void 0}),this.actions=void 0,this.fetchNextState=void 0,this.name=n,this.payload=i,this.error=r,this.status=o,this.csrf_token=a,u(this,ie)[ie]=s,this.actions=u(this,re)[re](s,a),this.fetchNextState=t}return e.toJSON=function(){return{name:this.name,payload:this.payload,error:this.error,status:this.status,csrf_token:this.csrf_token,actions:u(this,ie)[ie]}},e.runAction=function(e,t){var n={};if("inputs"in e&&"object"==typeof e.inputs&&null!==e.inputs){var i=e.inputs;for(var r in e.inputs){var o=i[r];o&&"value"in o&&(n[r]=o.value)}}return this.fetchNextState(e.href,{input_data:n,csrf_token:t})},e.validateAction=function(e){if("inputs"in e){var t=function(t){var n=e.inputs[t];function i(e,n,i,r){throw new ae({reason:e,inputName:t,wanted:i,actual:r,message:n})}var r=n.value;n.required&&!r&&i(R.Required,"is required"),(null!=n.min_length||null!=n.max_length)&&("length"in r||i(R.InvalidInputDefinition,'has min/max length requirement, but is missing "length" property',"string",typeof r),null!=n.min_length&&r<n.min_length&&i(R.MinLength,"too short (min "+n.min_length+")",n.min_length,r.length),null!=n.max_length&&r>n.max_length&&i(R.MaxLength,"too long (max "+n.max_length+")",n.max_length,r.length))};for(var n in e.inputs)t(n)}},t}();function se(e,t){var n=this,i=function(e){return n.validateAction(e)};return new Proxy(e,{get:function(e,r){if("symbol"==typeof r)return e[r];var o=e[r];return null==o?null:function(e){var r=Object.assign(JSON.parse(JSON.stringify(o)),{validate:function(){return i(r),r},tryValidate:function(){try{i(r)}catch(e){if(e instanceof ae)return e;throw e}},run:function(){return function(e){return n.runAction(e,t)}(r)}});if(null!==r&&"object"==typeof r&&"inputs"in r)for(var s in e){var a=r.inputs;a[s]||(a[s]={name:s,type:""}),a[s].value=e[s]}return r}}})}!function(e){e[e.InvalidInputDefinition=0]="InvalidInputDefinition",e[e.MinLength=1]="MinLength",e[e.MaxLength=2]="MaxLength",e[e.Required=3]="Required"}(R||(R={}));var ae=/*#__PURE__*/function(e){function n(t){var n;return(n=e.call(this,'"'+t.inputName+'" '+t.message)||this).reason=void 0,n.inputName=void 0,n.wanted=void 0,n.actual=void 0,n.name="ValidationError",n.reason=t.reason,n.inputName=t.inputName,n.wanted=t.wanted,n.actual=t.actual,n}return t(n,e),n}(/*#__PURE__*/o(Error));function ce(e){return"object"==typeof e&&null!==e&&"status"in e&&"error"in e&&"name"in e&&Boolean(e.name)&&Boolean(e.status)}function ue(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var he=/*#__PURE__*/function(e){function n(){for(var t,n=arguments.length,i=new Array(n),r=0;r<n;r++)i[r]=arguments[r];return(t=e.call.apply(e,[this].concat(i))||this).run=function(e,n){try{return Promise.resolve(ue(function(){if(!ce(e))throw new de(e);var i=n[e.name];if(!i)throw new le(e);return Promise.resolve(i(e)).then(function(e){function i(){if(ce(e))return t.run(e,n)}var r=function(){if("object"==typeof(t=e)&&null!==t&&"href"in t&&"inputs"in t)return Promise.resolve(e.run()).then(function(t){e=t});var t}();return r&&r.then?r.then(i):i()})},function(e){if("function"==typeof n.onError)return n.onError(e)}))}catch(e){return Promise.reject(e)}},t}t(n,e);var i=n.prototype;return i.init=function(e,t){var n=this;return Promise.resolve(function e(i,r){try{return Promise.resolve(ue(function(){return Promise.resolve(n.client.post(i,r)).then(function(t){return new oe(t.json(),e)})},function(e){null==t.onError||t.onError(e)}))}catch(e){return Promise.reject(e)}}(e)).then(function(e){return Promise.resolve(n.run(e,t)).then(function(){})})},i.fromString=function(e,t){try{var n=this,i=new oe(JSON.parse(e),function e(i,r){try{return Promise.resolve(ue(function(){return Promise.resolve(n.client.post(i,r)).then(function(t){return new oe(t.json(),e)})},function(e){null==t.onError||t.onError(e)}))}catch(e){return Promise.reject(e)}});return Promise.resolve(n.run(i,t)).then(function(){})}catch(e){return Promise.reject(e)}},n}(K),le=/*#__PURE__*/function(e){function n(t){var i;return(i=e.call(this,"No handler found for state: "+("string"==typeof t.name?'"'+t.name+'"':"("+typeof t.name+")"),"handlerNotFoundError")||this).state=void 0,i.state=t,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),de=/*#__PURE__*/function(e){function n(t){var n;return(n=e.call(this,"Invalid state: "+("string"==typeof t.name?'"'+t.name+'"':"("+typeof t.name+")"))||this).state=void 0,n.state=t,n}return t(n,e),n}(/*#__PURE__*/o(Error)),pe=/*#__PURE__*/function(e){function n(t,n){var i;(i=e.call(this)||this).api=void 0,i.user=void 0,i.email=void 0,i.thirdParty=void 0,i.enterprise=void 0,i.token=void 0,i.sessionClient=void 0,i.session=void 0,i.relay=void 0,i.flow=void 0;var r={timeout:13e3,cookieName:"hanko",localStorageKey:"hanko",sessionCheckInterval:3e4,sessionCheckChannelName:"hanko-session-check",sessionTokenLocation:"cookie"};return void 0!==(null==n?void 0:n.cookieName)&&(r.cookieName=n.cookieName),void 0!==(null==n?void 0:n.timeout)&&(r.timeout=n.timeout),void 0!==(null==n?void 0:n.localStorageKey)&&(r.localStorageKey=n.localStorageKey),void 0!==(null==n?void 0:n.cookieDomain)&&(r.cookieDomain=n.cookieDomain),void 0!==(null==n?void 0:n.cookieSameSite)&&(r.cookieSameSite=n.cookieSameSite),void 0!==(null==n?void 0:n.lang)&&(r.lang=n.lang),void 0!==(null==n?void 0:n.sessionCheckInterval)&&(r.sessionCheckInterval=n.sessionCheckInterval<3e3?3e3:n.sessionCheckInterval),void 0!==(null==n?void 0:n.sessionCheckChannelName)&&(r.sessionCheckChannelName=n.sessionCheckChannelName),void 0!==(null==n?void 0:n.sessionTokenLocation)&&(r.sessionTokenLocation=n.sessionTokenLocation),i.api=t,i.user=new J(t,r),i.email=new B(t,r),i.thirdParty=new z(t,r),i.enterprise=new F(t,r),i.token=new V(t,r),i.sessionClient=new Q(t,r),i.session=new Y(t,r),i.relay=new ne(t,r),i.flow=new he(t,r),i}return t(n,e),n.prototype.setLang=function(e){this.flow.client.lang=e},n}(G),fe=/*#__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}();exports.ConflictError=d,exports.CustomEventWithDetail=T,exports.EmailAddressAlreadyExistsError=P,exports.EmailClient=B,exports.EnterpriseClient=F,exports.ForbiddenError=x,exports.Hanko=pe,exports.HankoError=h,exports.InvalidPasscodeError=m,exports.InvalidPasswordError=v,exports.InvalidWebauthnCredentialError=y,exports.MaxNumOfEmailAddressesReachedError=C,exports.MaxNumOfPasscodeAttemptsReachedError=g,exports.NotFoundError=k,exports.PasscodeExpiredError=w,exports.RequestTimeoutError=p,exports.SessionClient=Q,exports.TechnicalError=l,exports.ThirdPartyClient=z,exports.ThirdPartyError=O,exports.TokenClient=V,exports.TooManyRequestsError=E,exports.UnauthorizedError=S,exports.UserClient=J,exports.UserVerificationError=b,exports.WebauthnRequestCancelledError=f,exports.WebauthnSupport=fe,exports.sessionCreatedType=j,exports.sessionExpiredType=_,exports.userDeletedType=L,exports.userLoggedOutType=I;
|
|
2
2
|
//# sourceMappingURL=sdk.cjs.map
|