@teamhanko/hanko-frontend-sdk 0.8.2 → 0.8.4
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/index.d.ts +2 -2
- package/dist/lib/Cookie.d.ts +14 -2
- package/dist/lib/Dto.d.ts +2 -0
- package/dist/lib/Errors.d.ts +11 -1
- package/dist/sdk.cjs +1 -1
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.modern.js +1 -1
- package/dist/sdk.modern.js.map +1 -1
- package/dist/sdk.module.js +1 -1
- package/dist/sdk.module.js.map +1 -1
- package/dist/sdk.umd.js +1 -1
- package/dist/sdk.umd.js.map +1 -1
- package/package.json +11 -8
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 r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},t.apply(this,arguments)}function r(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 o(e,t,r){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,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&i(o,r.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,r)}function r(){return o(e,arguments,n(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),i(r,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=/*#__PURE__*/function(e){function t(r,n,i){var o;return(o=e.call(this,r)||this).code=void 0,o.cause=void 0,o.code=n,o.cause=i,Object.setPrototypeOf(a(o),t.prototype),o}return r(t,e),t}(/*#__PURE__*/s(Error)),u=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Technical error","somethingWentWrong",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),d=/*#__PURE__*/function(e){function t(r,n){var i;return i=e.call(this,"Conflict error","conflict",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return r(t,e),t}(c),h=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Request timed out error","requestTimeout",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),l=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Request cancelled error","requestCancelled",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),f=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Invalid password error","invalidPassword",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),p=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Invalid Passcode error","invalidPasscode",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),v=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Invalid WebAuthn credential error","invalidWebauthnCredential",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),w=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Passcode expired error","passcodeExpired",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),m=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Maximum number of Passcode attempts reached error","passcodeAttemptsReached",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),y=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Not found error","notFound",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),g=/*#__PURE__*/function(e){function t(r,n){var i;return(i=e.call(this,"Too many requests error","tooManyRequests",n)||this).retryAfter=void 0,i.retryAfter=r,Object.setPrototypeOf(a(i),t.prototype),i}return r(t,e),t}(c),S=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Unauthorized error","unauthorized",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),E=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"User verification error","userVerification",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),P=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Maximum number of email addresses reached error","maxNumOfEmailAddressesReached",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),b=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"The email address already exists","emailAddressAlreadyExistsError",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),k=/*#__PURE__*/function(e){function t(r,n){var i;return i=e.call(this,"An error occurred during third party sign up/sign in",r,n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return r(t,e),t}(c),C=/*#__PURE__*/function(){function e(e){this.key=void 0,this.ls=void 0,this.key=e,this.ls={}}var t=e.prototype;return t.read=function(){var e;try{var t=localStorage.getItem(this.key),r=decodeURIComponent(decodeURI(window.atob(t)));e=JSON.parse(r)}catch(e){return this.ls={},this}return this.ls=e,this},t.write=function(){var e=JSON.stringify(this.ls),t=window.btoa(encodeURI(encodeURIComponent(e)));return localStorage.setItem(this.key,t),this},e.timeToRemainingSeconds=function(e){return void 0===e&&(e=0),e-Math.floor(Date.now()/1e3)},e.remainingSecondsToTime=function(e){return void 0===e&&(e=0),Math.floor(Date.now()/1e3)+e},e}(),_=/*#__PURE__*/function(e){function t(t){return e.call(this,t.localStorageKey+"_session")||this}r(t,e);var n=t.prototype;return n.read=function(){return e.prototype.read.call(this),this},n.getState=function(){var e;return(e=this.ls).session||(e.session={expiry:0,userID:"",authFlowCompleted:!1}),this.ls.session},n.getExpirationSeconds=function(){return C.timeToRemainingSeconds(this.getState().expiry)},n.setExpirationSeconds=function(e){return this.getState().expiry=C.remainingSecondsToTime(e),this},n.getUserID=function(){return this.getState().userID},n.setUserID=function(e){return this.getState().userID=e,this},n.getAuthFlowCompleted=function(){return this.getState().authFlowCompleted},n.setAuthFlowCompleted=function(e){return this.getState().authFlowCompleted=e,this},n.reset=function(){var e=this.getState();return delete e.expiry,delete e.userID,this},t}(C),A=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return r(t,e),t.prototype.getUserState=function(e){var t;return(t=this.ls).users||(t.users={}),Object.prototype.hasOwnProperty.call(this.ls.users,e)||(this.ls.users[e]={}),this.ls.users[e]},t}(C),x=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}r(t,e);var n=t.prototype;return n.getState=function(t){var r;return(r=e.prototype.getUserState.call(this,t)).passcode||(r.passcode={})},n.read=function(){return e.prototype.read.call(this),this},n.getActiveID=function(e){return this.getState(e).id},n.setActiveID=function(e,t){return this.getState(e).id=t,this},n.getEmailID=function(e){return this.getState(e).emailID},n.setEmailID=function(e,t){return this.getState(e).emailID=t,this},n.reset=function(e){var t=this.getState(e);return delete t.id,delete t.ttl,delete t.resendAfter,delete t.emailID,this},n.getTTL=function(e){return C.timeToRemainingSeconds(this.getState(e).ttl)},n.setTTL=function(e,t){return this.getState(e).ttl=C.remainingSecondsToTime(t),this},n.getResendAfter=function(e){return C.timeToRemainingSeconds(this.getState(e).resendAfter)},n.setResendAfter=function(e,t){return this.getState(e).resendAfter=C.remainingSecondsToTime(t),this},t}(A),O="hanko-session-created",j="hanko-session-expired",T="hanko-user-logged-out",R="hanko-user-deleted",I="hanko-auth-flow-completed",D=/*#__PURE__*/function(e){function t(t,r){return e.call(this,t,{detail:r})||this}return r(t,e),t}(/*#__PURE__*/s(CustomEvent)),L=/*#__PURE__*/function(){function e(e){this._dispatchEvent=document.dispatchEvent.bind(document),this._sessionState=void 0,this._sessionState=new _(t({},e))}var r=e.prototype;return r.dispatch=function(e,t){this._dispatchEvent(new D(e,t))},r.dispatchSessionCreatedEvent=function(e){this.dispatch(O,e)},r.dispatchSessionExpiredEvent=function(){this.dispatch(j,null)},r.dispatchUserLoggedOutEvent=function(){this.dispatch(T,null)},r.dispatchUserDeletedEvent=function(){this.dispatch(R,null)},r.dispatchAuthFlowCompletedEvent=function(e){this._sessionState.read().setAuthFlowCompleted(!0).write(),this.dispatch(I,e)},e}();function U(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)e[n]=r[n]}return e}var N=function e(t,r){function n(e,n,i){if("undefined"!=typeof document){"number"==typeof(i=U({},r,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var o="";for(var s in i)i[s]&&(o+="; "+s,!0!==i[s]&&(o+="="+i[s].split(";")[0]));return document.cookie=e+"="+t.write(n,e)+o}}return Object.create({set:n,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var r=document.cookie?document.cookie.split("; "):[],n={},i=0;i<r.length;i++){var o=r[i].split("="),s=o.slice(1).join("=");try{var a=decodeURIComponent(o[0]);if(n[a]=t.read(s,a),e===a)break}catch(e){}}return e?n[e]:n}},remove:function(e,t){n(e,"",U({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,U({},this.attributes,t))},withConverter:function(t){return e(U({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"}),H=/*#__PURE__*/function(){function e(e){this.authCookieName=void 0,this.authCookieName=e.cookieName}var t=e.prototype;return t.getAuthCookie=function(){return N.get(this.authCookieName)},t.setAuthCookie=function(e,t){void 0===t&&(t=!0),N.set(this.authCookieName,e,{secure:t})},t.removeAuthCookie=function(){N.remove(this.authCookieName)},e}(),F=/*#__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 F(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,r){this.timeout=void 0,this.api=void 0,this.sessionState=void 0,this.passcodeState=void 0,this.dispatcher=void 0,this.cookie=void 0,this.api=e,this.timeout=r.timeout,this.sessionState=new _(t({},r)),this.passcodeState=new x(r.cookieName),this.dispatcher=new L(t({},r)),this.cookie=new H(t({},r))}var r=e.prototype;return r._fetch=function(e,t,r){void 0===r&&(r=new XMLHttpRequest);var n=this.api+e,i=this.timeout,o=this.cookie.getAuthCookie();return new Promise(function(e,s){r.open(t.method,n,!0),r.setRequestHeader("Accept","application/json"),r.setRequestHeader("Content-Type","application/json"),o&&r.setRequestHeader("Authorization","Bearer "+o),r.timeout=i,r.withCredentials=!0,r.onload=function(){var t=new W(r);e(t)},r.onerror=function(){s(new u)},r.ontimeout=function(){s(new h)},r.send(t.body?t.body.toString():null)})},r.processResponseHeadersOnLogin=function(e,t){var r="",n=0;if(t.xhr.getAllResponseHeaders().split("\r\n").forEach(function(e){var i=e.toLowerCase();i.startsWith("x-auth-token")?r=t.headers.getResponseHeader("X-Auth-Token"):i.startsWith("x-session-lifetime")&&(n=parseInt(t.headers.getResponseHeader("X-Session-Lifetime"),10))}),r){var i=!!this.api.match("^https://");this.cookie.setAuthCookie(r,i)}this.passcodeState.read().reset(e).write(),n>0&&(this.sessionState.read(),this.sessionState.setExpirationSeconds(n),this.sessionState.setUserID(e),this.sessionState.setAuthFlowCompleted(!1),this.sessionState.write(),this.dispatcher.dispatchSessionCreatedEvent({jwt:r,userID:e,expirationSeconds:n}))},r.get=function(e){return this._fetch(e,{method:"GET"})},r.post=function(e,t){return this._fetch(e,{method:"POST",body:JSON.stringify(t)})},r.put=function(e,t){return this._fetch(e,{method:"PUT",body:JSON.stringify(t)})},r.patch=function(e,t){return this._fetch(e,{method:"PATCH",body:JSON.stringify(t)})},r.delete=function(e){return this._fetch(e,{method:"DELETE"})},e}(),q=function(e,t){this.client=void 0,this.client=new K(e,t)},M=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return r(t,e),t.prototype.get=function(){try{return Promise.resolve(this.client.get("/.well-known/config")).then(function(e){if(!e.ok)throw new u;return e.json()})}catch(e){return Promise.reject(e)}},t}(q),z=/*#__PURE__*/function(e){function t(t,r){var n;return(n=e.call(this,t,r)||this).state=void 0,n.state=new x(r.cookieName),n}r(t,e);var n=t.prototype;return n.initialize=function(e,t,r){try{var n=this;n.state.read();var i=n.state.getTTL(e),o=n.state.getActiveID(e),s=n.state.getEmailID(e),a=n.state.getResendAfter(e);if(a>0)throw new g(a);if(!r&&i>0&&t===s)return Promise.resolve({id:o,ttl:i});var c={user_id:e};return t&&(c.email_id=t),Promise.resolve(n.client.post("/passcode/login/initialize",c)).then(function(r){if(429===r.status)throw a=r.parseNumericHeader("Retry-After"),n.state.setResendAfter(e,a).write(),new g(a);if(!r.ok)throw new u;var i=r.json();return n.state.setActiveID(e,i.id).setTTL(e,i.ttl),t&&n.state.setEmailID(e,t),n.state.write(),i})}catch(e){return Promise.reject(e)}},n.finalize=function(e,t){try{var r=this,n=r.state.read().getActiveID(e);if(r.state.getTTL(e)<=0)throw new w;return Promise.resolve(r.client.post("/passcode/login/finalize",{id:n,code:t})).then(function(t){if(401===t.status)throw new p;if(410===t.status)throw r.state.reset(e).write(),new m;if(!t.ok)throw new u;r.client.processResponseHeadersOnLogin(e,t)})}catch(e){return Promise.reject(e)}},n.getTTL=function(e){return this.state.read().getTTL(e)},n.getResendAfter=function(e){return this.state.read().getResendAfter(e)},t}(q),J=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}r(t,e);var n=t.prototype;return n.getState=function(t){var r;return(r=e.prototype.getUserState.call(this,t)).password||(r.password={})},n.read=function(){return e.prototype.read.call(this),this},n.getRetryAfter=function(e){return C.timeToRemainingSeconds(this.getState(e).retryAfter)},n.setRetryAfter=function(e,t){return this.getState(e).retryAfter=C.remainingSecondsToTime(t),this},t}(A),B=/*#__PURE__*/function(e){function t(t,r){var n;return(n=e.call(this,t,r)||this).passwordState=void 0,n.passcodeState=void 0,n.passwordState=new J(r.cookieName),n.passcodeState=new x(r.cookieName),n}r(t,e);var n=t.prototype;return n.login=function(e,t){try{var r=this;return Promise.resolve(r.client.post("/password/login",{user_id:e,password:t})).then(function(t){if(401===t.status)throw new f;if(429===t.status){var n=t.parseNumericHeader("Retry-After");throw r.passwordState.read().setRetryAfter(e,n).write(),new g(n)}if(!t.ok)throw new u;r.client.processResponseHeadersOnLogin(e,t)})}catch(e){return Promise.reject(e)}},n.update=function(e,t){try{var r=this;return Promise.resolve(r.client.put("/password",{user_id:e,password:t})).then(function(e){if(401===e.status)throw r.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!e.ok)throw new u})}catch(e){return Promise.reject(e)}},n.getRetryAfter=function(e){return this.passwordState.read().getRetryAfter(e)},t}(q),V=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}r(t,e);var n=t.prototype;return n.getInfo=function(e){try{return Promise.resolve(this.client.post("/user",{email:e})).then(function(e){if(404===e.status)throw new y;if(!e.ok)throw new u;return e.json()})}catch(e){return Promise.reject(e)}},n.create=function(e){try{var t=this;return Promise.resolve(t.client.post("/users",{email:e})).then(function(e){if(409===e.status)throw new d;if(!e.ok)throw new u;var r=e.json();return r&&r.user_id&&t.client.processResponseHeadersOnLogin(r.user_id,e),r})}catch(e){return Promise.reject(e)}},n.getCurrent=function(){try{var e=this;return Promise.resolve(e.client.get("/me")).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!t.ok)throw new u;var r=t.json();return Promise.resolve(e.client.get("/users/"+r.id)).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!t.ok)throw new u;return t.json()})})}catch(e){return Promise.reject(e)}},n.delete=function(){try{var e=this;return Promise.resolve(e.client.delete("/user")).then(function(t){if(t.ok)return e.client.cookie.removeAuthCookie(),e.client.sessionState.reset().write(),void e.client.dispatcher.dispatchUserDeletedEvent();if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new S;throw new u})}catch(e){return Promise.reject(e)}},n.logout=function(){try{var e=this;return Promise.resolve(e.client.post("/logout")).then(function(t){if(e.client.cookie.removeAuthCookie(),e.client.sessionState.reset().write(),e.client.dispatcher.dispatchUserLoggedOutEvent(),401===t.status);else if(!t.ok)throw new u})}catch(e){return Promise.reject(e)}},t}(q);function X(e){const t="==".slice(0,(4-e.length%4)%4),r=e.replace(/-/g,"+").replace(/_/g,"/")+t,n=atob(r),i=new ArrayBuffer(n.length),o=new Uint8Array(i);for(let e=0;e<n.length;e++)o[e]=n.charCodeAt(e);return i}function G(e){const t=new Uint8Array(e);let r="";for(const e of t)r+=String.fromCharCode(e);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var $="copy",Q="convert";function Y(e,t,r){if(t===$)return r;if(t===Q)return e(r);if(t instanceof Array)return r.map(r=>Y(e,t[0],r));if(t instanceof Object){const n={};for(const[i,o]of Object.entries(t)){if(o.derive){const e=o.derive(r);void 0!==e&&(r[i]=e)}if(i in r)n[i]=null!=r[i]?Y(e,o.schema,r[i]):null;else if(o.required)throw new Error(`Missing key: ${i}`)}return n}}function Z(e,t){return{required:!0,schema:e,derive:t}}function ee(e){return{required:!0,schema:e}}function te(e){return{required:!1,schema:e}}var re={type:ee($),id:ee(Q),transports:te($)},ne={appid:te($),appidExclude:te($),credProps:te($)},ie={appid:te($),appidExclude:te($),credProps:te($)},oe={publicKey:ee({rp:ee($),user:ee({id:ee(Q),name:ee($),displayName:ee($)}),challenge:ee(Q),pubKeyCredParams:ee($),timeout:te($),excludeCredentials:te([re]),authenticatorSelection:te($),attestation:te($),extensions:te(ne)}),signal:te($)},se={type:ee($),id:ee($),rawId:ee(Q),authenticatorAttachment:te($),response:ee({clientDataJSON:ee(Q),attestationObject:ee(Q),transports:Z($,e=>{var t;return(null==(t=e.getTransports)?void 0:t.call(e))||[]})}),clientExtensionResults:Z(ie,e=>e.getClientExtensionResults())},ae={mediation:te($),publicKey:ee({challenge:ee(Q),timeout:te($),rpId:te($),allowCredentials:te([re]),userVerification:te($),extensions:te(ne)}),signal:te($)},ce={type:ee($),id:ee($),rawId:ee(Q),authenticatorAttachment:te($),response:ee({clientDataJSON:ee(Q),authenticatorData:ee(Q),signature:ee(Q),userHandle:ee(Q)}),clientExtensionResults:Z(ie,e=>e.getClientExtensionResults())};async function ue(e){const t=await navigator.credentials.create(function(e){return Y(X,oe,e)}(e));return function(e){return Y(G,se,e)}(t)}async function de(e){const t=await navigator.credentials.get(function(e){return Y(X,ae,e)}(e));return function(e){return Y(G,ce,e)}(t)}var he=/*#__PURE__*/function(){function e(){}return e.supported=function(){return!!(navigator.credentials&&navigator.credentials.create&&navigator.credentials.get&&window.PublicKeyCredential)},e.isPlatformAuthenticatorAvailable=function(){try{return this.supported()&&window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?Promise.resolve(window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()):Promise.resolve(!1)}catch(e){return Promise.reject(e)}},e.isSecurityKeySupported=function(){try{return void 0!==window.PublicKeyCredential&&window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported?Promise.resolve(window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported()):Promise.resolve(this.supported())}catch(e){return Promise.reject(e)}},e.isConditionalMediationAvailable=function(){try{return window.PublicKeyCredential&&window.PublicKeyCredential.isConditionalMediationAvailable?Promise.resolve(window.PublicKeyCredential.isConditionalMediationAvailable()):Promise.resolve(!1)}catch(e){return Promise.reject(e)}},e}(),le=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}r(t,e);var n=t.prototype;return n.getState=function(t){var r;return(r=e.prototype.getUserState.call(this,t)).webauthn||(r.webauthn={})},n.read=function(){return e.prototype.read.call(this),this},n.getCredentials=function(e){var t;return(t=this.getState(e)).credentials||(t.credentials=[])},n.addCredential=function(e,t){return this.getCredentials(e).push(t),this},n.matchCredentials=function(e,t){return this.getCredentials(e).filter(function(e){return t.find(function(t){return t.id===e})}).map(function(e){return{id:e}})},t}(A);function fe(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var pe=/*#__PURE__*/function(e){function t(t,r){var n;return(n=e.call(this,t,r)||this).webauthnState=void 0,n.passcodeState=void 0,n.controller=void 0,n._getCredential=de,n._createCredential=ue,n.webauthnState=new le(r.cookieName),n.passcodeState=new x(r.cookieName),n}r(t,e);var n=t.prototype;return n.login=function(e,t){try{var r=this;return Promise.resolve(r.client.post("/webauthn/login/initialize",{user_id:e})).then(function(e){var n;function i(e){return n?e:Promise.resolve(r.client.post("/webauthn/login/finalize",o)).then(function(e){if(400===e.status||401===e.status)throw new v;if(!e.ok)throw new u;var t=e.json();return r.webauthnState.read().addCredential(t.user_id,t.credential_id).write(),r.client.processResponseHeadersOnLogin(t.user_id,e),t})}if(!e.ok)throw new u;var o,s=e.json();s.signal=r._createAbortSignal(),t&&(s.mediation="conditional");var a=fe(function(){return Promise.resolve(r._getCredential(s)).then(function(e){o=e})},function(e){throw new l(e)});return a&&a.then?a.then(i):i(a)})}catch(e){return Promise.reject(e)}},n.register=function(){try{var e=this;return Promise.resolve(e.client.post("/webauthn/registration/initialize")).then(function(t){function r(t){return n.transports=n.response.transports,Promise.resolve(e.client.post("/webauthn/registration/finalize",n)).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(422===t.status)throw new E;if(!t.ok)throw new u;var r=t.json();e.webauthnState.read().addCredential(r.user_id,r.credential_id).write()})}if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!t.ok)throw new u;var n,i=t.json();i.signal=e._createAbortSignal();var o=fe(function(){return Promise.resolve(e._createCredential(i)).then(function(e){n=e})},function(e){throw new l(e)});return o&&o.then?o.then(r):r()})}catch(e){return Promise.reject(e)}},n.listCredentials=function(){try{var e=this;return Promise.resolve(e.client.get("/webauthn/credentials")).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!t.ok)throw new u;return t.json()})}catch(e){return Promise.reject(e)}},n.updateCredential=function(e,t){try{var r=this;return Promise.resolve(r.client.patch("/webauthn/credentials/"+e,{name:t})).then(function(e){if(401===e.status)throw r.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!e.ok)throw new u})}catch(e){return Promise.reject(e)}},n.deleteCredential=function(e){try{var t=this;return Promise.resolve(t.client.delete("/webauthn/credentials/"+e)).then(function(e){if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!e.ok)throw new u})}catch(e){return Promise.reject(e)}},n.shouldRegister=function(e){try{var t=he.supported();if(!e.webauthn_credentials||!e.webauthn_credentials.length)return Promise.resolve(t);var r=this.webauthnState.read().matchCredentials(e.id,e.webauthn_credentials);return Promise.resolve(t&&!r.length)}catch(e){return Promise.reject(e)}},n._createAbortSignal=function(){return this.controller&&this.controller.abort(),this.controller=new AbortController,this.controller.signal},t}(q),ve=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}r(t,e);var n=t.prototype;return n.list=function(){try{var e=this;return Promise.resolve(e.client.get("/emails")).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!t.ok)throw new u;return t.json()})}catch(e){return Promise.reject(e)}},n.create=function(e){try{var t=this;return Promise.resolve(t.client.post("/emails",{address:e})).then(function(e){if(e.ok)return e.json();if(400===e.status)throw new b;if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(409===e.status)throw new P;throw new u})}catch(e){return Promise.reject(e)}},n.setPrimaryEmail=function(e){try{var t=this;return Promise.resolve(t.client.post("/emails/"+e+"/set_primary")).then(function(e){if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!e.ok)throw new u})}catch(e){return Promise.reject(e)}},n.delete=function(e){try{var t=this;return Promise.resolve(t.client.delete("/emails/"+e)).then(function(e){if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!e.ok)throw new u})}catch(e){return Promise.reject(e)}},t}(q),we=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}r(t,e);var n=t.prototype;return n.auth=function(e,t){try{var r=new URL("/thirdparty/auth",this.client.api);if(!e)throw new k("somethingWentWrong",new Error("provider missing from request"));if(!t)throw new k("somethingWentWrong",new Error("redirectTo missing from request"));return r.searchParams.append("provider",e),r.searchParams.append("redirect_to",t),window.location.assign(r.href),Promise.resolve()}catch(e){return Promise.reject(e)}},n.getError=function(){var e=new URLSearchParams(window.location.search),t=e.get("error"),r=e.get("error_description");if(t){var n="";switch(t){case"access_denied":n="thirdPartyAccessDenied";break;case"user_conflict":n="emailAddressAlreadyExistsError";break;case"multiple_accounts":n="thirdPartyMultipleAccounts";break;case"unverified_email":n="thirdPartyUnverifiedEmail";break;case"email_maxnum":n="maxNumOfEmailAddressesReached";break;default:n="somethingWentWrong"}return new k(n,new Error(r))}},t}(q),me=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return r(t,e),t.prototype.validate=function(){try{var e=this,t=new URLSearchParams(window.location.search).get("hanko_token");return t?(window.history.replaceState(null,null,window.location.pathname),Promise.resolve(e.client.post("/token",{value:t})).then(function(t){if(!t.ok)throw new u;var r=t.json();e.client.processResponseHeadersOnLogin(r.user_id,t)})):Promise.resolve()}catch(e){return Promise.reject(e)}},t}(q),ye=/*#__PURE__*/function(){function e(){}return e.throttle=function(e,t,r){void 0===r&&(r={});var n,i,o,s=r.leading,a=void 0===s||s,c=r.trailing,u=void 0===c||c,d=0,h=function(){d=!1===a?0:Date.now(),o=null,e.apply(n,i)};return function(){var r=Date.now();d||!1!==a||(d=r);var s=t-(r-d);n=this,i=[].slice.call(arguments),s<=0||s>t?(o&&(window.clearTimeout(o),o=null),d=r,e.apply(n,i)):o||!1===u||(o=window.setTimeout(h,s))}},e}(),ge=/*#__PURE__*/function(){function e(){this.throttleLimit=1e3,this._addEventListener=document.addEventListener.bind(document),this._removeEventListener=document.removeEventListener.bind(document),this._throttle=ye.throttle}var t=e.prototype;return t.wrapCallback=function(e,t){var r=function(t){e(t.detail)};return t?this._throttle(r,this.throttleLimit,{leading:!0,trailing:!1}):r},t.addEventListenerWithType=function(e){var t=this,r=e.type,n=e.once,i=void 0!==n&&n,o=e.throttle,s=this.wrapCallback(e.callback,void 0!==o&&o);return this._addEventListener(r,s,{once:i}),function(){return t._removeEventListener(r,s)}},e.mapAddEventListenerParams=function(e,t,r){return{type:e,callback:t.callback,once:t.once,throttle:r}},t.addEventListener=function(t,r,n){return this.addEventListenerWithType(e.mapAddEventListenerParams(t,r,n))},t.onSessionCreated=function(e,t){return this.addEventListener(O,{callback:e,once:t},!0)},t.onSessionExpired=function(e,t){return this.addEventListener(j,{callback:e,once:t},!0)},t.onUserLoggedOut=function(e,t){return this.addEventListener(T,{callback:e,once:t})},t.onUserDeleted=function(e,t){return this.addEventListener(R,{callback:e,once:t})},t.onAuthFlowCompleted=function(e,t){return this.addEventListener(I,{callback:e,once:t})},e}(),Se=/*#__PURE__*/function(){function e(){this._tasks=[]}var t=e.prototype;return t.removeTask=function(e){window.clearTimeout(e.timeoutID),this._tasks=this._tasks.filter(function(t){return t!==e})},t.removeTasksWithType=function(e){var t=this;this._tasks.filter(function(t){return t.type===e}).forEach(function(e){return t.removeTask(e)})},t.scheduleTask=function(e,t,r){var n=this,i={timeoutID:window.setTimeout(function(){t(),n.removeTask(i)},1e3*r),type:e,func:t};this._tasks.push(i)},e}(),Ee=/*#__PURE__*/function(){function e(e){this._sessionState=void 0,this._cookie=void 0,this._sessionState=new _(t({},e)),this._cookie=new H(t({},e))}var r=e.prototype;return r.get=function(){var t=this._get();return e.validate(t)?t:null},r.isValid=function(){var t=this._get();return e.validate(t)},r._get=function(){return this._sessionState.read(),{userID:this._sessionState.getUserID(),expirationSeconds:this._sessionState.getExpirationSeconds(),jwt:this._cookie.getAuthCookie()}},r.isAuthFlowCompleted=function(){return this._sessionState.read(),this._sessionState.getAuthFlowCompleted()},e.validate=function(e){var t;return!!(e.expirationSeconds>0&&null!=(t=e.userID)&&t.length)},e}(),Pe=/*#__PURE__*/function(e){function n(r){var n;return(n=e.call(this,t({},r))||this)._listener=new ge,n._scheduler=new Se,n._session=void 0,n.scheduleSessionExpiredEvent=function(e){n._scheduler.removeTasksWithType(j),n._scheduler.scheduleTask(j,function(){return n.dispatchSessionExpiredEvent()},e.expirationSeconds)},n.cancelSessionExpiredEvent=function(){n._scheduler.removeTasksWithType(j)},n.handleStorageEvent=function(e){if("hanko_session"===e.key){var t=n._session.get();t?n._session.isAuthFlowCompleted()?n.dispatchAuthFlowCompletedEvent({userID:t.userID}):n.dispatchSessionCreatedEvent(t):n.dispatchSessionExpiredEvent()}},n._session=new Ee(t({},r)),n.listenEventDependencies(),n}return r(n,e),n.prototype.listenEventDependencies=function(){this._listener.onSessionCreated(this.scheduleSessionExpiredEvent),this._listener.onSessionExpired(this.cancelSessionExpiredEvent),this._listener.onUserDeleted(this.cancelSessionExpiredEvent),this._listener.onUserLoggedOut(this.cancelSessionExpiredEvent),window.addEventListener("storage",this.handleStorageEvent);var e=this._session.get();e&&this.scheduleSessionExpiredEvent(e)},n}(L),be=/*#__PURE__*/function(e){function n(r,n){var i;(i=e.call(this)||this).api=void 0,i.config=void 0,i.user=void 0,i.webauthn=void 0,i.password=void 0,i.passcode=void 0,i.email=void 0,i.thirdParty=void 0,i.token=void 0,i.relay=void 0,i.session=void 0;var o={timeout:13e3,cookieName:"hanko",localStorageKey:"hanko"};return void 0!==(null==n?void 0:n.cookieName)&&(o.cookieName=n.cookieName),void 0!==(null==n?void 0:n.timeout)&&(o.timeout=n.timeout),void 0!==(null==n?void 0:n.localStorageKey)&&(o.localStorageKey=n.localStorageKey),i.api=r,i.config=new M(r,o),i.user=new V(r,o),i.webauthn=new pe(r,o),i.password=new B(r,o),i.passcode=new z(r,o),i.email=new ve(r,o),i.thirdParty=new we(r,o),i.token=new me(r,o),i.relay=new Pe(t({},o)),i.session=new Ee(t({},o)),i}return r(n,e),n}(ge);e.ConfigClient=M,e.ConflictError=d,e.CustomEventWithDetail=D,e.EmailAddressAlreadyExistsError=b,e.EmailClient=ve,e.Hanko=be,e.HankoError=c,e.InvalidPasscodeError=p,e.InvalidPasswordError=f,e.InvalidWebauthnCredentialError=v,e.MaxNumOfEmailAddressesReachedError=P,e.MaxNumOfPasscodeAttemptsReachedError=m,e.NotFoundError=y,e.PasscodeClient=z,e.PasscodeExpiredError=w,e.PasswordClient=B,e.RequestTimeoutError=h,e.TechnicalError=u,e.ThirdPartyClient=we,e.ThirdPartyError=k,e.TokenClient=me,e.TooManyRequestsError=g,e.UnauthorizedError=S,e.UserClient=V,e.UserVerificationError=E,e.WebauthnClient=pe,e.WebauthnRequestCancelledError=l,e.WebauthnSupport=he,e.authFlowCompletedType=I,e.sessionCreatedType=O,e.sessionExpiredType=j,e.userDeletedType=R,e.userLoggedOutType=T});
|
|
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 r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},t.apply(this,arguments)}function r(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 o(e,t,r){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,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&i(o,r.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,r)}function r(){return o(e,arguments,n(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),i(r,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=/*#__PURE__*/function(e){function t(r,n,i){var o;return(o=e.call(this,r)||this).code=void 0,o.cause=void 0,o.code=n,o.cause=i,Object.setPrototypeOf(a(o),t.prototype),o}return r(t,e),t}(/*#__PURE__*/s(Error)),u=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Technical error","somethingWentWrong",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),d=/*#__PURE__*/function(e){function t(r,n){var i;return i=e.call(this,"Conflict error","conflict",n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return r(t,e),t}(c),h=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Request timed out error","requestTimeout",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),l=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Request cancelled error","requestCancelled",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),f=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Invalid password error","invalidPassword",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),p=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Invalid Passcode error","invalidPasscode",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),v=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Invalid WebAuthn credential error","invalidWebauthnCredential",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),w=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Passcode expired error","passcodeExpired",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),m=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Maximum number of Passcode attempts reached error","passcodeAttemptsReached",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),y=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Not found error","notFound",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),g=/*#__PURE__*/function(e){function t(r,n){var i;return(i=e.call(this,"Too many requests error","tooManyRequests",n)||this).retryAfter=void 0,i.retryAfter=r,Object.setPrototypeOf(a(i),t.prototype),i}return r(t,e),t}(c),S=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Unauthorized error","unauthorized",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),E=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Forbidden error","forbidden",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),b=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"User verification error","userVerification",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),P=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"Maximum number of email addresses reached error","maxNumOfEmailAddressesReached",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),k=/*#__PURE__*/function(e){function t(r){var n;return n=e.call(this,"The email address already exists","emailAddressAlreadyExistsError",r)||this,Object.setPrototypeOf(a(n),t.prototype),n}return r(t,e),t}(c),C=/*#__PURE__*/function(e){function t(r,n){var i;return i=e.call(this,"An error occurred during third party sign up/sign in",r,n)||this,Object.setPrototypeOf(a(i),t.prototype),i}return r(t,e),t}(c),_=/*#__PURE__*/function(){function e(e){this.key=void 0,this.ls=void 0,this.key=e,this.ls={}}var t=e.prototype;return t.read=function(){var e;try{var t=localStorage.getItem(this.key),r=decodeURIComponent(decodeURI(window.atob(t)));e=JSON.parse(r)}catch(e){return this.ls={},this}return this.ls=e,this},t.write=function(){var e=JSON.stringify(this.ls),t=window.btoa(encodeURI(encodeURIComponent(e)));return localStorage.setItem(this.key,t),this},e.timeToRemainingSeconds=function(e){return void 0===e&&(e=0),e-Math.floor(Date.now()/1e3)},e.remainingSecondsToTime=function(e){return void 0===e&&(e=0),Math.floor(Date.now()/1e3)+e},e}(),x=/*#__PURE__*/function(e){function t(t){return e.call(this,t.localStorageKey+"_session")||this}r(t,e);var n=t.prototype;return n.read=function(){return e.prototype.read.call(this),this},n.getState=function(){var e;return(e=this.ls).session||(e.session={expiry:0,userID:"",authFlowCompleted:!1}),this.ls.session},n.getExpirationSeconds=function(){return _.timeToRemainingSeconds(this.getState().expiry)},n.setExpirationSeconds=function(e){return this.getState().expiry=_.remainingSecondsToTime(e),this},n.getUserID=function(){return this.getState().userID},n.setUserID=function(e){return this.getState().userID=e,this},n.getAuthFlowCompleted=function(){return this.getState().authFlowCompleted},n.setAuthFlowCompleted=function(e){return this.getState().authFlowCompleted=e,this},n.reset=function(){var e=this.getState();return delete e.expiry,delete e.userID,this},t}(_),A=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return r(t,e),t.prototype.getUserState=function(e){var t;return(t=this.ls).users||(t.users={}),Object.prototype.hasOwnProperty.call(this.ls.users,e)||(this.ls.users[e]={}),this.ls.users[e]},t}(_),O=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}r(t,e);var n=t.prototype;return n.getState=function(t){var r;return(r=e.prototype.getUserState.call(this,t)).passcode||(r.passcode={})},n.read=function(){return e.prototype.read.call(this),this},n.getActiveID=function(e){return this.getState(e).id},n.setActiveID=function(e,t){return this.getState(e).id=t,this},n.getEmailID=function(e){return this.getState(e).emailID},n.setEmailID=function(e,t){return this.getState(e).emailID=t,this},n.reset=function(e){var t=this.getState(e);return delete t.id,delete t.ttl,delete t.resendAfter,delete t.emailID,this},n.getTTL=function(e){return _.timeToRemainingSeconds(this.getState(e).ttl)},n.setTTL=function(e,t){return this.getState(e).ttl=_.remainingSecondsToTime(t),this},n.getResendAfter=function(e){return _.timeToRemainingSeconds(this.getState(e).resendAfter)},n.setResendAfter=function(e,t){return this.getState(e).resendAfter=_.remainingSecondsToTime(t),this},t}(A),j="hanko-session-created",T="hanko-session-expired",R="hanko-user-logged-out",I="hanko-user-deleted",D="hanko-auth-flow-completed",L=/*#__PURE__*/function(e){function t(t,r){return e.call(this,t,{detail:r})||this}return r(t,e),t}(/*#__PURE__*/s(CustomEvent)),U=/*#__PURE__*/function(){function e(e){this._dispatchEvent=document.dispatchEvent.bind(document),this._sessionState=void 0,this._sessionState=new x(t({},e))}var r=e.prototype;return r.dispatch=function(e,t){this._dispatchEvent(new L(e,t))},r.dispatchSessionCreatedEvent=function(e){this.dispatch(j,e)},r.dispatchSessionExpiredEvent=function(){this.dispatch(T,null)},r.dispatchUserLoggedOutEvent=function(){this.dispatch(R,null)},r.dispatchUserDeletedEvent=function(){this.dispatch(I,null)},r.dispatchAuthFlowCompletedEvent=function(e){this._sessionState.read().setAuthFlowCompleted(!0).write(),this.dispatch(D,e)},e}();function N(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)e[n]=r[n]}return e}var F=function e(t,r){function n(e,n,i){if("undefined"!=typeof document){"number"==typeof(i=N({},r,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var o="";for(var s in i)i[s]&&(o+="; "+s,!0!==i[s]&&(o+="="+i[s].split(";")[0]));return document.cookie=e+"="+t.write(n,e)+o}}return Object.create({set:n,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var r=document.cookie?document.cookie.split("; "):[],n={},i=0;i<r.length;i++){var o=r[i].split("="),s=o.slice(1).join("=");try{var a=decodeURIComponent(o[0]);if(n[a]=t.read(s,a),e===a)break}catch(e){}}return e?n[e]:n}},remove:function(e,t){n(e,"",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(r)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"}),H=/*#__PURE__*/function(){function e(e){this.authCookieName=void 0,this.authCookieName=e.cookieName}var t=e.prototype;return t.getAuthCookie=function(){return F.get(this.authCookieName)},t.setAuthCookie=function(e,t){void 0===t&&(t={secure:!0}),F.set(this.authCookieName,e,t)},t.removeAuthCookie=function(){F.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}(),K=/*#__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}(),q=/*#__PURE__*/function(){function e(e,r){this.timeout=void 0,this.api=void 0,this.sessionState=void 0,this.passcodeState=void 0,this.dispatcher=void 0,this.cookie=void 0,this.api=e,this.timeout=r.timeout,this.sessionState=new x(t({},r)),this.passcodeState=new O(r.cookieName),this.dispatcher=new U(t({},r)),this.cookie=new H(t({},r))}var r=e.prototype;return r._fetch=function(e,t,r){void 0===r&&(r=new XMLHttpRequest);var n=this.api+e,i=this.timeout,o=this.cookie.getAuthCookie();return new Promise(function(e,s){r.open(t.method,n,!0),r.setRequestHeader("Accept","application/json"),r.setRequestHeader("Content-Type","application/json"),o&&r.setRequestHeader("Authorization","Bearer "+o),r.timeout=i,r.withCredentials=!0,r.onload=function(){var t=new K(r);e(t)},r.onerror=function(){s(new u)},r.ontimeout=function(){s(new h)},r.send(t.body?t.body.toString():null)})},r.processResponseHeadersOnLogin=function(e,t){var r="",n=0;if(t.xhr.getAllResponseHeaders().split("\r\n").forEach(function(e){var i=e.toLowerCase();i.startsWith("x-auth-token")?r=t.headers.getResponseHeader("X-Auth-Token"):i.startsWith("x-session-lifetime")&&(n=parseInt(t.headers.getResponseHeader("X-Session-Lifetime"),10))}),r){var i=!!this.api.match("^https://"),o=new Date((new Date).getTime()+1e3*n);this.cookie.setAuthCookie(r,{secure:i,expires:o})}this.passcodeState.read().reset(e).write(),n>0&&(this.sessionState.read(),this.sessionState.setExpirationSeconds(n),this.sessionState.setUserID(e),this.sessionState.setAuthFlowCompleted(!1),this.sessionState.write(),this.dispatcher.dispatchSessionCreatedEvent({jwt:r,userID:e,expirationSeconds:n}))},r.get=function(e){return this._fetch(e,{method:"GET"})},r.post=function(e,t){return this._fetch(e,{method:"POST",body:JSON.stringify(t)})},r.put=function(e,t){return this._fetch(e,{method:"PUT",body:JSON.stringify(t)})},r.patch=function(e,t){return this._fetch(e,{method:"PATCH",body:JSON.stringify(t)})},r.delete=function(e){return this._fetch(e,{method:"DELETE"})},e}(),M=function(e,t){this.client=void 0,this.client=new q(e,t)},z=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return r(t,e),t.prototype.get=function(){try{return Promise.resolve(this.client.get("/.well-known/config")).then(function(e){if(!e.ok)throw new u;return e.json()})}catch(e){return Promise.reject(e)}},t}(M),J=/*#__PURE__*/function(e){function t(t,r){var n;return(n=e.call(this,t,r)||this).state=void 0,n.state=new O(r.cookieName),n}r(t,e);var n=t.prototype;return n.initialize=function(e,t,r){try{var n=this;n.state.read();var i=n.state.getTTL(e),o=n.state.getActiveID(e),s=n.state.getEmailID(e),a=n.state.getResendAfter(e);if(a>0)throw new g(a);if(!r&&i>0&&t===s)return Promise.resolve({id:o,ttl:i});var c={user_id:e};return t&&(c.email_id=t),Promise.resolve(n.client.post("/passcode/login/initialize",c)).then(function(r){if(429===r.status)throw a=r.parseNumericHeader("Retry-After"),n.state.setResendAfter(e,a).write(),new g(a);if(!r.ok)throw new u;var i=r.json();return n.state.setActiveID(e,i.id).setTTL(e,i.ttl),t&&n.state.setEmailID(e,t),n.state.write(),i})}catch(e){return Promise.reject(e)}},n.finalize=function(e,t){try{var r=this,n=r.state.read().getActiveID(e);if(r.state.getTTL(e)<=0)throw new w;return Promise.resolve(r.client.post("/passcode/login/finalize",{id:n,code:t})).then(function(t){if(401===t.status)throw new p;if(410===t.status)throw r.state.reset(e).write(),new m;if(!t.ok)throw new u;r.client.processResponseHeadersOnLogin(e,t)})}catch(e){return Promise.reject(e)}},n.getTTL=function(e){return this.state.read().getTTL(e)},n.getResendAfter=function(e){return this.state.read().getResendAfter(e)},t}(M),B=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}r(t,e);var n=t.prototype;return n.getState=function(t){var r;return(r=e.prototype.getUserState.call(this,t)).password||(r.password={})},n.read=function(){return e.prototype.read.call(this),this},n.getRetryAfter=function(e){return _.timeToRemainingSeconds(this.getState(e).retryAfter)},n.setRetryAfter=function(e,t){return this.getState(e).retryAfter=_.remainingSecondsToTime(t),this},t}(A),V=/*#__PURE__*/function(e){function t(t,r){var n;return(n=e.call(this,t,r)||this).passwordState=void 0,n.passcodeState=void 0,n.passwordState=new B(r.cookieName),n.passcodeState=new O(r.cookieName),n}r(t,e);var n=t.prototype;return n.login=function(e,t){try{var r=this;return Promise.resolve(r.client.post("/password/login",{user_id:e,password:t})).then(function(t){if(401===t.status)throw new f;if(429===t.status){var n=t.parseNumericHeader("Retry-After");throw r.passwordState.read().setRetryAfter(e,n).write(),new g(n)}if(!t.ok)throw new u;r.client.processResponseHeadersOnLogin(e,t)})}catch(e){return Promise.reject(e)}},n.update=function(e,t){try{var r=this;return Promise.resolve(r.client.put("/password",{user_id:e,password:t})).then(function(e){if(401===e.status)throw r.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!e.ok)throw new u})}catch(e){return Promise.reject(e)}},n.getRetryAfter=function(e){return this.passwordState.read().getRetryAfter(e)},t}(M),X=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}r(t,e);var n=t.prototype;return n.getInfo=function(e){try{return Promise.resolve(this.client.post("/user",{email:e})).then(function(e){if(404===e.status)throw new y;if(!e.ok)throw new u;return e.json()})}catch(e){return Promise.reject(e)}},n.create=function(e){try{var t=this;return Promise.resolve(t.client.post("/users",{email:e})).then(function(e){if(409===e.status)throw new d;if(403===e.status)throw new E;if(!e.ok)throw new u;var r=e.json();return r&&r.user_id&&t.client.processResponseHeadersOnLogin(r.user_id,e),r})}catch(e){return Promise.reject(e)}},n.getCurrent=function(){try{var e=this;return Promise.resolve(e.client.get("/me")).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!t.ok)throw new u;var r=t.json();return Promise.resolve(e.client.get("/users/"+r.id)).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!t.ok)throw new u;return t.json()})})}catch(e){return Promise.reject(e)}},n.delete=function(){try{var e=this;return Promise.resolve(e.client.delete("/user")).then(function(t){if(t.ok)return e.client.cookie.removeAuthCookie(),e.client.sessionState.reset().write(),void e.client.dispatcher.dispatchUserDeletedEvent();if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new S;throw new u})}catch(e){return Promise.reject(e)}},n.logout=function(){try{var e=this;return Promise.resolve(e.client.post("/logout")).then(function(t){if(e.client.cookie.removeAuthCookie(),e.client.sessionState.reset().write(),e.client.dispatcher.dispatchUserLoggedOutEvent(),401===t.status);else if(!t.ok)throw new u})}catch(e){return Promise.reject(e)}},t}(M);function G(e){const t="==".slice(0,(4-e.length%4)%4),r=e.replace(/-/g,"+").replace(/_/g,"/")+t,n=atob(r),i=new ArrayBuffer(n.length),o=new Uint8Array(i);for(let e=0;e<n.length;e++)o[e]=n.charCodeAt(e);return i}function $(e){const t=new Uint8Array(e);let r="";for(const e of t)r+=String.fromCharCode(e);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var Q="copy",Y="convert";function Z(e,t,r){if(t===Q)return r;if(t===Y)return e(r);if(t instanceof Array)return r.map(r=>Z(e,t[0],r));if(t instanceof Object){const n={};for(const[i,o]of Object.entries(t)){if(o.derive){const e=o.derive(r);void 0!==e&&(r[i]=e)}if(i in r)n[i]=null!=r[i]?Z(e,o.schema,r[i]):null;else if(o.required)throw new Error(`Missing key: ${i}`)}return n}}function ee(e,t){return{required:!0,schema:e,derive:t}}function te(e){return{required:!0,schema:e}}function re(e){return{required:!1,schema:e}}var ne={type:te(Q),id:te(Y),transports:re(Q)},ie={appid:re(Q),appidExclude:re(Q),credProps:re(Q)},oe={appid:re(Q),appidExclude:re(Q),credProps:re(Q)},se={publicKey:te({rp:te(Q),user:te({id:te(Y),name:te(Q),displayName:te(Q)}),challenge:te(Y),pubKeyCredParams:te(Q),timeout:re(Q),excludeCredentials:re([ne]),authenticatorSelection:re(Q),attestation:re(Q),extensions:re(ie)}),signal:re(Q)},ae={type:te(Q),id:te(Q),rawId:te(Y),authenticatorAttachment:re(Q),response:te({clientDataJSON:te(Y),attestationObject:te(Y),transports:ee(Q,e=>{var t;return(null==(t=e.getTransports)?void 0:t.call(e))||[]})}),clientExtensionResults:ee(oe,e=>e.getClientExtensionResults())},ce={mediation:re(Q),publicKey:te({challenge:te(Y),timeout:re(Q),rpId:re(Q),allowCredentials:re([ne]),userVerification:re(Q),extensions:re(ie)}),signal:re(Q)},ue={type:te(Q),id:te(Q),rawId:te(Y),authenticatorAttachment:re(Q),response:te({clientDataJSON:te(Y),authenticatorData:te(Y),signature:te(Y),userHandle:te(Y)}),clientExtensionResults:ee(oe,e=>e.getClientExtensionResults())};async function de(e){const t=await navigator.credentials.create(function(e){return Z(G,se,e)}(e));return function(e){return Z($,ae,e)}(t)}async function he(e){const t=await navigator.credentials.get(function(e){return Z(G,ce,e)}(e));return function(e){return Z($,ue,e)}(t)}var le=/*#__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}(),fe=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}r(t,e);var n=t.prototype;return n.getState=function(t){var r;return(r=e.prototype.getUserState.call(this,t)).webauthn||(r.webauthn={})},n.read=function(){return e.prototype.read.call(this),this},n.getCredentials=function(e){var t;return(t=this.getState(e)).credentials||(t.credentials=[])},n.addCredential=function(e,t){return this.getCredentials(e).push(t),this},n.matchCredentials=function(e,t){return this.getCredentials(e).filter(function(e){return t.find(function(t){return t.id===e})}).map(function(e){return{id:e}})},t}(A);function pe(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var ve=/*#__PURE__*/function(e){function t(t,r){var n;return(n=e.call(this,t,r)||this).webauthnState=void 0,n.passcodeState=void 0,n.controller=void 0,n._getCredential=he,n._createCredential=de,n.webauthnState=new fe(r.cookieName),n.passcodeState=new O(r.cookieName),n}r(t,e);var n=t.prototype;return n.login=function(e,t){try{var r=this;return Promise.resolve(r.client.post("/webauthn/login/initialize",{user_id:e})).then(function(e){var n;function i(e){return n?e:Promise.resolve(r.client.post("/webauthn/login/finalize",o)).then(function(e){if(400===e.status||401===e.status)throw new v;if(!e.ok)throw new u;var t=e.json();return r.webauthnState.read().addCredential(t.user_id,t.credential_id).write(),r.client.processResponseHeadersOnLogin(t.user_id,e),t})}if(!e.ok)throw new u;var o,s=e.json();s.signal=r._createAbortSignal(),t&&(s.mediation="conditional");var a=pe(function(){return Promise.resolve(r._getCredential(s)).then(function(e){o=e})},function(e){throw new l(e)});return a&&a.then?a.then(i):i(a)})}catch(e){return Promise.reject(e)}},n.register=function(){try{var e=this;return Promise.resolve(e.client.post("/webauthn/registration/initialize")).then(function(t){function r(t){return n.transports=n.response.transports,Promise.resolve(e.client.post("/webauthn/registration/finalize",n)).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(422===t.status)throw new b;if(!t.ok)throw new u;var r=t.json();e.webauthnState.read().addCredential(r.user_id,r.credential_id).write()})}if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!t.ok)throw new u;var n,i=t.json();i.signal=e._createAbortSignal();var o=pe(function(){return Promise.resolve(e._createCredential(i)).then(function(e){n=e})},function(e){throw new l(e)});return o&&o.then?o.then(r):r()})}catch(e){return Promise.reject(e)}},n.listCredentials=function(){try{var e=this;return Promise.resolve(e.client.get("/webauthn/credentials")).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!t.ok)throw new u;return t.json()})}catch(e){return Promise.reject(e)}},n.updateCredential=function(e,t){try{var r=this;return Promise.resolve(r.client.patch("/webauthn/credentials/"+e,{name:t})).then(function(e){if(401===e.status)throw r.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!e.ok)throw new u})}catch(e){return Promise.reject(e)}},n.deleteCredential=function(e){try{var t=this;return Promise.resolve(t.client.delete("/webauthn/credentials/"+e)).then(function(e){if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!e.ok)throw new u})}catch(e){return Promise.reject(e)}},n.shouldRegister=function(e){try{var t=le.supported();if(!e.webauthn_credentials||!e.webauthn_credentials.length)return Promise.resolve(t);var r=this.webauthnState.read().matchCredentials(e.id,e.webauthn_credentials);return Promise.resolve(t&&!r.length)}catch(e){return Promise.reject(e)}},n._createAbortSignal=function(){return this.controller&&this.controller.abort(),this.controller=new AbortController,this.controller.signal},t}(M),we=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}r(t,e);var n=t.prototype;return n.list=function(){try{var e=this;return Promise.resolve(e.client.get("/emails")).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!t.ok)throw new u;return t.json()})}catch(e){return Promise.reject(e)}},n.create=function(e){try{var t=this;return Promise.resolve(t.client.post("/emails",{address:e})).then(function(e){if(e.ok)return e.json();if(400===e.status)throw new k;if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(409===e.status)throw new P;throw new u})}catch(e){return Promise.reject(e)}},n.setPrimaryEmail=function(e){try{var t=this;return Promise.resolve(t.client.post("/emails/"+e+"/set_primary")).then(function(e){if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!e.ok)throw new u})}catch(e){return Promise.reject(e)}},n.delete=function(e){try{var t=this;return Promise.resolve(t.client.delete("/emails/"+e)).then(function(e){if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new S;if(!e.ok)throw new u})}catch(e){return Promise.reject(e)}},t}(M),me=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}r(t,e);var n=t.prototype;return n.auth=function(e,t){try{var r=new URL("/thirdparty/auth",this.client.api);if(!e)throw new C("somethingWentWrong",new Error("provider missing from request"));if(!t)throw new C("somethingWentWrong",new Error("redirectTo missing from request"));return r.searchParams.append("provider",e),r.searchParams.append("redirect_to",t),window.location.assign(r.href),Promise.resolve()}catch(e){return Promise.reject(e)}},n.getError=function(){var e=new URLSearchParams(window.location.search),t=e.get("error"),r=e.get("error_description");if(t){var n="";switch(t){case"access_denied":n="thirdPartyAccessDenied";break;case"user_conflict":n="emailAddressAlreadyExistsError";break;case"multiple_accounts":n="thirdPartyMultipleAccounts";break;case"unverified_email":n="thirdPartyUnverifiedEmail";break;case"email_maxnum":n="maxNumOfEmailAddressesReached";break;default:n="somethingWentWrong"}return new C(n,new Error(r))}},t}(M),ye=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return r(t,e),t.prototype.validate=function(){try{var e=this,t=new URLSearchParams(window.location.search).get("hanko_token");return t?(window.history.replaceState(null,null,window.location.pathname),Promise.resolve(e.client.post("/token",{value:t})).then(function(t){if(!t.ok)throw new u;var r=t.json();e.client.processResponseHeadersOnLogin(r.user_id,t)})):Promise.resolve()}catch(e){return Promise.reject(e)}},t}(M),ge=/*#__PURE__*/function(){function e(){}return e.throttle=function(e,t,r){void 0===r&&(r={});var n,i,o,s=r.leading,a=void 0===s||s,c=r.trailing,u=void 0===c||c,d=0,h=function(){d=!1===a?0:Date.now(),o=null,e.apply(n,i)};return function(){var r=Date.now();d||!1!==a||(d=r);var s=t-(r-d);n=this,i=[].slice.call(arguments),s<=0||s>t?(o&&(window.clearTimeout(o),o=null),d=r,e.apply(n,i)):o||!1===u||(o=window.setTimeout(h,s))}},e}(),Se=/*#__PURE__*/function(){function e(){this.throttleLimit=1e3,this._addEventListener=document.addEventListener.bind(document),this._removeEventListener=document.removeEventListener.bind(document),this._throttle=ge.throttle}var t=e.prototype;return t.wrapCallback=function(e,t){var r=function(t){e(t.detail)};return t?this._throttle(r,this.throttleLimit,{leading:!0,trailing:!1}):r},t.addEventListenerWithType=function(e){var t=this,r=e.type,n=e.once,i=void 0!==n&&n,o=e.throttle,s=this.wrapCallback(e.callback,void 0!==o&&o);return this._addEventListener(r,s,{once:i}),function(){return t._removeEventListener(r,s)}},e.mapAddEventListenerParams=function(e,t,r){return{type:e,callback:t.callback,once:t.once,throttle:r}},t.addEventListener=function(t,r,n){return this.addEventListenerWithType(e.mapAddEventListenerParams(t,r,n))},t.onSessionCreated=function(e,t){return this.addEventListener(j,{callback:e,once:t},!0)},t.onSessionExpired=function(e,t){return this.addEventListener(T,{callback:e,once:t},!0)},t.onUserLoggedOut=function(e,t){return this.addEventListener(R,{callback:e,once:t})},t.onUserDeleted=function(e,t){return this.addEventListener(I,{callback:e,once:t})},t.onAuthFlowCompleted=function(e,t){return this.addEventListener(D,{callback:e,once:t})},e}(),Ee=/*#__PURE__*/function(){function e(){this._tasks=[]}var t=e.prototype;return t.removeTask=function(e){window.clearTimeout(e.timeoutID),this._tasks=this._tasks.filter(function(t){return t!==e})},t.removeTasksWithType=function(e){var t=this;this._tasks.filter(function(t){return t.type===e}).forEach(function(e){return t.removeTask(e)})},t.scheduleTask=function(e,t,r){var n=this,i={timeoutID:window.setTimeout(function(){t(),n.removeTask(i)},1e3*r),type:e,func:t};this._tasks.push(i)},e}(),be=/*#__PURE__*/function(){function e(e){this._sessionState=void 0,this._cookie=void 0,this._sessionState=new x(t({},e)),this._cookie=new H(t({},e))}var r=e.prototype;return r.get=function(){var t=this._get();return e.validate(t)?t:null},r.isValid=function(){var t=this._get();return e.validate(t)},r._get=function(){return this._sessionState.read(),{userID:this._sessionState.getUserID(),expirationSeconds:this._sessionState.getExpirationSeconds(),jwt:this._cookie.getAuthCookie()}},r.isAuthFlowCompleted=function(){return this._sessionState.read(),this._sessionState.getAuthFlowCompleted()},e.validate=function(e){var t;return!!(e.expirationSeconds>0&&null!=(t=e.userID)&&t.length)},e}(),Pe=/*#__PURE__*/function(e){function n(r){var n;return(n=e.call(this,t({},r))||this)._listener=new Se,n._scheduler=new Ee,n._session=void 0,n.scheduleSessionExpiredEvent=function(e){n._scheduler.removeTasksWithType(T),n._scheduler.scheduleTask(T,function(){return n.dispatchSessionExpiredEvent()},e.expirationSeconds)},n.cancelSessionExpiredEvent=function(){n._scheduler.removeTasksWithType(T)},n.handleStorageEvent=function(e){if("hanko_session"===e.key){var t=n._session.get();t?n._session.isAuthFlowCompleted()?n.dispatchAuthFlowCompletedEvent({userID:t.userID}):n.dispatchSessionCreatedEvent(t):n.dispatchSessionExpiredEvent()}},n._session=new be(t({},r)),n.listenEventDependencies(),n}return r(n,e),n.prototype.listenEventDependencies=function(){this._listener.onSessionCreated(this.scheduleSessionExpiredEvent),this._listener.onSessionExpired(this.cancelSessionExpiredEvent),this._listener.onUserDeleted(this.cancelSessionExpiredEvent),this._listener.onUserLoggedOut(this.cancelSessionExpiredEvent),window.addEventListener("storage",this.handleStorageEvent);var e=this._session.get();e&&this.scheduleSessionExpiredEvent(e)},n}(U),ke=/*#__PURE__*/function(e){function n(r,n){var i;(i=e.call(this)||this).api=void 0,i.config=void 0,i.user=void 0,i.webauthn=void 0,i.password=void 0,i.passcode=void 0,i.email=void 0,i.thirdParty=void 0,i.token=void 0,i.relay=void 0,i.session=void 0;var o={timeout:13e3,cookieName:"hanko",localStorageKey:"hanko"};return void 0!==(null==n?void 0:n.cookieName)&&(o.cookieName=n.cookieName),void 0!==(null==n?void 0:n.timeout)&&(o.timeout=n.timeout),void 0!==(null==n?void 0:n.localStorageKey)&&(o.localStorageKey=n.localStorageKey),i.api=r,i.config=new z(r,o),i.user=new X(r,o),i.webauthn=new ve(r,o),i.password=new V(r,o),i.passcode=new J(r,o),i.email=new we(r,o),i.thirdParty=new me(r,o),i.token=new ye(r,o),i.relay=new Pe(t({},o)),i.session=new be(t({},o)),i}return r(n,e),n}(Se);e.ConfigClient=z,e.ConflictError=d,e.CustomEventWithDetail=L,e.EmailAddressAlreadyExistsError=k,e.EmailClient=we,e.ForbiddenError=E,e.Hanko=ke,e.HankoError=c,e.InvalidPasscodeError=p,e.InvalidPasswordError=f,e.InvalidWebauthnCredentialError=v,e.MaxNumOfEmailAddressesReachedError=P,e.MaxNumOfPasscodeAttemptsReachedError=m,e.NotFoundError=y,e.PasscodeClient=J,e.PasscodeExpiredError=w,e.PasswordClient=V,e.RequestTimeoutError=h,e.TechnicalError=u,e.ThirdPartyClient=me,e.ThirdPartyError=C,e.TokenClient=ye,e.TooManyRequestsError=g,e.UnauthorizedError=S,e.UserClient=X,e.UserVerificationError=b,e.WebauthnClient=ve,e.WebauthnRequestCancelledError=l,e.WebauthnSupport=le,e.authFlowCompletedType=D,e.sessionCreatedType=j,e.sessionExpiredType=T,e.userDeletedType=I,e.userLoggedOutType=R});
|
|
2
2
|
//# sourceMappingURL=sdk.umd.js.map
|