@teamhanko/hanko-frontend-sdk 0.0.5-alpha → 0.0.7-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.
- package/dist/lib/client/Client.d.ts +1 -1
- package/dist/lib/client/HttpClient.d.ts +7 -1
- package/dist/lib/client/PasscodeClient.d.ts +3 -2
- package/dist/lib/client/PasswordClient.d.ts +3 -2
- package/dist/lib/client/WebauthnClient.d.ts +8 -3
- package/dist/lib/state/State.d.ts +5 -7
- package/dist/lib/state/UserState.d.ts +1 -2
- 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 +15 -11
|
@@ -9,7 +9,7 @@ import { HttpClient } from "./HttpClient";
|
|
|
9
9
|
* @param {number=} timeout - The request timeout in milliseconds
|
|
10
10
|
*/
|
|
11
11
|
declare abstract class Client {
|
|
12
|
-
|
|
12
|
+
client: HttpClient;
|
|
13
13
|
constructor(api: string, timeout?: number);
|
|
14
14
|
}
|
|
15
15
|
export { Client };
|
|
@@ -9,6 +9,12 @@
|
|
|
9
9
|
declare class Headers {
|
|
10
10
|
_xhr: XMLHttpRequest;
|
|
11
11
|
constructor(xhr: XMLHttpRequest);
|
|
12
|
+
/**
|
|
13
|
+
* Returns the response header with the given name.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} name
|
|
16
|
+
* @return {string}
|
|
17
|
+
*/
|
|
12
18
|
get(name: string): string;
|
|
13
19
|
}
|
|
14
20
|
/**
|
|
@@ -52,7 +58,7 @@ declare class HttpClient {
|
|
|
52
58
|
timeout: number;
|
|
53
59
|
api: string;
|
|
54
60
|
constructor(api: string, timeout?: number);
|
|
55
|
-
_fetch(path: string, options: RequestInit): Promise<Response>;
|
|
61
|
+
_fetch(path: string, options: RequestInit, xhr?: XMLHttpRequest): Promise<Response>;
|
|
56
62
|
/**
|
|
57
63
|
* Performs a GET request.
|
|
58
64
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PasscodeState } from "../state/PasscodeState";
|
|
1
2
|
import { Passcode } from "../Dto";
|
|
2
3
|
import { Client } from "./Client";
|
|
3
4
|
/**
|
|
@@ -9,8 +10,8 @@ import { Client } from "./Client";
|
|
|
9
10
|
* @extends {Client}
|
|
10
11
|
*/
|
|
11
12
|
declare class PasscodeClient extends Client {
|
|
12
|
-
|
|
13
|
-
constructor(api: string, timeout
|
|
13
|
+
state: PasscodeState;
|
|
14
|
+
constructor(api: string, timeout?: number);
|
|
14
15
|
/**
|
|
15
16
|
* Causes the API to send a new passcode to the user's email address.
|
|
16
17
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PasswordState } from "../state/PasswordState";
|
|
1
2
|
import { Client } from "./Client";
|
|
2
3
|
/**
|
|
3
4
|
* A class to handle passwords.
|
|
@@ -8,8 +9,8 @@ import { Client } from "./Client";
|
|
|
8
9
|
* @extends {Client}
|
|
9
10
|
*/
|
|
10
11
|
declare class PasswordClient extends Client {
|
|
11
|
-
|
|
12
|
-
constructor(api: string, timeout
|
|
12
|
+
state: PasswordState;
|
|
13
|
+
constructor(api: string, timeout?: number);
|
|
13
14
|
/**
|
|
14
15
|
* Logs in a user with a password.
|
|
15
16
|
*
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { WebauthnState } from "../state/WebauthnState";
|
|
2
|
+
import { create as createWebauthnCredential, get as getWebauthnCredential } from "@github/webauthn-json";
|
|
1
3
|
import { User } from "../Dto";
|
|
2
4
|
import { Client } from "./Client";
|
|
3
5
|
/**
|
|
@@ -9,8 +11,11 @@ import { Client } from "./Client";
|
|
|
9
11
|
* @extends {Client}
|
|
10
12
|
*/
|
|
11
13
|
declare class WebauthnClient extends Client {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
state: WebauthnState;
|
|
15
|
+
_getCredentialController: AbortController;
|
|
16
|
+
_getCredential: typeof getWebauthnCredential;
|
|
17
|
+
_createCredential: typeof createWebauthnCredential;
|
|
18
|
+
constructor(api: string, timeout?: number);
|
|
14
19
|
/**
|
|
15
20
|
* Performs a WebAuthn authentication ceremony. When 'userID' is specified, the API provides a list of
|
|
16
21
|
* allowed credentials and the browser is able to present a list of suitable credentials to the user.
|
|
@@ -47,8 +52,8 @@ declare class WebauthnClient extends Client {
|
|
|
47
52
|
*
|
|
48
53
|
* @param {User} user - The user object.
|
|
49
54
|
* @return {Promise<boolean>}
|
|
50
|
-
* @throws {TechnicalError}
|
|
51
55
|
*/
|
|
52
56
|
shouldRegister(user: User): Promise<boolean>;
|
|
57
|
+
_abortPendingGetCredentialRequest(): Promise<void>;
|
|
53
58
|
}
|
|
54
59
|
export { WebauthnClient };
|
|
@@ -18,15 +18,14 @@ interface LocalStorage {
|
|
|
18
18
|
*/
|
|
19
19
|
declare abstract class State {
|
|
20
20
|
private readonly key;
|
|
21
|
-
|
|
21
|
+
ls: LocalStorage;
|
|
22
22
|
constructor(key?: string);
|
|
23
23
|
/**
|
|
24
24
|
* Reads and decodes the locally stored data.
|
|
25
25
|
*
|
|
26
|
-
* @protected
|
|
27
26
|
* @return {State}
|
|
28
27
|
*/
|
|
29
|
-
|
|
28
|
+
read(): State;
|
|
30
29
|
/**
|
|
31
30
|
* Encodes and writes the data to the local storage.
|
|
32
31
|
*
|
|
@@ -37,19 +36,18 @@ declare abstract class State {
|
|
|
37
36
|
* Converts a timestamp into remaining seconds that you can count down.
|
|
38
37
|
*
|
|
39
38
|
* @static
|
|
40
|
-
* @protected
|
|
41
39
|
* @param {number} time - Timestamp in seconds (since January 1, 1970 00:00:00 UTC).
|
|
42
40
|
* @return {number}
|
|
43
41
|
*/
|
|
44
|
-
|
|
42
|
+
static timeToRemainingSeconds(time?: number): number;
|
|
45
43
|
/**
|
|
46
44
|
* Converts a number of seconds into a timestamp.
|
|
47
45
|
*
|
|
48
46
|
* @static
|
|
49
|
-
* @protected
|
|
50
47
|
* @param {number} seconds - Remaining seconds to be converted into a timestamp.
|
|
51
48
|
* @return {number}
|
|
52
49
|
*/
|
|
53
|
-
|
|
50
|
+
static remainingSecondsToTime(seconds?: number): number;
|
|
54
51
|
}
|
|
55
52
|
export { State };
|
|
53
|
+
export type { LocalStorage };
|
|
@@ -43,10 +43,9 @@ declare abstract class UserState extends State {
|
|
|
43
43
|
/**
|
|
44
44
|
* Gets the state of the specified user.
|
|
45
45
|
*
|
|
46
|
-
* @protected
|
|
47
46
|
* @param {string} userID - The UUID of the user.
|
|
48
47
|
* @return {LocalStorageUser}
|
|
49
48
|
*/
|
|
50
|
-
|
|
49
|
+
getUserState(userID: string): LocalStorageUser;
|
|
51
50
|
}
|
|
52
51
|
export { UserState };
|
package/dist/sdk.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function t(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,n(t,e)}function e(t){return e=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},e(t)}function n(t,e){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},n(t,e)}function r(){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 o(t,e,i){return o=r()?Reflect.construct.bind():function(t,e,r){var o=[null];o.push.apply(o,e);var i=new(Function.bind.apply(t,o));return r&&n(i,r.prototype),i},o.apply(null,arguments)}function i(t){var r="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!==r){if(r.has(t))return r.get(t);r.set(t,i)}function i(){return o(t,arguments,e(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),n(i,t)},i(t)}function s(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}var u=/*#__PURE__*/function(e){function n(t,r,o){var i;return(i=e.call(this,t)||this).code=void 0,i.cause=void 0,i.code=r,i.cause=o,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(/*#__PURE__*/i(Error)),c=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Technical error","somethingWentWrong",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(u),a=/*#__PURE__*/function(e){function n(t,r){var o;return o=e.call(this,"Conflict error","conflict",r)||this,Object.setPrototypeOf(s(o),n.prototype),o}return t(n,e),n}(u),f=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Request timed out error","requestTimeout",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(u),p=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Request cancelled error","requestCancelled",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(u),d=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Invalid password error","invalidPassword",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(u),l=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Invalid Passcode error","invalidPasscode",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(u),h=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Invalid WebAuthn credential error","invalidWebauthnCredential",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(u),y=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Passcode expired error","passcodeExpired",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(u),v=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Maximum number of Passcode attempts reached error","passcodeAttemptsReached",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(u),w=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Not found error","notFound",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(u),g=/*#__PURE__*/function(e){function n(t,r){var o;return(o=e.call(this,"Too many requests error","tooManyRequests",r)||this).retryAfter=void 0,o.retryAfter=t,Object.setPrototypeOf(s(o),n.prototype),o}return t(n,e),n}(u),m=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Unauthorized error","unauthorized",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(u);function b(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)t[r]=n[r]}return t}var P=function t(e,n){function r(t,r,o){if("undefined"!=typeof document){"number"==typeof(o=b({},n,o)).expires&&(o.expires=new Date(Date.now()+864e5*o.expires)),o.expires&&(o.expires=o.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var i="";for(var s in o)o[s]&&(i+="; "+s,!0!==o[s]&&(i+="="+o[s].split(";")[0]));return document.cookie=t+"="+e.write(r,t)+i}}return Object.create({set:r,get:function(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var n=document.cookie?document.cookie.split("; "):[],r={},o=0;o<n.length;o++){var i=n[o].split("="),s=i.slice(1).join("=");try{var u=decodeURIComponent(i[0]);if(r[u]=e.read(s,u),t===u)break}catch(t){}}return t?r[t]:r}},remove:function(t,e){r(t,"",b({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,b({},this.attributes,e))},withConverter:function(e){return t(b({},this.converter,e),this.attributes)}},{attributes:{value:Object.freeze(n)},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}(),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.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._decodedJSON=JSON.parse(t.response)}return t.prototype.json=function(){return this._decodedJSON},t}(),x=/*#__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){var n=this.api,r=n+t,o=this.timeout,i="hanko",s=P.get(i);return new Promise(function(t,u){var a=new XMLHttpRequest;a.open(e.method,r,!0),a.setRequestHeader("Accept","application/json"),a.setRequestHeader("Content-Type","application/json"),s&&a.setRequestHeader("Authorization","Bearer "+s),a.timeout=o,a.withCredentials=!0,a.onload=function(){var e=a.getResponseHeader("X-Auth-Token");if(e){var r=!!n.match("^https://");P.set(i,e,{secure:r})}t(new C(a))},a.onerror=function(){u(new c)},a.ontimeout=function(){u(new f)},a.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)})},t}(),A=function(t,e){void 0===e&&(e=13e3),this.client=void 0,this.client=new x(t,e)},R=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n.prototype.get=function(){var t=this;return new Promise(function(e,n){t.client.get("/.well-known/config").then(function(t){if(t.ok)return e(t.json());throw new c}).catch(function(t){n(t)})})},n}(A),S=/*#__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),n=decodeURIComponent(decodeURI(window.atob(e)));t=JSON.parse(n)}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}(),j=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n.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]},n}(S),T=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var r=n.prototype;return r.getState=function(t){var n;return(n=e.prototype.getUserState.call(this,t)).passcode||(n.passcode={})},r.read=function(){return e.prototype.read.call(this),this},r.getActiveID=function(t){return this.getState(t).id},r.setActiveID=function(t,e){return this.getState(t).id=e,this},r.reset=function(t){var e=this.getState(t);return delete e.id,delete e.ttl,delete e.resendAfter,this},r.getTTL=function(t){return S.timeToRemainingSeconds(this.getState(t).ttl)},r.setTTL=function(t,e){return this.getState(t).ttl=S.remainingSecondsToTime(e),this},r.getResendAfter=function(t){return S.timeToRemainingSeconds(this.getState(t).resendAfter)},r.setResendAfter=function(t,e){return this.getState(t).resendAfter=S.remainingSecondsToTime(e),this},n}(j),_=/*#__PURE__*/function(e){function n(t,n){var r;return(r=e.call(this,t,n)||this).state=void 0,r.state=new T,r}t(n,e);var r=n.prototype;return r.initialize=function(t){var e=this;return new Promise(function(n,r){e.client.post("/passcode/login/initialize",{user_id:t}).then(function(n){if(n.ok)return n.json();if(429===n.status){var r=parseInt(n.headers.get("X-Retry-After")||"0",10);throw e.state.read().setResendAfter(t,r).write(),new g(r)}throw new c}).then(function(r){return e.state.read().setActiveID(t,r.id).setTTL(t,r.ttl).write(),n(r)}).catch(function(t){r(t)})})},r.finalize=function(t,e){var n=this,r=this.state.read().getActiveID(t);return new Promise(function(o,i){n.client.post("/passcode/login/finalize",{id:r,code:e}).then(function(e){if(e.ok)return n.state.reset(t).write(),o();throw 401===e.status?new l:410===e.status?(n.state.reset(t).write(),new v):new c}).catch(function(t){i(t)})})},r.getTTL=function(t){return this.state.read().getTTL(t)},r.getResendAfter=function(t){return this.state.read().getResendAfter(t)},n}(A),k=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var r=n.prototype;return r.getState=function(t){var n;return(n=e.prototype.getUserState.call(this,t)).password||(n.password={})},r.read=function(){return e.prototype.read.call(this),this},r.getRetryAfter=function(t){return S.timeToRemainingSeconds(this.getState(t).retryAfter)},r.setRetryAfter=function(t,e){return this.getState(t).retryAfter=S.remainingSecondsToTime(e),this},n}(j),E=/*#__PURE__*/function(e){function n(t,n){var r;return(r=e.call(this,t,n)||this).state=void 0,r.state=new k,r}t(n,e);var r=n.prototype;return r.login=function(t,e){var n=this;return new Promise(function(r,o){n.client.post("/password/login",{user_id:t,password:e}).then(function(e){if(e.ok)return r();if(401===e.status)throw new d;if(429===e.status){var o=parseInt(e.headers.get("X-Retry-After")||"0",10);throw n.state.read().setRetryAfter(t,o).write(),new g(o)}throw new c}).catch(function(t){o(t)})})},r.update=function(t,e){var n=this;return new Promise(function(r,o){n.client.put("/password",{user_id:t,password:e}).then(function(t){if(t.ok)return r();throw new c}).catch(function(t){o(t)})})},r.getRetryAfter=function(t){return this.state.read().getRetryAfter(t)},n}(A),I=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var r=n.prototype;return r.getInfo=function(t){var e=this;return new Promise(function(n,r){e.client.post("/user",{email:t}).then(function(t){if(t.ok)return t.json();throw 404===t.status?new w:new c}).then(function(t){return n(t)}).catch(function(t){r(t)})})},r.create=function(t){var e=this;return new Promise(function(n,r){e.client.post("/users",{email:t}).then(function(t){if(t.ok)return n(t.json());throw 409===t.status?new a:new c}).catch(function(t){r(t)})})},r.getCurrent=function(){var t=this;return new Promise(function(e,n){return t.client.get("/me").then(function(t){if(t.ok)return t.json();throw 400===t.status||401===t.status||404===t.status?new m:new c}).then(function(e){return t.client.get("/users/"+e.id)}).then(function(t){if(t.ok)return e(t.json());throw 400===t.status||401===t.status||404===t.status?new m:new c}).catch(function(t){n(t)})})},n}(A),U=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var r=n.prototype;return r.getState=function(t){var n;return(n=e.prototype.getUserState.call(this,t)).webauthn||(n.webauthn={})},r.read=function(){return e.prototype.read.call(this),this},r.getCredentials=function(t){var e;return(e=this.getState(t)).credentials||(e.credentials=[])},r.addCredential=function(t,e){return this.getCredentials(t).push(e),this},r.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}})},n}(j);function q(t){const e="==".slice(0,(4-t.length%4)%4),n=t.replace(/-/g,"+").replace(/_/g,"/")+e,r=atob(n),o=new ArrayBuffer(r.length),i=new Uint8Array(o);for(let t=0;t<r.length;t++)i[t]=r.charCodeAt(t);return o}function z(t){const e=new Uint8Array(t);let n="";for(const t of e)n+=String.fromCharCode(t);return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function K(t,e,n){if("copy"===e)return n;if("convert"===e)return t(n);if(e instanceof Array)return n.map(n=>K(t,e[0],n));if(e instanceof Object){const r={};for(const[o,i]of Object.entries(e)){if(i.derive){const t=i.derive(n);void 0!==t&&(n[o]=t)}if(o in n)r[o]=null!=n[o]?K(t,i.schema,n[o]):null;else if(i.required)throw new Error(`Missing key: ${o}`)}return r}}function N(t,e){return{required:!0,schema:t,derive:e}}function D(t){return{required:!0,schema:t}}function M(t){return{required:!1,schema:t}}var J={type:D("copy"),id:D("convert"),transports:M("copy")},H={appid:M("copy"),appidExclude:M("copy"),credProps:M("copy")},B={appid:M("copy"),appidExclude:M("copy"),credProps:M("copy")},W={publicKey:D({rp:D("copy"),user:D({id:D("convert"),name:D("copy"),displayName:D("copy")}),challenge:D("convert"),pubKeyCredParams:D("copy"),timeout:M("copy"),excludeCredentials:M([J]),authenticatorSelection:M("copy"),attestation:M("copy"),extensions:M(H)}),signal:M("copy")},F={type:D("copy"),id:D("copy"),rawId:D("convert"),authenticatorAttachment:M("copy"),response:D({clientDataJSON:D("convert"),attestationObject:D("convert"),transports:N("copy",t=>{var e;return(null==(e=t.getTransports)?void 0:e.call(t))||[]})}),clientExtensionResults:N(B,t=>t.getClientExtensionResults())},L={mediation:M("copy"),publicKey:D({challenge:D("convert"),timeout:M("copy"),rpId:M("copy"),allowCredentials:M([J]),userVerification:M("copy"),extensions:M(H)}),signal:M("copy")},X={type:D("copy"),id:D("copy"),rawId:D("convert"),authenticatorAttachment:M("copy"),response:D({clientDataJSON:D("convert"),authenticatorData:D("convert"),signature:D("convert"),userHandle:D("convert")}),clientExtensionResults:N(B,t=>t.getClientExtensionResults())},V=/*#__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&&"function"==typeof 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.isConditionalMediationAvailable?Promise.resolve(window.PublicKeyCredential.isConditionalMediationAvailable()):Promise.resolve(!1)}catch(t){return Promise.reject(t)}},t}(),G=/*#__PURE__*/function(e){function n(t,n){var r;return(r=e.call(this,t,n)||this).state=void 0,r.state=new U,r}t(n,e);var r=n.prototype;return r.login=function(t,e){var n=this;return new Promise(function(r,o){n.client.post("/webauthn/login/initialize",{user_id:t}).then(function(t){if(t.ok)return t.json();throw new c}).catch(function(t){o(t)}).then(function(t){return e&&(t.mediation="conditional"),async function(t){const e=await navigator.credentials.get(function(t){return K(q,L,t)}(t));return function(t){return K(z,X,t)}(e)}(t)}).catch(function(t){throw new p(t)}).then(function(t){return n.client.post("/webauthn/login/finalize",t)}).then(function(t){if(t.ok)return t.json();throw 400===t.status||401===t.status?new h:new c}).catch(function(t){o(t)}).then(function(t){return n.state.read().addCredential(t.user_id,t.credential_id).write(),r()}).catch(function(t){o(t)})})},r.register=function(){var t=this;return new Promise(function(e,n){t.client.post("/webauthn/registration/initialize").then(function(t){if(t.ok)return t.json();if(t.status>=400&&t.status<=499)throw new m;throw new c}).catch(function(t){n(t)}).then(function(t){return async function(t){const e=await navigator.credentials.create(function(t){return K(q,W,t)}(t));return function(t){return K(z,F,t)}(e)}(t)}).catch(function(t){n(new p(t))}).then(function(e){return e.transports=e.response.transports,t.client.post("/webauthn/registration/finalize",e)}).then(function(t){if(t.ok)return t.json();if(t.status>=400&&t.status<=499)throw new m;throw new c}).catch(function(t){n(t)}).then(function(n){return t.state.read().addCredential(n.user_id,n.credential_id).write(),e()}).catch(function(t){n(t)})})},r.shouldRegister=function(t){var e=this;return new Promise(function(n,r){V.isPlatformAuthenticatorAvailable().then(function(r){if(!t.webauthn_credentials||!t.webauthn_credentials.length)return n(r);var o=e.state.read().matchCredentials(t.id,t.webauthn_credentials);return n(r&&!o.length)}).catch(function(t){r(new c(t))})})},n}(A);exports.ConfigClient=R,exports.ConflictError=a,exports.Hanko=function(t,e){void 0===e&&(e=13e3),this.config=void 0,this.user=void 0,this.webauthn=void 0,this.password=void 0,this.passcode=void 0,this.config=new R(t,e),this.user=new I(t,e),this.webauthn=new G(t,e),this.password=new E(t,e),this.passcode=new _(t,e)},exports.HankoError=u,exports.InvalidPasscodeError=l,exports.InvalidPasswordError=d,exports.InvalidWebauthnCredentialError=h,exports.MaxNumOfPasscodeAttemptsReachedError=v,exports.NotFoundError=w,exports.PasscodeClient=_,exports.PasscodeExpiredError=y,exports.PasswordClient=E,exports.RequestTimeoutError=f,exports.TechnicalError=c,exports.TooManyRequestsError=g,exports.UnauthorizedError=m,exports.UserClient=I,exports.WebauthnClient=G,exports.WebauthnRequestCancelledError=p,exports.WebauthnSupport=V;
|
|
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 o(t,e,i){return o=n()?Reflect.construct.bind():function(t,e,n){var o=[null];o.push.apply(o,e);var i=new(Function.bind.apply(t,o));return n&&r(i,n.prototype),i},o.apply(null,arguments)}function i(t){var n="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!==n){if(n.has(t))return n.get(t);n.set(t,i)}function i(){return o(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 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,o){var i;return(i=e.call(this,t)||this).code=void 0,i.cause=void 0,i.code=n,i.cause=o,Object.setPrototypeOf(s(i),r.prototype),i}return t(r,e),r}(/*#__PURE__*/i(Error)),u=/*#__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),c=/*#__PURE__*/function(e){function r(t,n){var o;return o=e.call(this,"Conflict error","conflict",n)||this,Object.setPrototypeOf(s(o),r.prototype),o}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),d=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Request cancelled error","requestCancelled",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),f=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Invalid password error","invalidPassword",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),p=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Invalid Passcode error","invalidPasscode",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),h=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Invalid WebAuthn credential error","invalidWebauthnCredential",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),v=/*#__PURE__*/function(e){function r(t){var n;return n=e.call(this,"Passcode expired error","passcodeExpired",t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(a),y=/*#__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),w=/*#__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),g=/*#__PURE__*/function(e){function r(t,n){var o;return(o=e.call(this,"Too many requests error","tooManyRequests",n)||this).retryAfter=void 0,o.retryAfter=t,Object.setPrototypeOf(s(o),r.prototype),o}return t(r,e),r}(a),m=/*#__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);function b(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 P=function t(e,r){function n(t,n,o){if("undefined"!=typeof document){"number"==typeof(o=b({},r,o)).expires&&(o.expires=new Date(Date.now()+864e5*o.expires)),o.expires&&(o.expires=o.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var i="";for(var s in o)o[s]&&(i+="; "+s,!0!==o[s]&&(i+="="+o[s].split(";")[0]));return document.cookie=t+"="+e.write(n,t)+i}}return Object.create({set:n,get:function(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var r=document.cookie?document.cookie.split("; "):[],n={},o=0;o<r.length;o++){var i=r[o].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(n[a]=e.read(s,a),t===a)break}catch(t){}}return t?n[t]:n}},remove:function(t,e){n(t,"",b({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,b({},this.attributes,e))},withConverter:function(e){return t(b({},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:"/"}),C=/*#__PURE__*/function(){function t(t){this._xhr=void 0,this._xhr=t}return t.prototype.get=function(t){return this._xhr.getResponseHeader(t)},t}(),O=/*#__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.headers=new C(t),this.ok=t.status>=200&&t.status<=299,this.status=t.status,this.statusText=t.statusText,this.url=t.responseURL,this._decodedJSON=JSON.parse(t.response)}return t.prototype.json=function(){return this._decodedJSON},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,o=n+t,i=this.timeout,s="hanko",a=P.get(s);return new Promise(function(t,c){r.open(e.method,o,!0),r.setRequestHeader("Accept","application/json"),r.setRequestHeader("Content-Type","application/json"),a&&r.setRequestHeader("Authorization","Bearer "+a),r.timeout=i,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 o=!!n.match("^https://");P.set(s,e,{secure:o})}}t(new O(r))},r.onerror=function(){c(new u)},r.ontimeout=function(){c(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)})},t}(),j=function(t,e){void 0===e&&(e=13e3),this.client=void 0,this.client=new R(t,e)},A=/*#__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 u;return t.json()})}catch(t){return Promise.reject(t)}},r}(j),x=/*#__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}(),S=/*#__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}(x),_=/*#__PURE__*/function(e){function r(){return e.apply(this,arguments)||this}t(r,e);var n=r.prototype;return n.getState=function(t){var r;return(r=e.prototype.getUserState.call(this,t)).passcode||(r.passcode={})},n.read=function(){return e.prototype.read.call(this),this},n.getActiveID=function(t){return this.getState(t).id},n.setActiveID=function(t,e){return this.getState(t).id=e,this},n.reset=function(t){var e=this.getState(t);return delete e.id,delete e.ttl,delete e.resendAfter,this},n.getTTL=function(t){return x.timeToRemainingSeconds(this.getState(t).ttl)},n.setTTL=function(t,e){return this.getState(t).ttl=x.remainingSecondsToTime(e),this},n.getResendAfter=function(t){return x.timeToRemainingSeconds(this.getState(t).resendAfter)},n.setResendAfter=function(t,e){return this.getState(t).resendAfter=x.remainingSecondsToTime(e),this},r}(S),T=/*#__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 _,n}t(r,e);var n=r.prototype;return n.initialize=function(t){try{var e=this;return Promise.resolve(e.client.post("/passcode/login/initialize",{user_id:t})).then(function(r){if(429===r.status){var n=parseInt(r.headers.get("X-Retry-After")||"0",10);throw e.state.read().setResendAfter(t,n).write(),new g(n)}if(!r.ok)throw new u;var o=r.json();return e.state.read().setActiveID(t,o.id).setTTL(t,o.ttl).write(),o})}catch(t){return Promise.reject(t)}},n.finalize=function(t,e){try{var r=this,n=r.state.read().getActiveID(t);return Promise.resolve(r.client.post("/passcode/login/finalize",{id:n,code:e})).then(function(e){if(401===e.status)throw new p;if(410===e.status)throw r.state.reset(t).write(),new y;if(!e.ok)throw new u;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}(j),k=/*#__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 x.timeToRemainingSeconds(this.getState(t).retryAfter)},n.setRetryAfter=function(t,e){return this.getState(t).retryAfter=x.remainingSecondsToTime(e),this},r}(S),E=/*#__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 k,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 f;if(429===e.status){var n=parseInt(e.headers.get("X-Retry-After")||"0",10);throw r.state.read().setRetryAfter(t,n).write(),new g(n)}if(!e.ok)throw new u})}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(!t.ok)throw new u})}catch(t){return Promise.reject(t)}},n.getRetryAfter=function(t){return this.state.read().getRetryAfter(t)},r}(j),I=/*#__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 w;if(!t.ok)throw new u;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 c;if(!t.ok)throw new u;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 m;if(!e.ok)throw new u;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 m;if(!t.ok)throw new u;return t.json()})})}catch(t){return Promise.reject(t)}},r}(j),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)).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}(S);function q(t){const e="==".slice(0,(4-t.length%4)%4),r=t.replace(/-/g,"+").replace(/_/g,"/")+e,n=atob(r),o=new ArrayBuffer(n.length),i=new Uint8Array(o);for(let t=0;t<n.length;t++)i[t]=n.charCodeAt(t);return o}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 z(t,e,r){if("copy"===e)return r;if("convert"===e)return t(r);if(e instanceof Array)return r.map(r=>z(t,e[0],r));if(e instanceof Object){const n={};for(const[o,i]of Object.entries(e)){if(i.derive){const t=i.derive(r);void 0!==t&&(r[o]=t)}if(o in r)n[o]=null!=r[o]?z(t,i.schema,r[o]):null;else if(i.required)throw new Error(`Missing key: ${o}`)}return n}}function N(t,e){return{required:!0,schema:t,derive:e}}function D(t){return{required:!0,schema:t}}function M(t){return{required:!1,schema:t}}var H={type:D("copy"),id:D("convert"),transports:M("copy")},J={appid:M("copy"),appidExclude:M("copy"),credProps:M("copy")},L={appid:M("copy"),appidExclude:M("copy"),credProps:M("copy")},W={publicKey:D({rp:D("copy"),user:D({id:D("convert"),name:D("copy"),displayName:D("copy")}),challenge:D("convert"),pubKeyCredParams:D("copy"),timeout:M("copy"),excludeCredentials:M([H]),authenticatorSelection:M("copy"),attestation:M("copy"),extensions:M(J)}),signal:M("copy")},B={type:D("copy"),id:D("copy"),rawId:D("convert"),authenticatorAttachment:M("copy"),response:D({clientDataJSON:D("convert"),attestationObject:D("convert"),transports:N("copy",t=>{var e;return(null==(e=t.getTransports)?void 0:e.call(t))||[]})}),clientExtensionResults:N(L,t=>t.getClientExtensionResults())},F={mediation:M("copy"),publicKey:D({challenge:D("convert"),timeout:M("copy"),rpId:M("copy"),allowCredentials:M([H]),userVerification:M("copy"),extensions:M(J)}),signal:M("copy")},G={type:D("copy"),id:D("copy"),rawId:D("convert"),authenticatorAttachment:M("copy"),response:D({clientDataJSON:D("convert"),authenticatorData:D("convert"),signature:D("convert"),userHandle:D("convert")}),clientExtensionResults:N(L,t=>t.getClientExtensionResults())};async function X(t){const e=await navigator.credentials.create(function(t){return z(q,W,t)}(t));return function(t){return z(K,B,t)}(e)}async function V(t){const e=await navigator.credentials.get(function(t){return z(q,F,t)}(t));return function(t){return z(K,G,t)}(e)}var $=/*#__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}();function Q(t,e){try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}var Y=/*#__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._getCredentialController=void 0,n._getCredential=V,n._createCredential=X,n.state=new U,n._getCredentialController=new AbortController,n}t(r,e);var n=r.prototype;return n.login=function(t,e){try{var r=this;return Promise.resolve(r._abortPendingGetCredentialRequest()).then(function(){return Promise.resolve(r.client.post("/webauthn/login/initialize",{user_id:t})).then(function(t){function n(t){return Promise.resolve(r.client.post("/webauthn/login/finalize",o)).then(function(t){if(400===t.status||401===t.status)throw new h;if(!t.ok)throw new u;var e=t.json();r.state.read().addCredential(e.user_id,e.credential_id).write()})}if(!t.ok)throw new u;var o,i=t.json();e&&(i.mediation="conditional",r._getCredentialController=new AbortController,i.signal=r._getCredentialController.signal);var s=Q(function(){return Promise.resolve(r._getCredential(i)).then(function(t){o=t})},function(t){throw new d(t)});return s&&s.then?s.then(n):n()})})}catch(t){return Promise.reject(t)}},n.register=function(){try{var t=this;return Promise.resolve(t._abortPendingGetCredentialRequest()).then(function(){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)throw new m;if(!e.ok)throw new u;var r=e.json();t.state.read().addCredential(r.user_id,r.credential_id).write()})}if(e.status>=400&&e.status<=499)throw new m;if(!e.ok)throw new u;var n,o=e.json(),i=Q(function(){return Promise.resolve(t._createCredential(o)).then(function(t){n=t})},function(t){throw new d(t)});return i&&i.then?i.then(r):r()})})}catch(t){return Promise.reject(t)}},n.shouldRegister=function(t){try{var e=this;return Promise.resolve($.isPlatformAuthenticatorAvailable()).then(function(r){if(!t.webauthn_credentials||!t.webauthn_credentials.length)return r;var n=e.state.read().matchCredentials(t.id,t.webauthn_credentials);return r&&!n.length})}catch(t){return Promise.reject(t)}},n._abortPendingGetCredentialRequest=function(){var t=this._getCredentialController;return new Promise(function(e){t&&(t.signal.addEventListener("abort",function(){e()}),t.abort())})},r}(j);exports.ConfigClient=A,exports.ConflictError=c,exports.Hanko=function(t,e){void 0===e&&(e=13e3),this.config=void 0,this.user=void 0,this.webauthn=void 0,this.password=void 0,this.passcode=void 0,this.config=new A(t,e),this.user=new I(t,e),this.webauthn=new Y(t,e),this.password=new E(t,e),this.passcode=new T(t,e)},exports.HankoError=a,exports.InvalidPasscodeError=p,exports.InvalidPasswordError=f,exports.InvalidWebauthnCredentialError=h,exports.MaxNumOfPasscodeAttemptsReachedError=y,exports.NotFoundError=w,exports.PasscodeClient=T,exports.PasscodeExpiredError=v,exports.PasswordClient=E,exports.RequestTimeoutError=l,exports.TechnicalError=u,exports.TooManyRequestsError=g,exports.UnauthorizedError=m,exports.UserClient=I,exports.WebauthnClient=Y,exports.WebauthnRequestCancelledError=d,exports.WebauthnSupport=$;
|
|
2
2
|
//# sourceMappingURL=sdk.cjs.map
|