@teamhanko/hanko-frontend-sdk 0.2.0-alpha → 0.2.1-alpha

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.
@@ -64,8 +64,28 @@ declare class Response {
64
64
  declare class HttpClient {
65
65
  timeout: number;
66
66
  api: string;
67
+ authCookieName: string;
67
68
  constructor(api: string, timeout?: number);
68
69
  _fetch(path: string, options: RequestInit, xhr?: XMLHttpRequest): Promise<Response>;
70
+ /**
71
+ * Returns the authentication token that was stored in the cookie.
72
+ *
73
+ * @return {string}
74
+ * @return {string}
75
+ */
76
+ _getAuthCookie(): string;
77
+ /**
78
+ * Stores the authentication token to the cookie.
79
+ *
80
+ * @param {string} token - The authentication token to be stored.
81
+ */
82
+ _setAuthCookie(token: string): void;
83
+ /**
84
+ * Removes the cookie used for authentication.
85
+ *
86
+ * @param {string} token - The authorization token to be stored.
87
+ */
88
+ removeAuthCookie(): void;
69
89
  /**
70
90
  * Performs a GET request.
71
91
  *
@@ -44,5 +44,12 @@ declare class UserClient extends Client {
44
44
  * @see https://docs.hanko.io/api/public#tag/User-Management/operation/listUser
45
45
  */
46
46
  getCurrent(): Promise<User>;
47
+ /**
48
+ * Logs out the current user and expires the existing session cookie. A valid session cookie is required to call the logout endpoint.
49
+ *
50
+ * @return {Promise<void>}
51
+ * @throws {TechnicalError}
52
+ */
53
+ logout(): Promise<void>;
47
54
  }
48
55
  export { UserClient };
package/dist/sdk.cjs CHANGED
@@ -1,2 +1,2 @@
1
- function t(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,r(t,e)}function e(t){return e=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},e(t)}function r(t,e){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},r(t,e)}function n(){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(t){return!1}}function i(t,e,o){return i=n()?Reflect.construct.bind():function(t,e,n){var i=[null];i.push.apply(i,e);var o=new(Function.bind.apply(t,i));return n&&r(o,n.prototype),o},i.apply(null,arguments)}function o(t){var n="function"==typeof Map?new Map:void 0;return o=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,o)}function o(){return i(t,arguments,e(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),r(o,t)},o(t)}function s(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}var a=/*#__PURE__*/function(e){function r(t,n,i){var o;return(o=e.call(this,t)||this).code=void 0,o.cause=void 0,o.code=n,o.cause=i,Object.setPrototypeOf(s(o),r.prototype),o}return t(r,e),r}(/*#__PURE__*/o(Error)),c=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Technical error","somethingWentWrong",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),u=/*#__PURE__*/function(e){function r(t,n){var i;return i=e.call(this,"Conflict error","conflict",n)||this,Object.setPrototypeOf(s(i),r.prototype),i}return t(r,e),r}(a),l=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Request timed out error","requestTimeout",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),h=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Request cancelled error","requestCancelled",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),d=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Invalid password error","invalidPassword",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),f=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Invalid Passcode error","invalidPasscode",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),p=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Invalid WebAuthn credential error","invalidWebauthnCredential",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),w=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Passcode expired error","passcodeExpired",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),v=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Maximum number of Passcode attempts reached error","passcodeAttemptsReached",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),y=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Not found error","notFound",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),m=/*#__PURE__*/function(e){function r(t,n){var i;return(i=e.call(this,"Too many requests error","tooManyRequests",n)||this).retryAfter=void 0,i.retryAfter=t,Object.setPrototypeOf(s(i),r.prototype),i}return t(r,e),r}(a),g=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Unauthorized error","unauthorized",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),P=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"User verification error","userVerification",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),b=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Maximum number of email addresses reached error","maxNumOfEmailAddressesReached",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),S=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"The email address already exists","emailAddressAlreadyExistsError",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),O=/*#__PURE__*/function(e){function r(t,n){var i;return i=e.call(this,"An error occurred during third party sign up/sign in",t,n)||this,Object.setPrototypeOf(s(i),r.prototype),i}return t(r,e),r}(a);function A(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)t[n]=r[n]}return t}var x=function t(e,r){function n(t,n,i){if("undefined"!=typeof document){"number"==typeof(i=A({},r,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).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=t+"="+e.write(n,t)+o}}return Object.create({set:n,get:function(t){if("undefined"!=typeof document&&(!arguments.length||t)){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]=e.read(s,a),t===a)break}catch(t){}}return t?n[t]:n}},remove:function(t,e){n(t,"",A({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,A({},this.attributes,e))},withConverter:function(e){return t(A({},this.converter,e),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(e)}})}({read:function(t){return'"'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"}),j=/*#__PURE__*/function(){function t(t){this._xhr=void 0,this._xhr=t}return t.prototype.get=function(t){return this._xhr.getResponseHeader(t)},t}(),C=/*#__PURE__*/function(){function t(t){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 j(t),this.ok=t.status>=200&&t.status<=299,this.status=t.status,this.statusText=t.statusText,this.url=t.responseURL,this.xhr=t}var e=t.prototype;return e.json=function(){return this._decodedJSON||(this._decodedJSON=JSON.parse(this.xhr.response)),this._decodedJSON},e.parseRetryAfterHeader=function(){var t=parseInt(this.headers.get("Retry-After"),10);return isNaN(t)?0:t},t}(),R=/*#__PURE__*/function(){function t(t,e){void 0===e&&(e=13e3),this.timeout=void 0,this.api=void 0,this.api=t,this.timeout=e}var e=t.prototype;return e._fetch=function(t,e,r){void 0===r&&(r=new XMLHttpRequest);var n=this.api,i=n+t,o=this.timeout,s="hanko",a=x.get(s);return new Promise(function(t,u){r.open(e.method,i,!0),r.setRequestHeader("Accept","application/json"),r.setRequestHeader("Content-Type","application/json"),a&&r.setRequestHeader("Authorization","Bearer "+a),r.timeout=o,r.withCredentials=!0,r.onload=function(){if(r.getAllResponseHeaders().split("\r\n").filter(function(t){return t.toLowerCase().startsWith("x-auth-token")}).length){var e=r.getResponseHeader("X-Auth-Token");if(e){var i=!!n.match("^https://");x.set(s,e,{secure:i})}}t(new C(r))},r.onerror=function(){u(new c)},r.ontimeout=function(){u(new l)},r.send(e.body?e.body.toString():null)})},e.get=function(t){return this._fetch(t,{method:"GET"})},e.post=function(t,e){return this._fetch(t,{method:"POST",body:JSON.stringify(e)})},e.put=function(t,e){return this._fetch(t,{method:"PUT",body:JSON.stringify(e)})},e.patch=function(t,e){return this._fetch(t,{method:"PATCH",body:JSON.stringify(e)})},e.delete=function(t){return this._fetch(t,{method:"DELETE"})},t}(),E=function(t,e){void 0===e&&(e=13e3),this.client=void 0,this.client=new R(t,e)},T=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}return t(r,e),r.prototype.get=function(){try{return Promise.resolve(this.client.get("/.well-known/config")).then(function(t){if(!t.ok)throw new c;return t.json()})}catch(t){return Promise.reject(t)}},r}(E),_=/*#__PURE__*/function(){function t(t){void 0===t&&(t="hanko"),this.key=void 0,this.ls=void 0,this.key=t,this.ls={}}var e=t.prototype;return e.read=function(){var t;try{var e=localStorage.getItem(this.key),r=decodeURIComponent(decodeURI(window.atob(e)));t=JSON.parse(r)}catch(t){return this.ls={},this}return this.ls=t,this},e.write=function(){var t=JSON.stringify(this.ls),e=window.btoa(encodeURI(encodeURIComponent(t)));return localStorage.setItem(this.key,e),this},t.timeToRemainingSeconds=function(t){return void 0===t&&(t=0),t-Math.floor(Date.now()/1e3)},t.remainingSecondsToTime=function(t){return void 0===t&&(t=0),Math.floor(Date.now()/1e3)+t},t}(),k=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}return t(r,e),r.prototype.getUserState=function(t){var e;return(e=this.ls).users||(e.users={}),Object.prototype.hasOwnProperty.call(this.ls.users,t)||(this.ls.users[t]={}),this.ls.users[t]},r}(_),I=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.getState=function(t){var r;return(r=e.prototype.getUserState.call(this,t)).passcode||(r.passcode={})},n.read=function(){return e.prototype.read.call(this),this},n.getActiveID=function(t){return this.getState(t).id},n.setActiveID=function(t,e){return this.getState(t).id=e,this},n.getEmailID=function(t){return this.getState(t).emailID},n.setEmailID=function(t,e){return this.getState(t).emailID=e,this},n.reset=function(t){var e=this.getState(t);return delete e.id,delete e.ttl,delete e.resendAfter,delete e.emailID,this},n.getTTL=function(t){return _.timeToRemainingSeconds(this.getState(t).ttl)},n.setTTL=function(t,e){return this.getState(t).ttl=_.remainingSecondsToTime(e),this},n.getResendAfter=function(t){return _.timeToRemainingSeconds(this.getState(t).resendAfter)},n.setResendAfter=function(t,e){return this.getState(t).resendAfter=_.remainingSecondsToTime(e),this},r}(k),U=/*#__PURE__*/function(e){function r(t,r){var n;return void 0===r&&(r=13e3),(n=e.call(this,t,r)||this).state=void 0,n.state=new I,n}t(r,e);var n=r.prototype;return n.initialize=function(t,e,r){try{var n=this;n.state.read();var i=n.state.getTTL(t),o=n.state.getActiveID(t),s=n.state.getEmailID(t),a=n.state.getResendAfter(t);if(a>0)throw new m(a);if(!r&&i>0&&e===s)return Promise.resolve({id:o,ttl:i});var u={user_id:t};return e&&(u.email_id=e),Promise.resolve(n.client.post("/passcode/login/initialize",u)).then(function(r){if(429===r.status)throw a=r.parseRetryAfterHeader(),n.state.setResendAfter(t,a).write(),new m(a);if(401===r.status)throw new g;if(!r.ok)throw new c;var i=r.json();return n.state.setActiveID(t,i.id).setTTL(t,i.ttl),e&&n.state.setEmailID(t,e),n.state.write(),i})}catch(t){return Promise.reject(t)}},n.finalize=function(t,e){try{var r=this,n=r.state.read().getActiveID(t);if(r.state.getTTL(t)<=0)throw new w;return Promise.resolve(r.client.post("/passcode/login/finalize",{id:n,code:e})).then(function(e){if(401===e.status)throw new f;if(410===e.status)throw r.state.reset(t).write(),new v;if(!e.ok)throw new c;r.state.reset(t).write()})}catch(t){return Promise.reject(t)}},n.getTTL=function(t){return this.state.read().getTTL(t)},n.getResendAfter=function(t){return this.state.read().getResendAfter(t)},r}(E),D=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.getState=function(t){var r;return(r=e.prototype.getUserState.call(this,t)).password||(r.password={})},n.read=function(){return e.prototype.read.call(this),this},n.getRetryAfter=function(t){return _.timeToRemainingSeconds(this.getState(t).retryAfter)},n.setRetryAfter=function(t,e){return this.getState(t).retryAfter=_.remainingSecondsToTime(e),this},r}(k),N=/*#__PURE__*/function(e){function r(t,r){var n;return void 0===r&&(r=13e3),(n=e.call(this,t,r)||this).passwordState=void 0,n.passcodeState=void 0,n.passwordState=new D,n.passcodeState=new I,n}t(r,e);var n=r.prototype;return n.login=function(t,e){try{var r=this;return Promise.resolve(r.client.post("/password/login",{user_id:t,password:e})).then(function(e){if(401===e.status)throw new d;if(429===e.status){var n=e.parseRetryAfterHeader();throw r.passwordState.read().setRetryAfter(t,n).write(),new m(n)}if(!e.ok)throw new c;r.passcodeState.read().reset(t).write()})}catch(t){return Promise.reject(t)}},n.update=function(t,e){try{return Promise.resolve(this.client.put("/password",{user_id:t,password:e})).then(function(t){if(401===t.status)throw new g;if(!t.ok)throw new c})}catch(t){return Promise.reject(t)}},n.getRetryAfter=function(t){return this.passwordState.read().getRetryAfter(t)},r}(E),q=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.getInfo=function(t){try{return Promise.resolve(this.client.post("/user",{email:t})).then(function(t){if(404===t.status)throw new y;if(!t.ok)throw new c;return t.json()})}catch(t){return Promise.reject(t)}},n.create=function(t){try{return Promise.resolve(this.client.post("/users",{email:t})).then(function(t){if(409===t.status)throw new u;if(!t.ok)throw new c;return t.json()})}catch(t){return Promise.reject(t)}},n.getCurrent=function(){try{var t=this;return Promise.resolve(t.client.get("/me")).then(function(e){if(400===e.status||401===e.status||404===e.status)throw new g;if(!e.ok)throw new c;var r=e.json();return Promise.resolve(t.client.get("/users/"+r.id)).then(function(t){if(400===t.status||401===t.status||404===t.status)throw new g;if(!t.ok)throw new c;return t.json()})})}catch(t){return Promise.reject(t)}},r}(E);function M(t){const e="==".slice(0,(4-t.length%4)%4),r=t.replace(/-/g,"+").replace(/_/g,"/")+e,n=atob(r),i=new ArrayBuffer(n.length),o=new Uint8Array(i);for(let t=0;t<n.length;t++)o[t]=n.charCodeAt(t);return i}function K(t){const e=new Uint8Array(t);let r="";for(const t of e)r+=String.fromCharCode(t);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function W(t,e,r){if("copy"===e)return r;if("convert"===e)return t(r);if(e instanceof Array)return r.map(r=>W(t,e[0],r));if(e instanceof Object){const n={};for(const[i,o]of Object.entries(e)){if(o.derive){const t=o.derive(r);void 0!==t&&(r[i]=t)}if(i in r)n[i]=null!=r[i]?W(t,o.schema,r[i]):null;else if(o.required)throw new Error(`Missing key: ${i}`)}return n}}function z(t,e){return{required:!0,schema:t,derive:e}}function H(t){return{required:!0,schema:t}}function L(t){return{required:!1,schema:t}}var J={type:H("copy"),id:H("convert"),transports:L("copy")},B={appid:L("copy"),appidExclude:L("copy"),credProps:L("copy")},F={appid:L("copy"),appidExclude:L("copy"),credProps:L("copy")},V={publicKey:H({rp:H("copy"),user:H({id:H("convert"),name:H("copy"),displayName:H("copy")}),challenge:H("convert"),pubKeyCredParams:H("copy"),timeout:L("copy"),excludeCredentials:L([J]),authenticatorSelection:L("copy"),attestation:L("copy"),extensions:L(B)}),signal:L("copy")},X={type:H("copy"),id:H("copy"),rawId:H("convert"),authenticatorAttachment:L("copy"),response:H({clientDataJSON:H("convert"),attestationObject:H("convert"),transports:z("copy",t=>{var e;return(null==(e=t.getTransports)?void 0:e.call(t))||[]})}),clientExtensionResults:z(F,t=>t.getClientExtensionResults())},G={mediation:L("copy"),publicKey:H({challenge:H("convert"),timeout:L("copy"),rpId:L("copy"),allowCredentials:L([J]),userVerification:L("copy"),extensions:L(B)}),signal:L("copy")},$={type:H("copy"),id:H("copy"),rawId:H("convert"),authenticatorAttachment:L("copy"),response:H({clientDataJSON:H("convert"),authenticatorData:H("convert"),signature:H("convert"),userHandle:H("convert")}),clientExtensionResults:z(F,t=>t.getClientExtensionResults())};async function Q(t){const e=await navigator.credentials.create(function(t){return W(M,V,t)}(t));return function(t){return W(K,X,t)}(e)}async function Y(t){const e=await navigator.credentials.get(function(t){return W(M,G,t)}(t));return function(t){return W(K,$,t)}(e)}var Z=/*#__PURE__*/function(){function t(){}return t.supported=function(){return!!(navigator.credentials&&navigator.credentials.create&&navigator.credentials.get&&window.PublicKeyCredential)},t.isPlatformAuthenticatorAvailable=function(){try{return this.supported()&&window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?Promise.resolve(window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()):Promise.resolve(!1)}catch(t){return Promise.reject(t)}},t.isSecurityKeySupported=function(){try{return void 0!==window.PublicKeyCredential&&window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported?Promise.resolve(window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported()):Promise.resolve(this.supported())}catch(t){return Promise.reject(t)}},t.isConditionalMediationAvailable=function(){try{return window.PublicKeyCredential&&window.PublicKeyCredential.isConditionalMediationAvailable?Promise.resolve(window.PublicKeyCredential.isConditionalMediationAvailable()):Promise.resolve(!1)}catch(t){return Promise.reject(t)}},t}(),tt=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.getState=function(t){var r;return(r=e.prototype.getUserState.call(this,t)).webauthn||(r.webauthn={})},n.read=function(){return e.prototype.read.call(this),this},n.getCredentials=function(t){var e;return(e=this.getState(t)).credentials||(e.credentials=[])},n.addCredential=function(t,e){return this.getCredentials(t).push(e),this},n.matchCredentials=function(t,e){return this.getCredentials(t).filter(function(t){return e.find(function(e){return e.id===t})}).map(function(t){return{id:t}})},r}(k);function et(t,e){try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}var rt=/*#__PURE__*/function(e){function r(t,r){var n;return void 0===r&&(r=13e3),(n=e.call(this,t,r)||this).webauthnState=void 0,n.passcodeState=void 0,n.controller=void 0,n._getCredential=Y,n._createCredential=Q,n.webauthnState=new tt,n.passcodeState=new I,n}t(r,e);var n=r.prototype;return n.login=function(t,e){try{var r=this;return Promise.resolve(r.client.post("/webauthn/login/initialize",{user_id:t})).then(function(n){function i(e){return Promise.resolve(r.client.post("/webauthn/login/finalize",o)).then(function(e){if(400===e.status||401===e.status)throw new p;if(!e.ok)throw new c;var n=e.json();r.webauthnState.read().addCredential(n.user_id,n.credential_id).write(),r.passcodeState.read().reset(t).write()})}if(!n.ok)throw new c;var o,s=n.json();s.signal=r._createAbortSignal(),e&&(s.mediation="conditional");var a=et(function(){return Promise.resolve(r._getCredential(s)).then(function(t){o=t})},function(t){throw new h(t)});return a&&a.then?a.then(i):i()})}catch(t){return Promise.reject(t)}},n.register=function(){try{var t=this;return Promise.resolve(t.client.post("/webauthn/registration/initialize")).then(function(e){function r(e){return n.transports=n.response.transports,Promise.resolve(t.client.post("/webauthn/registration/finalize",n)).then(function(e){if(e.status>=400&&e.status<=499){if(422===e.status)throw new P;throw new g}if(!e.ok)throw new c;var r=e.json();t.webauthnState.read().addCredential(r.user_id,r.credential_id).write()})}if(e.status>=400&&e.status<=499)throw new g;if(!e.ok)throw new c;var n,i=e.json();i.signal=t._createAbortSignal();var o=et(function(){return Promise.resolve(t._createCredential(i)).then(function(t){n=t})},function(t){throw new h(t)});return o&&o.then?o.then(r):r()})}catch(t){return Promise.reject(t)}},n.listCredentials=function(){try{return Promise.resolve(this.client.get("/webauthn/credentials")).then(function(t){if(401===t.status)throw new g;if(!t.ok)throw new c;return t.json()})}catch(t){return Promise.reject(t)}},n.updateCredential=function(t,e){try{return Promise.resolve(this.client.patch("/webauthn/credentials/"+t,{name:e})).then(function(t){if(401===t.status)throw new g;if(!t.ok)throw new c})}catch(t){return Promise.reject(t)}},n.deleteCredential=function(t){try{return Promise.resolve(this.client.delete("/webauthn/credentials/"+t)).then(function(t){if(401===t.status)throw new g;if(!t.ok)throw new c})}catch(t){return Promise.reject(t)}},n.shouldRegister=function(t){try{var e=Z.supported();if(!t.webauthn_credentials||!t.webauthn_credentials.length)return Promise.resolve(e);var r=this.webauthnState.read().matchCredentials(t.id,t.webauthn_credentials);return Promise.resolve(e&&!r.length)}catch(t){return Promise.reject(t)}},n._createAbortSignal=function(){return this.controller&&this.controller.abort(),this.controller=new AbortController,this.controller.signal},r}(E),nt=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.list=function(){try{return Promise.resolve(this.client.get("/emails")).then(function(t){if(401===t.status)throw new g;if(!t.ok)throw new c;return t.json()})}catch(t){return Promise.reject(t)}},n.create=function(t){try{return Promise.resolve(this.client.post("/emails",{address:t})).then(function(t){if(t.ok)return t.json();if(400===t.status)throw new S;if(401===t.status)throw new g;if(409===t.status)throw new b;throw new c})}catch(t){return Promise.reject(t)}},n.setPrimaryEmail=function(t){try{return Promise.resolve(this.client.post("/emails/"+t+"/set_primary")).then(function(t){if(401===t.status)throw new g;if(!t.ok)throw new c})}catch(t){return Promise.reject(t)}},n.delete=function(t){try{return Promise.resolve(this.client.delete("/emails/"+t)).then(function(t){if(401===t.status)throw new g;if(!t.ok)throw new c})}catch(t){return Promise.reject(t)}},r}(E),it=/*#__PURE__*/function(e){function r(t,r){return void 0===r&&(r=13e3),e.call(this,t,r)||this}t(r,e);var n=r.prototype;return n.auth=function(t,e){try{var r=new URL("/thirdparty/auth",this.client.api);if(!t)throw new O("somethingWentWrong",new Error("provider missing from request"));if(!e)throw new O("somethingWentWrong",new Error("redirectTo missing from request"));return r.searchParams.append("provider",t),r.searchParams.append("redirect_to",e),window.location.assign(r.href),Promise.resolve()}catch(t){return Promise.reject(t)}},n.getError=function(){var t=new URLSearchParams(window.location.search),e=t.get("error"),r=t.get("error_description");if(e){var n="";switch(e){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 O(n,new Error(r))}},r}(E);exports.ConfigClient=T,exports.ConflictError=u,exports.EmailAddressAlreadyExistsError=S,exports.EmailClient=nt,exports.Hanko=function(t,e){void 0===e&&(e=13e3),this.api=void 0,this.config=void 0,this.user=void 0,this.webauthn=void 0,this.password=void 0,this.passcode=void 0,this.email=void 0,this.thirdParty=void 0,this.api=t,this.config=new T(t,e),this.user=new q(t,e),this.webauthn=new rt(t,e),this.password=new N(t,e),this.passcode=new U(t,e),this.email=new nt(t,e),this.thirdParty=new it(t,e)},exports.HankoError=a,exports.InvalidPasscodeError=f,exports.InvalidPasswordError=d,exports.InvalidWebauthnCredentialError=p,exports.MaxNumOfEmailAddressesReachedError=b,exports.MaxNumOfPasscodeAttemptsReachedError=v,exports.NotFoundError=y,exports.PasscodeClient=U,exports.PasscodeExpiredError=w,exports.PasswordClient=N,exports.RequestTimeoutError=l,exports.TechnicalError=c,exports.ThirdPartyClient=it,exports.ThirdPartyError=O,exports.TooManyRequestsError=m,exports.UnauthorizedError=g,exports.UserClient=q,exports.UserVerificationError=P,exports.WebauthnClient=rt,exports.WebauthnRequestCancelledError=h,exports.WebauthnSupport=Z;
1
+ function t(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,r(t,e)}function e(t){return e=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},e(t)}function r(t,e){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},r(t,e)}function n(t,e,i){return n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct.bind():function(t,e,n){var i=[null];i.push.apply(i,e);var o=new(Function.bind.apply(t,i));return n&&r(o,n.prototype),o},n.apply(null,arguments)}function i(t){var o="function"==typeof Map?new Map:void 0;return i=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==o){if(o.has(t))return o.get(t);o.set(t,i)}function i(){return n(t,arguments,e(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),r(i,t)},i(t)}function o(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}var s=/*#__PURE__*/function(e){function r(t,n,i){var s;return(s=e.call(this,t)||this).code=void 0,s.cause=void 0,s.code=n,s.cause=i,Object.setPrototypeOf(o(s),r.prototype),s}return t(r,e),r}(/*#__PURE__*/i(Error)),a=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Technical error","somethingWentWrong",t)||this,Object.setPrototypeOf(o(n),r.prototype),n}return t(r,e),r}(s),u=/*#__PURE__*/function(e){function r(t,n){var i;return i=e.call(this,"Conflict error","conflict",n)||this,Object.setPrototypeOf(o(i),r.prototype),i}return t(r,e),r}(s),c=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Request timed out error","requestTimeout",t)||this,Object.setPrototypeOf(o(n),r.prototype),n}return t(r,e),r}(s),h=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Request cancelled error","requestCancelled",t)||this,Object.setPrototypeOf(o(n),r.prototype),n}return t(r,e),r}(s),l=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Invalid password error","invalidPassword",t)||this,Object.setPrototypeOf(o(n),r.prototype),n}return t(r,e),r}(s),d=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Invalid Passcode error","invalidPasscode",t)||this,Object.setPrototypeOf(o(n),r.prototype),n}return t(r,e),r}(s),f=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Invalid WebAuthn credential error","invalidWebauthnCredential",t)||this,Object.setPrototypeOf(o(n),r.prototype),n}return t(r,e),r}(s),p=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Passcode expired error","passcodeExpired",t)||this,Object.setPrototypeOf(o(n),r.prototype),n}return t(r,e),r}(s),w=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Maximum number of Passcode attempts reached error","passcodeAttemptsReached",t)||this,Object.setPrototypeOf(o(n),r.prototype),n}return t(r,e),r}(s),v=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Not found error","notFound",t)||this,Object.setPrototypeOf(o(n),r.prototype),n}return t(r,e),r}(s),m=/*#__PURE__*/function(e){function r(t,n){var i;return(i=e.call(this,"Too many requests error","tooManyRequests",n)||this).retryAfter=void 0,i.retryAfter=t,Object.setPrototypeOf(o(i),r.prototype),i}return t(r,e),r}(s),y=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Unauthorized error","unauthorized",t)||this,Object.setPrototypeOf(o(n),r.prototype),n}return t(r,e),r}(s),g=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"User verification error","userVerification",t)||this,Object.setPrototypeOf(o(n),r.prototype),n}return t(r,e),r}(s),P=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Maximum number of email addresses reached error","maxNumOfEmailAddressesReached",t)||this,Object.setPrototypeOf(o(n),r.prototype),n}return t(r,e),r}(s),b=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"The email address already exists","emailAddressAlreadyExistsError",t)||this,Object.setPrototypeOf(o(n),r.prototype),n}return t(r,e),r}(s),C=/*#__PURE__*/function(e){function r(t,n){var i;return i=e.call(this,"An error occurred during third party sign up/sign in",t,n)||this,Object.setPrototypeOf(o(i),r.prototype),i}return t(r,e),r}(s);function A(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)t[n]=r[n]}return t}var S=function t(e,r){function n(t,n,i){if("undefined"!=typeof document){"number"==typeof(i=A({},r,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).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=t+"="+e.write(n,t)+o}}return Object.create({set:n,get:function(t){if("undefined"!=typeof document&&(!arguments.length||t)){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]=e.read(s,a),t===a)break}catch(t){}}return t?n[t]:n}},remove:function(t,e){n(t,"",A({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,A({},this.attributes,e))},withConverter:function(e){return t(A({},this.converter,e),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(e)}})}({read:function(t){return'"'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"}),O=/*#__PURE__*/function(){function t(t){this._xhr=void 0,this._xhr=t}return t.prototype.get=function(t){return this._xhr.getResponseHeader(t)},t}(),j=/*#__PURE__*/function(){function t(t){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 O(t),this.ok=t.status>=200&&t.status<=299,this.status=t.status,this.statusText=t.statusText,this.url=t.responseURL,this.xhr=t}var e=t.prototype;return e.json=function(){return this._decodedJSON||(this._decodedJSON=JSON.parse(this.xhr.response)),this._decodedJSON},e.parseRetryAfterHeader=function(){var t=parseInt(this.headers.get("Retry-After"),10);return isNaN(t)?0:t},t}(),x=/*#__PURE__*/function(){function t(t,e){void 0===e&&(e=13e3),this.timeout=void 0,this.api=void 0,this.authCookieName="hanko",this.api=t,this.timeout=e}var e=t.prototype;return e._fetch=function(t,e,r){void 0===r&&(r=new XMLHttpRequest);var n=this,i=this.api+t,o=this.timeout,s=this._getAuthCookie();return new Promise(function(t,u){r.open(e.method,i,!0),r.setRequestHeader("Accept","application/json"),r.setRequestHeader("Content-Type","application/json"),s&&r.setRequestHeader("Authorization","Bearer "+s),r.timeout=o,r.withCredentials=!0,r.onload=function(){if(r.getAllResponseHeaders().split("\r\n").filter(function(t){return t.toLowerCase().startsWith("x-auth-token")}).length){var e=r.getResponseHeader("X-Auth-Token");e&&n._setAuthCookie(e)}t(new j(r))},r.onerror=function(){u(new a)},r.ontimeout=function(){u(new c)},r.send(e.body?e.body.toString():null)})},e._getAuthCookie=function(){return S.get(this.authCookieName)},e._setAuthCookie=function(t){var e=!!this.api.match("^https://");S.set(this.authCookieName,t,{secure:e})},e.removeAuthCookie=function(){S.remove(this.authCookieName)},e.get=function(t){return this._fetch(t,{method:"GET"})},e.post=function(t,e){return this._fetch(t,{method:"POST",body:JSON.stringify(e)})},e.put=function(t,e){return this._fetch(t,{method:"PUT",body:JSON.stringify(e)})},e.patch=function(t,e){return this._fetch(t,{method:"PATCH",body:JSON.stringify(e)})},e.delete=function(t){return this._fetch(t,{method:"DELETE"})},t}(),R=function(t,e){void 0===e&&(e=13e3),this.client=void 0,this.client=new x(t,e)},E=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}return t(r,e),r.prototype.get=function(){try{return Promise.resolve(this.client.get("/.well-known/config")).then(function(t){if(!t.ok)throw new a;return t.json()})}catch(t){return Promise.reject(t)}},r}(R),k=/*#__PURE__*/function(){function t(t){void 0===t&&(t="hanko"),this.key=void 0,this.ls=void 0,this.key=t,this.ls={}}var e=t.prototype;return e.read=function(){var t;try{var e=localStorage.getItem(this.key),r=decodeURIComponent(decodeURI(window.atob(e)));t=JSON.parse(r)}catch(t){return this.ls={},this}return this.ls=t,this},e.write=function(){var t=JSON.stringify(this.ls),e=window.btoa(encodeURI(encodeURIComponent(t)));return localStorage.setItem(this.key,e),this},t.timeToRemainingSeconds=function(t){return void 0===t&&(t=0),t-Math.floor(Date.now()/1e3)},t.remainingSecondsToTime=function(t){return void 0===t&&(t=0),Math.floor(Date.now()/1e3)+t},t}(),_=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}return t(r,e),r.prototype.getUserState=function(t){var e;return(e=this.ls).users||(e.users={}),Object.prototype.hasOwnProperty.call(this.ls.users,t)||(this.ls.users[t]={}),this.ls.users[t]},r}(k),T=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.getState=function(t){var r;return(r=e.prototype.getUserState.call(this,t)).passcode||(r.passcode={})},n.read=function(){return e.prototype.read.call(this),this},n.getActiveID=function(t){return this.getState(t).id},n.setActiveID=function(t,e){return this.getState(t).id=e,this},n.getEmailID=function(t){return this.getState(t).emailID},n.setEmailID=function(t,e){return this.getState(t).emailID=e,this},n.reset=function(t){var e=this.getState(t);return delete e.id,delete e.ttl,delete e.resendAfter,delete e.emailID,this},n.getTTL=function(t){return k.timeToRemainingSeconds(this.getState(t).ttl)},n.setTTL=function(t,e){return this.getState(t).ttl=k.remainingSecondsToTime(e),this},n.getResendAfter=function(t){return k.timeToRemainingSeconds(this.getState(t).resendAfter)},n.setResendAfter=function(t,e){return this.getState(t).resendAfter=k.remainingSecondsToTime(e),this},r}(_),I=/*#__PURE__*/function(e){function r(t,r){var n;return void 0===r&&(r=13e3),(n=e.call(this,t,r)||this).state=void 0,n.state=new T,n}t(r,e);var n=r.prototype;return n.initialize=function(t,e,r){try{var n=this;n.state.read();var i=n.state.getTTL(t),o=n.state.getActiveID(t),s=n.state.getEmailID(t),u=n.state.getResendAfter(t);if(u>0)throw new m(u);if(!r&&i>0&&e===s)return Promise.resolve({id:o,ttl:i});var c={user_id:t};return e&&(c.email_id=e),Promise.resolve(n.client.post("/passcode/login/initialize",c)).then(function(r){if(429===r.status)throw u=r.parseRetryAfterHeader(),n.state.setResendAfter(t,u).write(),new m(u);if(401===r.status)throw new y;if(!r.ok)throw new a;var i=r.json();return n.state.setActiveID(t,i.id).setTTL(t,i.ttl),e&&n.state.setEmailID(t,e),n.state.write(),i})}catch(t){return Promise.reject(t)}},n.finalize=function(t,e){try{var r=this,n=r.state.read().getActiveID(t);if(r.state.getTTL(t)<=0)throw new p;return Promise.resolve(r.client.post("/passcode/login/finalize",{id:n,code:e})).then(function(e){if(401===e.status)throw new d;if(410===e.status)throw r.state.reset(t).write(),new w;if(!e.ok)throw new a;r.state.reset(t).write()})}catch(t){return Promise.reject(t)}},n.getTTL=function(t){return this.state.read().getTTL(t)},n.getResendAfter=function(t){return this.state.read().getResendAfter(t)},r}(R),U=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.getState=function(t){var r;return(r=e.prototype.getUserState.call(this,t)).password||(r.password={})},n.read=function(){return e.prototype.read.call(this),this},n.getRetryAfter=function(t){return k.timeToRemainingSeconds(this.getState(t).retryAfter)},n.setRetryAfter=function(t,e){return this.getState(t).retryAfter=k.remainingSecondsToTime(e),this},r}(_),N=/*#__PURE__*/function(e){function r(t,r){var n;return void 0===r&&(r=13e3),(n=e.call(this,t,r)||this).passwordState=void 0,n.passcodeState=void 0,n.passwordState=new U,n.passcodeState=new T,n}t(r,e);var n=r.prototype;return n.login=function(t,e){try{var r=this;return Promise.resolve(r.client.post("/password/login",{user_id:t,password:e})).then(function(e){if(401===e.status)throw new l;if(429===e.status){var n=e.parseRetryAfterHeader();throw r.passwordState.read().setRetryAfter(t,n).write(),new m(n)}if(!e.ok)throw new a;r.passcodeState.read().reset(t).write()})}catch(t){return Promise.reject(t)}},n.update=function(t,e){try{return Promise.resolve(this.client.put("/password",{user_id:t,password:e})).then(function(t){if(401===t.status)throw new y;if(!t.ok)throw new a})}catch(t){return Promise.reject(t)}},n.getRetryAfter=function(t){return this.passwordState.read().getRetryAfter(t)},r}(R),D=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.getInfo=function(t){try{return Promise.resolve(this.client.post("/user",{email:t})).then(function(t){if(404===t.status)throw new v;if(!t.ok)throw new a;return t.json()})}catch(t){return Promise.reject(t)}},n.create=function(t){try{return Promise.resolve(this.client.post("/users",{email:t})).then(function(t){if(409===t.status)throw new u;if(!t.ok)throw new a;return t.json()})}catch(t){return Promise.reject(t)}},n.getCurrent=function(){try{var t=this;return Promise.resolve(t.client.get("/me")).then(function(e){if(400===e.status||401===e.status||404===e.status)throw new y;if(!e.ok)throw new a;var r=e.json();return Promise.resolve(t.client.get("/users/"+r.id)).then(function(t){if(400===t.status||401===t.status||404===t.status)throw new y;if(!t.ok)throw new a;return t.json()})})}catch(t){return Promise.reject(t)}},n.logout=function(){try{var t=this;return Promise.resolve(t.client.post("/logout")).then(function(e){if(t.client.removeAuthCookie(),401===e.status);else if(!e.ok)throw new a})}catch(t){return Promise.reject(t)}},r}(R);function q(t){const e="==".slice(0,(4-t.length%4)%4),r=t.replace(/-/g,"+").replace(/_/g,"/")+e,n=atob(r),i=new ArrayBuffer(n.length),o=new Uint8Array(i);for(let t=0;t<n.length;t++)o[t]=n.charCodeAt(t);return i}function M(t){const e=new Uint8Array(t);let r="";for(const t of e)r+=String.fromCharCode(t);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var K="copy",W="convert";function z(t,e,r){if(e===K)return r;if(e===W)return t(r);if(e instanceof Array)return r.map(r=>z(t,e[0],r));if(e instanceof Object){const n={};for(const[i,o]of Object.entries(e)){if(o.derive){const t=o.derive(r);void 0!==t&&(r[i]=t)}if(i in r)n[i]=null!=r[i]?z(t,o.schema,r[i]):null;else if(o.required)throw new Error(`Missing key: ${i}`)}return n}}function H(t,e){return{required:!0,schema:t,derive:e}}function L(t){return{required:!0,schema:t}}function J(t){return{required:!1,schema:t}}var B={type:L(K),id:L(W),transports:J(K)},F={appid:J(K),appidExclude:J(K),credProps:J(K)},V={appid:J(K),appidExclude:J(K),credProps:J(K)},X={publicKey:L({rp:L(K),user:L({id:L(W),name:L(K),displayName:L(K)}),challenge:L(W),pubKeyCredParams:L(K),timeout:J(K),excludeCredentials:J([B]),authenticatorSelection:J(K),attestation:J(K),extensions:J(F)}),signal:J(K)},G={type:L(K),id:L(K),rawId:L(W),authenticatorAttachment:J(K),response:L({clientDataJSON:L(W),attestationObject:L(W),transports:H(K,t=>{var e;return(null==(e=t.getTransports)?void 0:e.call(t))||[]})}),clientExtensionResults:H(V,t=>t.getClientExtensionResults())},$={mediation:J(K),publicKey:L({challenge:L(W),timeout:J(K),rpId:J(K),allowCredentials:J([B]),userVerification:J(K),extensions:J(F)}),signal:J(K)},Q={type:L(K),id:L(K),rawId:L(W),authenticatorAttachment:J(K),response:L({clientDataJSON:L(W),authenticatorData:L(W),signature:L(W),userHandle:L(W)}),clientExtensionResults:H(V,t=>t.getClientExtensionResults())};async function Y(t){const e=await navigator.credentials.create(function(t){return z(q,X,t)}(t));return function(t){return z(M,G,t)}(e)}async function Z(t){const e=await navigator.credentials.get(function(t){return z(q,$,t)}(t));return function(t){return z(M,Q,t)}(e)}var tt=/*#__PURE__*/function(){function t(){}return t.supported=function(){return!!(navigator.credentials&&navigator.credentials.create&&navigator.credentials.get&&window.PublicKeyCredential)},t.isPlatformAuthenticatorAvailable=function(){try{return this.supported()&&window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?Promise.resolve(window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()):Promise.resolve(!1)}catch(t){return Promise.reject(t)}},t.isSecurityKeySupported=function(){try{return void 0!==window.PublicKeyCredential&&window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported?Promise.resolve(window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported()):Promise.resolve(this.supported())}catch(t){return Promise.reject(t)}},t.isConditionalMediationAvailable=function(){try{return window.PublicKeyCredential&&window.PublicKeyCredential.isConditionalMediationAvailable?Promise.resolve(window.PublicKeyCredential.isConditionalMediationAvailable()):Promise.resolve(!1)}catch(t){return Promise.reject(t)}},t}(),et=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.getState=function(t){var r;return(r=e.prototype.getUserState.call(this,t)).webauthn||(r.webauthn={})},n.read=function(){return e.prototype.read.call(this),this},n.getCredentials=function(t){var e;return(e=this.getState(t)).credentials||(e.credentials=[])},n.addCredential=function(t,e){return this.getCredentials(t).push(e),this},n.matchCredentials=function(t,e){return this.getCredentials(t).filter(function(t){return e.find(function(e){return e.id===t})}).map(function(t){return{id:t}})},r}(_);function rt(t,e){try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}var nt=/*#__PURE__*/function(e){function r(t,r){var n;return void 0===r&&(r=13e3),(n=e.call(this,t,r)||this).webauthnState=void 0,n.passcodeState=void 0,n.controller=void 0,n._getCredential=Z,n._createCredential=Y,n.webauthnState=new et,n.passcodeState=new T,n}t(r,e);var n=r.prototype;return n.login=function(t,e){try{var r=this;return Promise.resolve(r.client.post("/webauthn/login/initialize",{user_id:t})).then(function(n){var i;function o(e){return i?e:Promise.resolve(r.client.post("/webauthn/login/finalize",s)).then(function(e){if(400===e.status||401===e.status)throw new f;if(!e.ok)throw new a;var n=e.json();r.webauthnState.read().addCredential(n.user_id,n.credential_id).write(),r.passcodeState.read().reset(t).write()})}if(!n.ok)throw new a;var s,u=n.json();u.signal=r._createAbortSignal(),e&&(u.mediation="conditional");var c=rt(function(){return Promise.resolve(r._getCredential(u)).then(function(t){s=t})},function(t){throw new h(t)});return c&&c.then?c.then(o):o(c)})}catch(t){return Promise.reject(t)}},n.register=function(){try{var t=this;return Promise.resolve(t.client.post("/webauthn/registration/initialize")).then(function(e){function r(e){return n.transports=n.response.transports,Promise.resolve(t.client.post("/webauthn/registration/finalize",n)).then(function(e){if(e.status>=400&&e.status<=499){if(422===e.status)throw new g;throw new y}if(!e.ok)throw new a;var r=e.json();t.webauthnState.read().addCredential(r.user_id,r.credential_id).write()})}if(e.status>=400&&e.status<=499)throw new y;if(!e.ok)throw new a;var n,i=e.json();i.signal=t._createAbortSignal();var o=rt(function(){return Promise.resolve(t._createCredential(i)).then(function(t){n=t})},function(t){throw new h(t)});return o&&o.then?o.then(r):r()})}catch(t){return Promise.reject(t)}},n.listCredentials=function(){try{return Promise.resolve(this.client.get("/webauthn/credentials")).then(function(t){if(401===t.status)throw new y;if(!t.ok)throw new a;return t.json()})}catch(t){return Promise.reject(t)}},n.updateCredential=function(t,e){try{return Promise.resolve(this.client.patch("/webauthn/credentials/"+t,{name:e})).then(function(t){if(401===t.status)throw new y;if(!t.ok)throw new a})}catch(t){return Promise.reject(t)}},n.deleteCredential=function(t){try{return Promise.resolve(this.client.delete("/webauthn/credentials/"+t)).then(function(t){if(401===t.status)throw new y;if(!t.ok)throw new a})}catch(t){return Promise.reject(t)}},n.shouldRegister=function(t){try{var e=tt.supported();if(!t.webauthn_credentials||!t.webauthn_credentials.length)return Promise.resolve(e);var r=this.webauthnState.read().matchCredentials(t.id,t.webauthn_credentials);return Promise.resolve(e&&!r.length)}catch(t){return Promise.reject(t)}},n._createAbortSignal=function(){return this.controller&&this.controller.abort(),this.controller=new AbortController,this.controller.signal},r}(R),it=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.list=function(){try{return Promise.resolve(this.client.get("/emails")).then(function(t){if(401===t.status)throw new y;if(!t.ok)throw new a;return t.json()})}catch(t){return Promise.reject(t)}},n.create=function(t){try{return Promise.resolve(this.client.post("/emails",{address:t})).then(function(t){if(t.ok)return t.json();if(400===t.status)throw new b;if(401===t.status)throw new y;if(409===t.status)throw new P;throw new a})}catch(t){return Promise.reject(t)}},n.setPrimaryEmail=function(t){try{return Promise.resolve(this.client.post("/emails/"+t+"/set_primary")).then(function(t){if(401===t.status)throw new y;if(!t.ok)throw new a})}catch(t){return Promise.reject(t)}},n.delete=function(t){try{return Promise.resolve(this.client.delete("/emails/"+t)).then(function(t){if(401===t.status)throw new y;if(!t.ok)throw new a})}catch(t){return Promise.reject(t)}},r}(R),ot=/*#__PURE__*/function(e){function r(t,r){return void 0===r&&(r=13e3),e.call(this,t,r)||this}t(r,e);var n=r.prototype;return n.auth=function(t,e){try{var r=new URL("/thirdparty/auth",this.client.api);if(!t)throw new C("somethingWentWrong",new Error("provider missing from request"));if(!e)throw new C("somethingWentWrong",new Error("redirectTo missing from request"));return r.searchParams.append("provider",t),r.searchParams.append("redirect_to",e),window.location.assign(r.href),Promise.resolve()}catch(t){return Promise.reject(t)}},n.getError=function(){var t=new URLSearchParams(window.location.search),e=t.get("error"),r=t.get("error_description");if(e){var n="";switch(e){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))}},r}(R);exports.ConfigClient=E,exports.ConflictError=u,exports.EmailAddressAlreadyExistsError=b,exports.EmailClient=it,exports.Hanko=function(t,e){void 0===e&&(e=13e3),this.api=void 0,this.config=void 0,this.user=void 0,this.webauthn=void 0,this.password=void 0,this.passcode=void 0,this.email=void 0,this.thirdParty=void 0,this.api=t,this.config=new E(t,e),this.user=new D(t,e),this.webauthn=new nt(t,e),this.password=new N(t,e),this.passcode=new I(t,e),this.email=new it(t,e),this.thirdParty=new ot(t,e)},exports.HankoError=s,exports.InvalidPasscodeError=d,exports.InvalidPasswordError=l,exports.InvalidWebauthnCredentialError=f,exports.MaxNumOfEmailAddressesReachedError=P,exports.MaxNumOfPasscodeAttemptsReachedError=w,exports.NotFoundError=v,exports.PasscodeClient=I,exports.PasscodeExpiredError=p,exports.PasswordClient=N,exports.RequestTimeoutError=c,exports.TechnicalError=a,exports.ThirdPartyClient=ot,exports.ThirdPartyError=C,exports.TooManyRequestsError=m,exports.UnauthorizedError=y,exports.UserClient=D,exports.UserVerificationError=g,exports.WebauthnClient=nt,exports.WebauthnRequestCancelledError=h,exports.WebauthnSupport=tt;
2
2
  //# sourceMappingURL=sdk.cjs.map