@teamhanko/hanko-frontend-sdk 1.5.0 → 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/lib/flow-api/types/action.d.ts +1 -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/sdk.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).hankoFrontendSdk={})}(this,function(e){function t(){return t=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},t.apply(this,arguments)}function n(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,r(e,t)}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}function r(e,t){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},r(e,t)}function o(e,t,n){return o=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},o.apply(null,arguments)}function s(e){var t="function"==typeof Map?new Map:void 0;return s=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,n)}function n(){return o(e,arguments,i(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),r(n,e)},s(e)}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var c=0;function u(e){return"__private_"+c+++"_"+e}function h(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var l=/*#__PURE__*/function(e){function t(n,i,r){var o;return(o=e.call(this,n)||this).code=void 0,o.cause=void 0,o.code=i,o.cause=r,Object.setPrototypeOf(a(o),t.prototype),o}return n(t,e),t}(/*#__PURE__*/s(Error)),d=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Technical error","somethingWentWrong",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),f=/*#__PURE__*/function(e){function t(n,i){var r;return r=e.call(this,"Conflict error","conflict",i)||this,Object.setPrototypeOf(a(r),t.prototype),r}return n(t,e),t}(l),p=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Request timed out error","requestTimeout",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),v=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Request cancelled error","requestCancelled",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),m=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Invalid password error","invalidPassword",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),y=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Invalid Passcode error","invalidPasscode",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),w=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Invalid WebAuthn credential error","invalidWebauthnCredential",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),g=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Passcode expired error","passcodeExpired",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),k=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Maximum number of Passcode attempts reached error","passcodeAttemptsReached",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),E=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Not found error","notFound",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),b=/*#__PURE__*/function(e){function t(n,i){var r;return(r=e.call(this,"Too many requests error","tooManyRequests",i)||this).retryAfter=void 0,r.retryAfter=n,Object.setPrototypeOf(a(r),t.prototype),r}return n(t,e),t}(l),P=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Unauthorized error","unauthorized",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),C=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Forbidden error","forbidden",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),S=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"User verification error","userVerification",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),x=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Maximum number of email addresses reached error","maxNumOfEmailAddressesReached",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),O=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"The email address already exists","emailAddressAlreadyExistsError",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),j=/*#__PURE__*/function(e){function t(n,i){var r;return r=e.call(this,"An error occurred during third party sign up/sign in",n,i)||this,Object.setPrototypeOf(a(r),t.prototype),r}return n(t,e),t}(l),_="hanko-session-created",I="hanko-session-expired",A="hanko-user-logged-out",L="hanko-user-deleted",R=/*#__PURE__*/function(e){function t(t,n){return e.call(this,t,{detail:n})||this}return n(t,e),t}(/*#__PURE__*/s(CustomEvent)),D=/*#__PURE__*/function(){function e(){this._dispatchEvent=document.dispatchEvent.bind(document)}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(I,null)},t.dispatchUserLoggedOutEvent=function(){this.dispatch(A,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 T,q=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:"/"}),U=/*#__PURE__*/function(){function e(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=e.prototype;return n.getAuthCookie=function(){return q.get(this.authCookieName)},n.setAuthCookie=function(e,n){var i={secure:!0,sameSite:this.authCookieSameSite};void 0!==this.authCookieDomain&&(i.domain=this.authCookieDomain);var r=t({},i,n);if(("none"===r.sameSite||"None"===r.sameSite)&&!1===r.secure)throw new d(new Error("Secure attribute must be set when SameSite=None"));q.set(this.authCookieName,e,r)},n.removeAuthCookie=function(){q.remove(this.authCookieName)},e}(),W=/*#__PURE__*/function(){function e(e){this._xhr=void 0,this._xhr=e}return e.prototype.getResponseHeader=function(e){return this._xhr.getResponseHeader(e)},e}(),M=/*#__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 W(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 e(e,n){this.timeout=void 0,this.api=void 0,this.dispatcher=void 0,this.cookie=void 0,this.lang=void 0,this.api=e,this.timeout=n.timeout,this.dispatcher=new D,this.cookie=new U(t({},n)),this.lang=n.lang}var n=e.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.cookie.getAuthCookie(),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 M(n))},n.onerror=function(){c(new d)},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.cookie.getAuthCookie();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.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"})},e}(),K=function(e,t){this.client=void 0,this.client=new H(e,t)},F=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}n(t,e);var i=t.prototype;return i.getDomain=function(e){if(!e)throw new j("somethingWentWrong",new Error("email missing from request"));var t=e.split("@");if(2!==t.length)throw new j("somethingWentWrong",new Error("email is not in a valid email format."));var n=t[1].trim();if(""===n)throw new j("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 E(new Error("provider not found"));if(!e.ok)throw new d(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 j("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 j(i,new Error(n))}},t}(K),J=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}n(t,e);var i=t.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 E;if(!e.ok)throw new d;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 f;if(403===e.status)throw new C;if(!e.ok)throw new d;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 P;if(!t.ok)throw new d;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 P;if(!t.ok)throw new d;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.cookie.removeAuthCookie(),void e.client.dispatcher.dispatchUserDeletedEvent();if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new P;throw new d})}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.cookie.removeAuthCookie(),e.client.dispatcher.dispatchUserLoggedOutEvent(),401===t.status);else if(!t.ok)throw new d})}catch(e){return Promise.reject(e)}},t}(K),B=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}n(t,e);var i=t.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 P;if(!t.ok)throw new d;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 O;if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new P;if(409===e.status)throw new x;throw new d})}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 P;if(!e.ok)throw new d})}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 P;if(!e.ok)throw new d})}catch(e){return Promise.reject(e)}},t}(K),z=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}n(t,e);var i=t.prototype;return i.auth=function(e,t){try{var n=new URL("/thirdparty/auth",this.client.api);if(!e)throw new j("somethingWentWrong",new Error("provider missing from request"));if(!t)throw new j("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 j(i,new Error(n))}},t}(K),V=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return n(t,e),t.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 d;return e.json()})):Promise.resolve()}catch(e){return Promise.reject(e)}},t}(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(_,{callback:e,once:t},!0)},t.onSessionExpired=function(e,t){return this.addEventListener(I,{callback:e,once:t},!0)},t.onUserLoggedOut=function(e,t){return this.addEventListener(A,{callback:e,once:t})},t.onUserDeleted=function(e,t){return this.addEventListener(L,{callback:e,once:t})},e}(),Q=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return n(t,e),t.prototype.validate=function(){try{return Promise.resolve(this.client.get("/sessions/validate")).then(function(e){if(!e.ok)throw new d;return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}},t}(K),Y=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return n(t,e),t.prototype.isValid=function(){var e;try{var t=this.client._fetch_blocking("/sessions/validate",{method:"GET"});e=JSON.parse(t)}catch(e){throw new d(e)}return!!e&&e.is_valid},t}(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 t(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(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}n(t,e);var i=t.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()},t}(D),ie=/*#__PURE__*/u("actionDefinitions"),re=/*#__PURE__*/u("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,h(this,ie)[ie]=s,this.actions=h(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:h(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(T.Required,"is required"),(null!=n.min_length||null!=n.max_length)&&("length"in r||i(T.InvalidInputDefinition,'has min/max length requirement, but is missing "length" property',"string",typeof r),null!=n.min_length&&r<n.min_length&&i(T.MinLength,"too short (min "+n.min_length+")",n.min_length,r.length),null!=n.max_length&&r>n.max_length&&i(T.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"}(T||(T={}));var ae=/*#__PURE__*/function(e){function t(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 n(t,e),t}(/*#__PURE__*/s(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 t(){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}n(t,e);var i=t.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)}},t}(K),le=/*#__PURE__*/function(e){function t(n){var i;return(i=e.call(this,"No handler found for state: "+("string"==typeof n.name?'"'+n.name+'"':"("+typeof n.name+")"),"handlerNotFoundError")||this).state=void 0,i.state=n,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),de=/*#__PURE__*/function(e){function t(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 n(t,e),t}(/*#__PURE__*/s(Error)),fe=/*#__PURE__*/function(e){function t(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"};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),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 n(t,e),t.prototype.setLang=function(e){this.flow.client.lang=e},t}(G),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}();e.ConflictError=f,e.CustomEventWithDetail=R,e.EmailAddressAlreadyExistsError=O,e.EmailClient=B,e.EnterpriseClient=F,e.ForbiddenError=C,e.Hanko=fe,e.HankoError=l,e.InvalidPasscodeError=y,e.InvalidPasswordError=m,e.InvalidWebauthnCredentialError=w,e.MaxNumOfEmailAddressesReachedError=x,e.MaxNumOfPasscodeAttemptsReachedError=k,e.NotFoundError=E,e.PasscodeExpiredError=g,e.RequestTimeoutError=p,e.SessionClient=Q,e.TechnicalError=d,e.ThirdPartyClient=z,e.ThirdPartyError=j,e.TokenClient=V,e.TooManyRequestsError=b,e.UnauthorizedError=P,e.UserClient=J,e.UserVerificationError=S,e.WebauthnRequestCancelledError=v,e.WebauthnSupport=pe,e.sessionCreatedType=_,e.sessionExpiredType=I,e.userDeletedType=L,e.userLoggedOutType=A});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).hankoFrontendSdk={})}(this,function(e){function t(){return t=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},t.apply(this,arguments)}function n(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,r(e,t)}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}function r(e,t){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},r(e,t)}function o(e,t,n){return o=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},o.apply(null,arguments)}function s(e){var t="function"==typeof Map?new Map:void 0;return s=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,n)}function n(){return o(e,arguments,i(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),r(n,e)},s(e)}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var c=0;function u(e){return"__private_"+c+++"_"+e}function h(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var l=/*#__PURE__*/function(e){function t(n,i,r){var o;return(o=e.call(this,n)||this).code=void 0,o.cause=void 0,o.code=i,o.cause=r,Object.setPrototypeOf(a(o),t.prototype),o}return n(t,e),t}(/*#__PURE__*/s(Error)),d=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Technical error","somethingWentWrong",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),f=/*#__PURE__*/function(e){function t(n,i){var r;return r=e.call(this,"Conflict error","conflict",i)||this,Object.setPrototypeOf(a(r),t.prototype),r}return n(t,e),t}(l),p=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Request timed out error","requestTimeout",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),v=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Request cancelled error","requestCancelled",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),m=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Invalid password error","invalidPassword",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),y=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Invalid Passcode error","invalidPasscode",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),w=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Invalid WebAuthn credential error","invalidWebauthnCredential",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),g=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Passcode expired error","passcodeExpired",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),k=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Maximum number of Passcode attempts reached error","passcodeAttemptsReached",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),E=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Not found error","notFound",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),S=/*#__PURE__*/function(e){function t(n,i){var r;return(r=e.call(this,"Too many requests error","tooManyRequests",i)||this).retryAfter=void 0,r.retryAfter=n,Object.setPrototypeOf(a(r),t.prototype),r}return n(t,e),t}(l),b=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Unauthorized error","unauthorized",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),C=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Forbidden error","forbidden",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),P=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"User verification error","userVerification",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),x=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"Maximum number of email addresses reached error","maxNumOfEmailAddressesReached",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),O=/*#__PURE__*/function(e){function t(n){var i;return i=e.call(this,"The email address already exists","emailAddressAlreadyExistsError",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),j=/*#__PURE__*/function(e){function t(n,i){var r;return r=e.call(this,"An error occurred during third party sign up/sign in",n,i)||this,Object.setPrototypeOf(a(r),t.prototype),r}return n(t,e),t}(l),_="hanko-session-created",I="hanko-session-expired",L="hanko-user-logged-out",T="hanko-user-deleted",A=/*#__PURE__*/function(e){function t(t,n){return e.call(this,t,{detail:n})||this}return n(t,e),t}(/*#__PURE__*/s(CustomEvent)),N=/*#__PURE__*/function(){function e(){this._dispatchEvent=document.dispatchEvent.bind(document)}var t=e.prototype;return t.dispatch=function(e,t){this._dispatchEvent(new A(e,t))},t.dispatchSessionCreatedEvent=function(e){this.dispatch(_,e)},t.dispatchSessionExpiredEvent=function(){this.dispatch(I,null)},t.dispatchUserLoggedOutEvent=function(){this.dispatch(L,null)},t.dispatchUserDeletedEvent=function(){this.dispatch(T,null)},e}();function R(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 D,q=function e(t,n){function i(e,i,r){if("undefined"!=typeof document){"number"==typeof(r=R({},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,"",R({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,R({},this.attributes,t))},withConverter:function(t){return e(R({},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:"/"}),M=/*#__PURE__*/function(){function e(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=e.prototype;return n.getAuthCookie=function(){return q.get(this.authCookieName)},n.setAuthCookie=function(e,n){var i={secure:!0,sameSite:this.authCookieSameSite};void 0!==this.authCookieDomain&&(i.domain=this.authCookieDomain);var r=t({},i,n);if(("none"===r.sameSite||"None"===r.sameSite)&&!1===r.secure)throw new d(new Error("Secure attribute must be set when SameSite=None"));q.set(this.authCookieName,e,r)},n.removeAuthCookie=function(){q.remove(this.authCookieName)},e}(),U=/*#__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}(),W=/*#__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 W(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}(),K=/*#__PURE__*/function(){function e(e,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=e,this.timeout=n.timeout,this.dispatcher=new N,this.cookie=new M(t({},n)),this.sessionTokenStorage=new U({keyName:n.cookieName}),this.lang=n.lang,this.sessionTokenLocation=n.sessionTokenLocation}var n=e.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 H(n))},n.onerror=function(){c(new d)},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)}},e}(),F=function(e,t){this.client=void 0,this.client=new K(e,t)},J=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}n(t,e);var i=t.prototype;return i.getDomain=function(e){if(!e)throw new j("somethingWentWrong",new Error("email missing from request"));var t=e.split("@");if(2!==t.length)throw new j("somethingWentWrong",new Error("email is not in a valid email format."));var n=t[1].trim();if(""===n)throw new j("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 E(new Error("provider not found"));if(!e.ok)throw new d(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 j("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 j(i,new Error(n))}},t}(F),B=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}n(t,e);var i=t.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 E;if(!e.ok)throw new d;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 f;if(403===e.status)throw new C;if(!e.ok)throw new d;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 b;if(!t.ok)throw new d;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 b;if(!t.ok)throw new d;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 b;throw new d})}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 d})}catch(e){return Promise.reject(e)}},t}(F),z=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}n(t,e);var i=t.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 b;if(!t.ok)throw new d;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 O;if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new b;if(409===e.status)throw new x;throw new d})}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 b;if(!e.ok)throw new d})}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 b;if(!e.ok)throw new d})}catch(e){return Promise.reject(e)}},t}(F),V=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}n(t,e);var i=t.prototype;return i.auth=function(e,t){try{var n=new URL("/thirdparty/auth",this.client.api);if(!e)throw new j("somethingWentWrong",new Error("provider missing from request"));if(!t)throw new j("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 j(i,new Error(n))}},t}(F),X=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return n(t,e),t.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 d;return e.json()})):Promise.resolve()}catch(e){return Promise.reject(e)}},t}(F),G=/*#__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}(),Q=/*#__PURE__*/function(){function e(){this.throttleLimit=1e3,this._addEventListener=document.addEventListener.bind(document),this._removeEventListener=document.removeEventListener.bind(document),this._throttle=G.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(_,{callback:e,once:t},!0)},t.onSessionExpired=function(e,t){return this.addEventListener(I,{callback:e,once:t},!0)},t.onUserLoggedOut=function(e,t){return this.addEventListener(L,{callback:e,once:t})},t.onUserDeleted=function(e,t){return this.addEventListener(T,{callback:e,once:t})},e}(),Y=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return n(t,e),t.prototype.validate=function(){try{return Promise.resolve(this.client.get("/sessions/validate")).then(function(e){if(!e.ok)throw new d;return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}},t}(F),Z=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return n(t,e),t.prototype.isValid=function(){var e;try{var t=this.client._fetch_blocking("/sessions/validate",{method:"GET"});e=JSON.parse(t)}catch(e){throw new d(e)}return!!e&&e.is_valid},t}(F),$=/*#__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}(),ee=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)},te=/*#__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}(),ne=/*#__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}(),ie=/*#__PURE__*/function(e){function t(t,n){var i;(i=e.call(this)||this).listener=new Q,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 Y(t,n),i.checkInterval=n.sessionCheckInterval,i.sessionState=new $(n.cookieName+"_session_state"),i.sessionChannel=new ne(i.getSessionCheckChannelName(n.sessionTokenLocation,n.sessionCheckChannelName),function(){return i.onChannelSessionExpired()},function(e){return i.onChannelSessionCreated(e)},function(){return i.onChannelLeadershipRequested()}),i.scheduler=new te(i.checkInterval,function(){return i.checkSession()},function(){return i.onSessionExpired()}),i.windowActivityManager=new ee(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}n(t,e);var i=t.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},t}(N),re=/*#__PURE__*/u("actionDefinitions"),oe=/*#__PURE__*/u("createActionsProxy"),se=/*#__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,oe,{value:ae}),this.name=void 0,this.payload=void 0,this.error=void 0,this.status=void 0,this.csrf_token=void 0,Object.defineProperty(this,re,{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,h(this,re)[re]=s,this.actions=h(this,oe)[oe](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:h(this,re)[re]}},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 ce({reason:e,inputName:t,wanted:i,actual:r,message:n})}var r=n.value;n.required&&!r&&i(D.Required,"is required"),(null!=n.min_length||null!=n.max_length)&&("length"in r||i(D.InvalidInputDefinition,'has min/max length requirement, but is missing "length" property',"string",typeof r),null!=n.min_length&&r<n.min_length&&i(D.MinLength,"too short (min "+n.min_length+")",n.min_length,r.length),null!=n.max_length&&r>n.max_length&&i(D.MaxLength,"too long (max "+n.max_length+")",n.max_length,r.length))};for(var n in e.inputs)t(n)}},t}();function ae(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 ce)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"}(D||(D={}));var ce=/*#__PURE__*/function(e){function t(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 n(t,e),t}(/*#__PURE__*/s(Error));function ue(e){return"object"==typeof e&&null!==e&&"status"in e&&"error"in e&&"name"in e&&Boolean(e.name)&&Boolean(e.status)}function he(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var le=/*#__PURE__*/function(e){function t(){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(he(function(){if(!ue(e))throw new fe(e);var i=n[e.name];if(!i)throw new de(e);return Promise.resolve(i(e)).then(function(e){function i(){if(ue(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}n(t,e);var i=t.prototype;return i.init=function(e,t){var n=this;return Promise.resolve(function e(i,r){try{return Promise.resolve(he(function(){return Promise.resolve(n.client.post(i,r)).then(function(t){return new se(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 se(JSON.parse(e),function e(i,r){try{return Promise.resolve(he(function(){return Promise.resolve(n.client.post(i,r)).then(function(t){return new se(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)}},t}(F),de=/*#__PURE__*/function(e){function t(n){var i;return(i=e.call(this,"No handler found for state: "+("string"==typeof n.name?'"'+n.name+'"':"("+typeof n.name+")"),"handlerNotFoundError")||this).state=void 0,i.state=n,Object.setPrototypeOf(a(i),t.prototype),i}return n(t,e),t}(l),fe=/*#__PURE__*/function(e){function t(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 n(t,e),t}(/*#__PURE__*/s(Error)),pe=/*#__PURE__*/function(e){function t(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 B(t,r),i.email=new z(t,r),i.thirdParty=new V(t,r),i.enterprise=new J(t,r),i.token=new X(t,r),i.sessionClient=new Y(t,r),i.session=new Z(t,r),i.relay=new ie(t,r),i.flow=new le(t,r),i}return n(t,e),t.prototype.setLang=function(e){this.flow.client.lang=e},t}(Q),ve=/*#__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}();e.ConflictError=f,e.CustomEventWithDetail=A,e.EmailAddressAlreadyExistsError=O,e.EmailClient=z,e.EnterpriseClient=J,e.ForbiddenError=C,e.Hanko=pe,e.HankoError=l,e.InvalidPasscodeError=y,e.InvalidPasswordError=m,e.InvalidWebauthnCredentialError=w,e.MaxNumOfEmailAddressesReachedError=x,e.MaxNumOfPasscodeAttemptsReachedError=k,e.NotFoundError=E,e.PasscodeExpiredError=g,e.RequestTimeoutError=p,e.SessionClient=Y,e.TechnicalError=d,e.ThirdPartyClient=V,e.ThirdPartyError=j,e.TokenClient=X,e.TooManyRequestsError=S,e.UnauthorizedError=b,e.UserClient=B,e.UserVerificationError=P,e.WebauthnRequestCancelledError=v,e.WebauthnSupport=ve,e.sessionCreatedType=_,e.sessionExpiredType=I,e.userDeletedType=T,e.userLoggedOutType=L});
|
|
2
2
|
//# sourceMappingURL=sdk.umd.js.map
|