@teamhanko/hanko-frontend-sdk 0.0.2-alpha → 0.0.3-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/README.md +1 -1
- package/dist/Hanko.d.ts +1 -0
- package/dist/lib/client/ConfigClient.d.ts +1 -1
- package/dist/lib/client/HttpClient.d.ts +2 -0
- package/dist/lib/client/PasscodeClient.d.ts +2 -2
- package/dist/lib/client/PasswordClient.d.ts +2 -2
- package/dist/lib/client/UserClient.d.ts +4 -4
- package/dist/lib/client/WebauthnClient.d.ts +4 -4
- 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 +3 -3
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ With a script tag via CDN:
|
|
|
39
39
|
|
|
40
40
|
## Documentation
|
|
41
41
|
|
|
42
|
-
To see the latest documentation, please click [here](https://
|
|
42
|
+
To see the latest documentation, please click [here](https://docs.hanko.io/jsdoc/hanko-frontend-sdk).
|
|
43
43
|
|
|
44
44
|
## Exports
|
|
45
45
|
|
package/dist/Hanko.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ declare class ConfigClient extends Client {
|
|
|
13
13
|
* @return {Promise<Config>}
|
|
14
14
|
* @throws {RequestTimeoutError}
|
|
15
15
|
* @throws {TechnicalError}
|
|
16
|
-
* @see https://
|
|
16
|
+
* @see https://docs.hanko.io/api/public#tag/.well-known/operation/getConfig
|
|
17
17
|
*/
|
|
18
18
|
get(): Promise<Config>;
|
|
19
19
|
}
|
|
@@ -51,7 +51,9 @@ declare class Response {
|
|
|
51
51
|
declare class HttpClient {
|
|
52
52
|
timeout: number;
|
|
53
53
|
api: string;
|
|
54
|
+
isSameOrigin: boolean;
|
|
54
55
|
constructor(api: string, timeout?: number);
|
|
56
|
+
_detectSameOrigin(api: string): boolean;
|
|
55
57
|
_fetch(path: string, options: RequestInit): Promise<Response>;
|
|
56
58
|
/**
|
|
57
59
|
* Performs a GET request.
|
|
@@ -19,7 +19,7 @@ declare class PasscodeClient extends Client {
|
|
|
19
19
|
* @throws {TooManyRequestsError}
|
|
20
20
|
* @throws {RequestTimeoutError}
|
|
21
21
|
* @throws {TechnicalError}
|
|
22
|
-
* @see https://
|
|
22
|
+
* @see https://docs.hanko.io/api/public#tag/Passcode/operation/passcodeInit
|
|
23
23
|
*/
|
|
24
24
|
initialize(userID: string): Promise<Passcode>;
|
|
25
25
|
/**
|
|
@@ -32,7 +32,7 @@ declare class PasscodeClient extends Client {
|
|
|
32
32
|
* @throws {MaxNumOfPasscodeAttemptsReachedError}
|
|
33
33
|
* @throws {RequestTimeoutError}
|
|
34
34
|
* @throws {TechnicalError}
|
|
35
|
-
* @see https://
|
|
35
|
+
* @see https://docs.hanko.io/api/public#tag/Passcode/operation/passcodeFinal
|
|
36
36
|
*/
|
|
37
37
|
finalize(userID: string, code: string): Promise<void>;
|
|
38
38
|
/**
|
|
@@ -19,7 +19,7 @@ declare class PasswordClient extends Client {
|
|
|
19
19
|
* @throws {TooManyRequestsError}
|
|
20
20
|
* @throws {RequestTimeoutError}
|
|
21
21
|
* @throws {TechnicalError}
|
|
22
|
-
* @see https://
|
|
22
|
+
* @see https://docs.hanko.io/api/public#tag/Password/operation/passwordLogin
|
|
23
23
|
*/
|
|
24
24
|
login(userID: string, password: string): Promise<void>;
|
|
25
25
|
/**
|
|
@@ -31,7 +31,7 @@ declare class PasswordClient extends Client {
|
|
|
31
31
|
* @throws {RequestTimeoutError}
|
|
32
32
|
* @throws {UnauthorizedError}
|
|
33
33
|
* @throws {TechnicalError}
|
|
34
|
-
* @see https://
|
|
34
|
+
* @see https://docs.hanko.io/api/public#tag/Password/operation/password
|
|
35
35
|
*/
|
|
36
36
|
update(userID: string, password: string): Promise<void>;
|
|
37
37
|
/**
|
|
@@ -18,7 +18,7 @@ declare class UserClient extends Client {
|
|
|
18
18
|
* @throws {NotFoundError}
|
|
19
19
|
* @throws {RequestTimeoutError}
|
|
20
20
|
* @throws {TechnicalError}
|
|
21
|
-
* @see https://
|
|
21
|
+
* @see https://docs.hanko.io/api/public#tag/User-Management/operation/getUserId
|
|
22
22
|
*/
|
|
23
23
|
getInfo(email: string): Promise<UserInfo>;
|
|
24
24
|
/**
|
|
@@ -30,7 +30,7 @@ declare class UserClient extends Client {
|
|
|
30
30
|
* @throws {ConflictError}
|
|
31
31
|
* @throws {RequestTimeoutError}
|
|
32
32
|
* @throws {TechnicalError}
|
|
33
|
-
* @see https://
|
|
33
|
+
* @see https://docs.hanko.io/api/public#tag/User-Management/operation/createUser
|
|
34
34
|
*/
|
|
35
35
|
create(email: string): Promise<User>;
|
|
36
36
|
/**
|
|
@@ -40,8 +40,8 @@ declare class UserClient extends Client {
|
|
|
40
40
|
* @throws {UnauthorizedError}
|
|
41
41
|
* @throws {RequestTimeoutError}
|
|
42
42
|
* @throws {TechnicalError}
|
|
43
|
-
* @see https://
|
|
44
|
-
* @see https://
|
|
43
|
+
* @see https://docs.hanko.io/api/public#tag/User-Management/operation/IsUserAuthorized
|
|
44
|
+
* @see https://docs.hanko.io/api/public#tag/User-Management/operation/listUser
|
|
45
45
|
*/
|
|
46
46
|
getCurrent(): Promise<User>;
|
|
47
47
|
}
|
|
@@ -21,8 +21,8 @@ declare class WebauthnClient extends Client {
|
|
|
21
21
|
* @throws {InvalidWebauthnCredentialError}
|
|
22
22
|
* @throws {RequestTimeoutError}
|
|
23
23
|
* @throws {TechnicalError}
|
|
24
|
-
* @see https://
|
|
25
|
-
* @see https://
|
|
24
|
+
* @see https://docs.hanko.io/api/public#tag/WebAuthn/operation/webauthnLoginInit
|
|
25
|
+
* @see https://docs.hanko.io/api/public#tag/WebAuthn/operation/webauthnLoginFinal
|
|
26
26
|
* @see https://www.w3.org/TR/webauthn-2/#authentication-ceremony
|
|
27
27
|
*/
|
|
28
28
|
login(userID?: string): Promise<void>;
|
|
@@ -34,8 +34,8 @@ declare class WebauthnClient extends Client {
|
|
|
34
34
|
* @throws {RequestTimeoutError}
|
|
35
35
|
* @throws {UnauthorizedError}
|
|
36
36
|
* @throws {TechnicalError}
|
|
37
|
-
* @see https://
|
|
38
|
-
* @see https://
|
|
37
|
+
* @see https://docs.hanko.io/api/public#tag/WebAuthn/operation/webauthnRegInit
|
|
38
|
+
* @see https://docs.hanko.io/api/public#tag/WebAuthn/operation/webauthnRegFinal
|
|
39
39
|
* @see https://www.w3.org/TR/webauthn-2/#sctn-registering-a-new-credential
|
|
40
40
|
*/
|
|
41
41
|
register(): Promise<void>;
|
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),h=/*#__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),d=/*#__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),l=/*#__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}(),x=/*#__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}(),C=/*#__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 x(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}(),R=function(t,e){void 0===e&&(e=13e3),this.client=void 0,this.client=new C(t,e)},S=/*#__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}(R),A=/*#__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}(A),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 A.timeToRemainingSeconds(this.getState(t).ttl)},r.setTTL=function(t,e){return this.getState(t).ttl=A.remainingSecondsToTime(e),this},r.getResendAfter=function(t){return A.timeToRemainingSeconds(this.getState(t).resendAfter)},r.setResendAfter=function(t,e){return this.getState(t).resendAfter=A.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 d:404===e.status||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}(R),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 A.timeToRemainingSeconds(this.getState(t).retryAfter)},r.setRetryAfter=function(t,e){return this.getState(t).retryAfter=A.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 h;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}(R),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}(R),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 N(t,e,n){if("copy"===e)return n;if("convert"===e)return t(n);if(e instanceof Array)return n.map(n=>N(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]?N(t,i.schema,n[o]):null;else if(i.required)throw new Error(`Missing key: ${o}`)}return r}}function D(t,e){return{required:!0,schema:t,derive:e}}function K(t){return{required:!0,schema:t}}function J(t){return{required:!1,schema:t}}var M={type:K("copy"),id:K("convert"),transports:J("copy")},H={appid:J("copy"),appidExclude:J("copy"),credProps:J("copy")},B={appid:J("copy"),appidExclude:J("copy"),credProps:J("copy")},W={publicKey:K({rp:K("copy"),user:K({id:K("convert"),name:K("copy"),displayName:K("copy")}),challenge:K("convert"),pubKeyCredParams:K("copy"),timeout:J("copy"),excludeCredentials:J([M]),authenticatorSelection:J("copy"),attestation:J("copy"),extensions:J(H)}),signal:J("copy")},F={type:K("copy"),id:K("copy"),rawId:K("convert"),authenticatorAttachment:J("copy"),response:K({clientDataJSON:K("convert"),attestationObject:K("convert"),transports:D("copy",t=>{var e;return(null==(e=t.getTransports)?void 0:e.call(t))||[]})}),clientExtensionResults:D(B,t=>t.getClientExtensionResults())},L={mediation:J("copy"),publicKey:K({challenge:K("convert"),timeout:J("copy"),rpId:J("copy"),allowCredentials:J([M]),userVerification:J("copy"),extensions:J(H)}),signal:J("copy")},X={type:K("copy"),id:K("copy"),rawId:K("convert"),authenticatorAttachment:J("copy"),response:K({clientDataJSON:K("convert"),authenticatorData:K("convert"),signature:K("convert"),userHandle:K("convert")}),clientExtensionResults:D(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{var t,e=this,n=function(){if(e.supported()&&window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return Promise.resolve(window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()).then(function(e){return t=1,e})}();return Promise.resolve(n&&n.then?n.then(function(e){return!!t&&e}):!!t&&n)}catch(t){return Promise.reject(t)}},t.isSecurityKeySupported=function(){try{var t,e=function(e){return t?e:n.supported()},n=this,r=function(){if(void 0!==window.PublicKeyCredential&&"function"==typeof window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported)return Promise.resolve(window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported()).then(function(e){return t=1,e})}();return Promise.resolve(r&&r.then?r.then(e):e(r))}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){var e=this;return new Promise(function(n,r){e.client.post("/webauthn/login/initialize",{user_id:t}).then(function(t){if(t.ok)return t.json();throw new c}).catch(function(t){r(t)}).then(function(t){return async function(t){const e=await navigator.credentials.get(function(t){return N(q,L,t)}(t));return function(t){return N(z,X,t)}(e)}(t)}).catch(function(t){throw new p(t)}).then(function(t){return e.client.post("/webauthn/login/finalize",t)}).then(function(t){if(t.ok)return t.json();throw 400===t.status||401===t.status?new l:new c}).catch(function(t){r(t)}).then(function(t){return e.state.read().addCredential(t.user_id,t.credential_id).write(),n()}).catch(function(t){r(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 N(q,W,t)}(t));return function(t){return N(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}(R);exports.ConfigClient=S,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 S(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=d,exports.InvalidPasswordError=h,exports.InvalidWebauthnCredentialError=l,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,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),h=/*#__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),p=/*#__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),d=/*#__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),l=/*#__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 O=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:"/"}),P=/*#__PURE__*/function(){function t(t){this._xhr=void 0,this._xhr=t}return t.prototype.get=function(t){return this._xhr.getResponseHeader(t)},t}(),S=/*#__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 P(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.isSameOrigin=void 0,this.api=t,this.timeout=e,this.isSameOrigin=this._detectSameOrigin(t)}var e=t.prototype;return e._detectSameOrigin=function(t){var e=window.location,n=document.createElement("a");return n.href=t,"localhost"===n.hostname&&"localhost"===e.hostname&&n.protocol===e.protocol||n.hostname===e.hostname&&n.port===e.port&&n.protocol===e.protocol},e._fetch=function(t,e){var n=this.api,r=n+t,o=this.timeout,i=this.isSameOrigin,s="hanko",u=O.get(s);return new Promise(function(t,a){var h=new XMLHttpRequest;h.open(e.method,r,!0),h.setRequestHeader("Accept","application/json"),h.setRequestHeader("Content-Type","application/json"),u&&h.setRequestHeader("Authorization","Bearer "+u),h.timeout=o,h.withCredentials=!0,h.onload=function(){if(!i){var e=h.getResponseHeader("X-Auth-Token");if(e){var r=!!n.match("^https://");O.set(s,e,{secure:r})}}t(new S(h))},h.onerror=function(){a(new c)},h.ontimeout=function(){a(new f)},h.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}(),C=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}(C),A=/*#__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}(A),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 A.timeToRemainingSeconds(this.getState(t).ttl)},r.setTTL=function(t,e){return this.getState(t).ttl=A.remainingSecondsToTime(e),this},r.getResendAfter=function(t){return A.timeToRemainingSeconds(this.getState(t).resendAfter)},r.setResendAfter=function(t,e){return this.getState(t).resendAfter=A.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 d:404===e.status||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}(C),E=/*#__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 A.timeToRemainingSeconds(this.getState(t).retryAfter)},r.setRetryAfter=function(t,e){return this.getState(t).retryAfter=A.remainingSecondsToTime(e),this},n}(j),k=/*#__PURE__*/function(e){function n(t,n){var r;return(r=e.call(this,t,n)||this).state=void 0,r.state=new E,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 p;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}(C),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}(C),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 N(t,e,n){if("copy"===e)return n;if("convert"===e)return t(n);if(e instanceof Array)return n.map(n=>N(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]?N(t,i.schema,n[o]):null;else if(i.required)throw new Error(`Missing key: ${o}`)}return r}}function D(t,e){return{required:!0,schema:t,derive:e}}function K(t){return{required:!0,schema:t}}function J(t){return{required:!1,schema:t}}var M={type:K("copy"),id:K("convert"),transports:J("copy")},H={appid:J("copy"),appidExclude:J("copy"),credProps:J("copy")},B={appid:J("copy"),appidExclude:J("copy"),credProps:J("copy")},W={publicKey:K({rp:K("copy"),user:K({id:K("convert"),name:K("copy"),displayName:K("copy")}),challenge:K("convert"),pubKeyCredParams:K("copy"),timeout:J("copy"),excludeCredentials:J([M]),authenticatorSelection:J("copy"),attestation:J("copy"),extensions:J(H)}),signal:J("copy")},F={type:K("copy"),id:K("copy"),rawId:K("convert"),authenticatorAttachment:J("copy"),response:K({clientDataJSON:K("convert"),attestationObject:K("convert"),transports:D("copy",t=>{var e;return(null==(e=t.getTransports)?void 0:e.call(t))||[]})}),clientExtensionResults:D(B,t=>t.getClientExtensionResults())},L={mediation:J("copy"),publicKey:K({challenge:K("convert"),timeout:J("copy"),rpId:J("copy"),allowCredentials:J([M]),userVerification:J("copy"),extensions:J(H)}),signal:J("copy")},X={type:K("copy"),id:K("copy"),rawId:K("convert"),authenticatorAttachment:J("copy"),response:K({clientDataJSON:K("convert"),authenticatorData:K("convert"),signature:K("convert"),userHandle:K("convert")}),clientExtensionResults:D(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{var t,e=this,n=function(){if(e.supported()&&window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return Promise.resolve(window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()).then(function(e){return t=1,e})}();return Promise.resolve(n&&n.then?n.then(function(e){return!!t&&e}):!!t&&n)}catch(t){return Promise.reject(t)}},t.isSecurityKeySupported=function(){try{var t,e=function(e){return t?e:n.supported()},n=this,r=function(){if(void 0!==window.PublicKeyCredential&&"function"==typeof window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported)return Promise.resolve(window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported()).then(function(e){return t=1,e})}();return Promise.resolve(r&&r.then?r.then(e):e(r))}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){var e=this;return new Promise(function(n,r){e.client.post("/webauthn/login/initialize",{user_id:t}).then(function(t){if(t.ok)return t.json();throw new c}).catch(function(t){r(t)}).then(function(t){return async function(t){const e=await navigator.credentials.get(function(t){return N(q,L,t)}(t));return function(t){return N(z,X,t)}(e)}(t)}).catch(function(t){throw new h(t)}).then(function(t){return e.client.post("/webauthn/login/finalize",t)}).then(function(t){if(t.ok)return t.json();throw 400===t.status||401===t.status?new l:new c}).catch(function(t){r(t)}).then(function(t){return e.state.read().addCredential(t.user_id,t.credential_id).write(),n()}).catch(function(t){r(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 N(q,W,t)}(t));return function(t){return N(z,F,t)}(e)}(t)}).catch(function(t){n(new h(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}(C);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.isSameOrigin=void 0,this.config=new R(t,e),this.user=new I(t,e),this.webauthn=new G(t,e),this.password=new k(t,e),this.passcode=new _(t,e)},exports.HankoError=u,exports.InvalidPasscodeError=d,exports.InvalidPasswordError=p,exports.InvalidWebauthnCredentialError=l,exports.MaxNumOfPasscodeAttemptsReachedError=v,exports.NotFoundError=w,exports.PasscodeClient=_,exports.PasscodeExpiredError=y,exports.PasswordClient=k,exports.RequestTimeoutError=f,exports.TechnicalError=c,exports.TooManyRequestsError=g,exports.UnauthorizedError=m,exports.UserClient=I,exports.WebauthnClient=G,exports.WebauthnRequestCancelledError=h,exports.WebauthnSupport=V;
|
|
2
2
|
//# sourceMappingURL=sdk.cjs.map
|