@teamhanko/hanko-frontend-sdk 0.1.1-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.
- package/dist/Hanko.d.ts +3 -0
- package/dist/index.d.ts +6 -5
- package/dist/lib/Dto.d.ts +19 -1
- package/dist/lib/Errors.d.ts +12 -1
- package/dist/lib/client/HttpClient.d.ts +20 -0
- package/dist/lib/client/ThirdPartyClient.d.ts +29 -0
- package/dist/lib/client/UserClient.d.ts +7 -0
- package/dist/sdk.cjs +1 -1
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.modern.js +1 -1
- package/dist/sdk.modern.js.map +1 -1
- package/dist/sdk.module.js +1 -1
- package/dist/sdk.module.js.map +1 -1
- package/dist/sdk.umd.js +1 -1
- package/dist/sdk.umd.js.map +1 -1
- package/package.json +9 -9
package/dist/Hanko.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { PasswordClient } from "./lib/client/PasswordClient";
|
|
|
4
4
|
import { UserClient } from "./lib/client/UserClient";
|
|
5
5
|
import { WebauthnClient } from "./lib/client/WebauthnClient";
|
|
6
6
|
import { EmailClient } from "./lib/client/EmailClient";
|
|
7
|
+
import { ThirdPartyClient } from "./lib/client/ThirdPartyClient";
|
|
7
8
|
/**
|
|
8
9
|
* A class that bundles all available SDK functions.
|
|
9
10
|
*
|
|
@@ -11,12 +12,14 @@ import { EmailClient } from "./lib/client/EmailClient";
|
|
|
11
12
|
* @param {number=} timeout - The request timeout in milliseconds
|
|
12
13
|
*/
|
|
13
14
|
declare class Hanko {
|
|
15
|
+
api: string;
|
|
14
16
|
config: ConfigClient;
|
|
15
17
|
user: UserClient;
|
|
16
18
|
webauthn: WebauthnClient;
|
|
17
19
|
password: PasswordClient;
|
|
18
20
|
passcode: PasscodeClient;
|
|
19
21
|
email: EmailClient;
|
|
22
|
+
thirdParty: ThirdPartyClient;
|
|
20
23
|
constructor(api: string, timeout?: number);
|
|
21
24
|
}
|
|
22
25
|
export { Hanko };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,11 @@ import { PasswordClient } from "./lib/client/PasswordClient";
|
|
|
6
6
|
import { UserClient } from "./lib/client/UserClient";
|
|
7
7
|
import { WebauthnClient } from "./lib/client/WebauthnClient";
|
|
8
8
|
import { EmailClient } from "./lib/client/EmailClient";
|
|
9
|
-
|
|
9
|
+
import { ThirdPartyClient } from "./lib/client/ThirdPartyClient";
|
|
10
|
+
export { ConfigClient, UserClient, WebauthnClient, PasswordClient, PasscodeClient, EmailClient, ThirdPartyClient, };
|
|
10
11
|
import { WebauthnSupport } from "./lib/WebauthnSupport";
|
|
11
12
|
export { WebauthnSupport };
|
|
12
|
-
import { PasswordConfig, Config, WebauthnFinalized, Credential, UserInfo, User, Email, Emails, WebauthnCredential, WebauthnCredentials, Passcode } from "./lib/Dto";
|
|
13
|
-
export type { PasswordConfig, Config, WebauthnFinalized, Credential, UserInfo, User, Email, Emails, WebauthnCredential, WebauthnCredentials, Passcode, };
|
|
14
|
-
import { HankoError, ConflictError, EmailAddressAlreadyExistsError, InvalidPasswordError, InvalidPasscodeError, InvalidWebauthnCredentialError, MaxNumOfEmailAddressesReachedError, MaxNumOfPasscodeAttemptsReachedError, NotFoundError, PasscodeExpiredError, RequestTimeoutError, TechnicalError, TooManyRequestsError, UnauthorizedError, UserVerificationError, WebauthnRequestCancelledError } from "./lib/Errors";
|
|
15
|
-
export { HankoError, ConflictError, EmailAddressAlreadyExistsError, InvalidPasswordError, InvalidPasscodeError, InvalidWebauthnCredentialError, MaxNumOfEmailAddressesReachedError, MaxNumOfPasscodeAttemptsReachedError, NotFoundError, PasscodeExpiredError, RequestTimeoutError, TechnicalError, TooManyRequestsError, UnauthorizedError, UserVerificationError, WebauthnRequestCancelledError, };
|
|
13
|
+
import { PasswordConfig, Config, WebauthnFinalized, Credential, UserInfo, User, Email, Emails, WebauthnCredential, WebauthnCredentials, Passcode, Identity } from "./lib/Dto";
|
|
14
|
+
export type { PasswordConfig, Config, WebauthnFinalized, Credential, UserInfo, User, Email, Emails, WebauthnCredential, WebauthnCredentials, Passcode, Identity, };
|
|
15
|
+
import { HankoError, ConflictError, EmailAddressAlreadyExistsError, InvalidPasswordError, InvalidPasscodeError, InvalidWebauthnCredentialError, MaxNumOfEmailAddressesReachedError, MaxNumOfPasscodeAttemptsReachedError, NotFoundError, PasscodeExpiredError, RequestTimeoutError, TechnicalError, ThirdPartyError, TooManyRequestsError, UnauthorizedError, UserVerificationError, WebauthnRequestCancelledError } from "./lib/Errors";
|
|
16
|
+
export { HankoError, ConflictError, EmailAddressAlreadyExistsError, InvalidPasswordError, InvalidPasscodeError, InvalidWebauthnCredentialError, MaxNumOfEmailAddressesReachedError, MaxNumOfPasscodeAttemptsReachedError, NotFoundError, PasscodeExpiredError, RequestTimeoutError, TechnicalError, ThirdPartyError, TooManyRequestsError, UnauthorizedError, UserVerificationError, WebauthnRequestCancelledError, };
|
package/dist/lib/Dto.d.ts
CHANGED
|
@@ -26,10 +26,13 @@ interface EmailConfig {
|
|
|
26
26
|
* @category SDK
|
|
27
27
|
* @subcategory DTO
|
|
28
28
|
* @property {PasswordConfig} password - The password configuration.
|
|
29
|
+
* @property {EmailConfig} emails - The email configuration.
|
|
30
|
+
* @property {string[]} providers - The enabled third party providers.
|
|
29
31
|
*/
|
|
30
32
|
interface Config {
|
|
31
33
|
password: PasswordConfig;
|
|
32
34
|
emails: EmailConfig;
|
|
35
|
+
providers: string[];
|
|
33
36
|
}
|
|
34
37
|
/**
|
|
35
38
|
* @interface
|
|
@@ -126,12 +129,14 @@ interface Attestation extends PublicKeyCredentialWithAttestationJSON {
|
|
|
126
129
|
* @property {string} address - The email address.
|
|
127
130
|
* @property {boolean} is_verified - Indicates whether the email address is verified.
|
|
128
131
|
* @property {boolean} is_primary - Indicates it's the primary email address.
|
|
132
|
+
* @property {Identity} identity - Indicates that this email is linked to a third party account.
|
|
129
133
|
*/
|
|
130
134
|
interface Email {
|
|
131
135
|
id: string;
|
|
132
136
|
address: string;
|
|
133
137
|
is_verified: boolean;
|
|
134
138
|
is_primary: boolean;
|
|
139
|
+
identity: Identity;
|
|
135
140
|
}
|
|
136
141
|
/**
|
|
137
142
|
* @interface
|
|
@@ -150,6 +155,7 @@ interface Emails extends Array<Email> {
|
|
|
150
155
|
* @property {string} public_key - The public key.
|
|
151
156
|
* @property {string} attestation_type - The attestation type.
|
|
152
157
|
* @property {string} aaguid - The AAGUID of the authenticator.
|
|
158
|
+
* @property {string} last_used_at - The time when the credential was used last.
|
|
153
159
|
* @property {string} created_at - Time of credential creation.
|
|
154
160
|
* @property {WebauthnTransports} transports
|
|
155
161
|
*/
|
|
@@ -159,6 +165,7 @@ interface WebauthnCredential {
|
|
|
159
165
|
public_key: string;
|
|
160
166
|
attestation_type: string;
|
|
161
167
|
aaguid: string;
|
|
168
|
+
last_used_at: string;
|
|
162
169
|
created_at: string;
|
|
163
170
|
transports: WebauthnTransports;
|
|
164
171
|
}
|
|
@@ -170,4 +177,15 @@ interface WebauthnCredential {
|
|
|
170
177
|
*/
|
|
171
178
|
interface WebauthnCredentials extends Array<WebauthnCredential> {
|
|
172
179
|
}
|
|
173
|
-
|
|
180
|
+
/**
|
|
181
|
+
* @interface
|
|
182
|
+
* @category SDK
|
|
183
|
+
* @subcategory DTO
|
|
184
|
+
* @property {id} - The subject ID with the third party provider.
|
|
185
|
+
* @property {provider} - The third party provider name.
|
|
186
|
+
*/
|
|
187
|
+
interface Identity {
|
|
188
|
+
id: string;
|
|
189
|
+
provider: string;
|
|
190
|
+
}
|
|
191
|
+
export type { PasswordConfig, Config, WebauthnFinalized, Credential, UserInfo, Me, User, Email, Emails, Passcode, Attestation, WebauthnCredential, WebauthnCredentials, Identity, };
|
package/dist/lib/Errors.d.ts
CHANGED
|
@@ -168,4 +168,15 @@ declare class MaxNumOfEmailAddressesReachedError extends HankoError {
|
|
|
168
168
|
declare class EmailAddressAlreadyExistsError extends HankoError {
|
|
169
169
|
constructor(cause?: Error);
|
|
170
170
|
}
|
|
171
|
-
|
|
171
|
+
/**
|
|
172
|
+
* A `ThirdPartyError` may occur during a sign in/sign up with a third party
|
|
173
|
+
* provider.
|
|
174
|
+
*
|
|
175
|
+
* @category SDK
|
|
176
|
+
* @subcategory Errors
|
|
177
|
+
* @extends {HankoError}
|
|
178
|
+
*/
|
|
179
|
+
declare class ThirdPartyError extends HankoError {
|
|
180
|
+
constructor(code: string, cause?: Error);
|
|
181
|
+
}
|
|
182
|
+
export { HankoError, TechnicalError, ConflictError, RequestTimeoutError, WebauthnRequestCancelledError, InvalidPasswordError, InvalidPasscodeError, InvalidWebauthnCredentialError, PasscodeExpiredError, MaxNumOfPasscodeAttemptsReachedError, NotFoundError, TooManyRequestsError, UnauthorizedError, UserVerificationError, MaxNumOfEmailAddressesReachedError, EmailAddressAlreadyExistsError, ThirdPartyError, };
|
|
@@ -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
|
*
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Client } from "./Client";
|
|
2
|
+
import { ThirdPartyError } from "../Errors";
|
|
3
|
+
/**
|
|
4
|
+
* A class that handles communication with the Hanko API for the purposes
|
|
5
|
+
* of authenticating through a third party provider.
|
|
6
|
+
*
|
|
7
|
+
* @constructor
|
|
8
|
+
* @category SDK
|
|
9
|
+
* @subcategory Clients
|
|
10
|
+
* @extends {Client}
|
|
11
|
+
*/
|
|
12
|
+
export declare class ThirdPartyClient extends Client {
|
|
13
|
+
constructor(api: string, timeout?: number);
|
|
14
|
+
/**
|
|
15
|
+
* Performs a request to the Hanko API that redirects to the given
|
|
16
|
+
* third party provider.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} provider - The name of the third party provider
|
|
19
|
+
* @param {string} redirectTo - The URL to redirect to after a successful third party authentication
|
|
20
|
+
* @throws {ThirdPartyError}
|
|
21
|
+
* @see http://docs.hanko.io/api/public#tag/Third-Party/operation/thirdPartyAuth
|
|
22
|
+
*/
|
|
23
|
+
auth(provider: string, redirectTo: string): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Get a third party error from the current location's query params.
|
|
26
|
+
* @returns {(ThirdPartyError|undefined)} The ThirdPartyError.
|
|
27
|
+
*/
|
|
28
|
+
getError(): ThirdPartyError;
|
|
29
|
+
}
|
|
@@ -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 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)),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 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),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),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),d=/*#__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 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),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);function O(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 C=function t(e,r){function n(t,n,o){if("undefined"!=typeof document){"number"==typeof(o=O({},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,"",O({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,O({},this.attributes,e))},withConverter:function(e){return t(O({},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}(),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.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}(),A=/*#__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=C.get(s);return new Promise(function(t,u){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://");C.set(s,e,{secure:o})}}t(new x(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}(),R=function(t,e){void 0===e&&(e=13e3),this.client=void 0,this.client=new A(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 c;return t.json()})}catch(t){return Promise.reject(t)}},r}(R),T=/*#__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}(T),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)).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 T.timeToRemainingSeconds(this.getState(t).ttl)},n.setTTL=function(t,e){return this.getState(t).ttl=T.remainingSecondsToTime(e),this},n.getResendAfter=function(t){return T.timeToRemainingSeconds(this.getState(t).resendAfter)},n.setResendAfter=function(t,e){return this.getState(t).resendAfter=T.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 k,n}t(r,e);var n=r.prototype;return n.initialize=function(t,e,r){try{var n=this;n.state.read();var o=n.state.getTTL(t),i=n.state.getActiveID(t),s=n.state.getEmailID(t),a=n.state.getResendAfter(t);if(!r&&o>0&&e===s)return Promise.resolve({id:i,ttl:o});if(a>0)throw new m(a);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 o=r.json();return n.state.setActiveID(t,o.id).setTTL(t,o.ttl),e&&n.state.setEmailID(t,e),n.state.write(),o})}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 d;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}(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 T.timeToRemainingSeconds(this.getState(t).retryAfter)},n.setRetryAfter=function(t,e){return this.getState(t).retryAfter=T.remainingSecondsToTime(e),this},r}(_),D=/*#__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 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=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}(R),N=/*#__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}(R);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 M(t,e,r){if("copy"===e)return r;if("convert"===e)return t(r);if(e instanceof Array)return r.map(r=>M(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]?M(t,i.schema,r[o]):null;else if(i.required)throw new Error(`Missing key: ${o}`)}return n}}function z(t,e){return{required:!0,schema:t,derive:e}}function H(t){return{required:!0,schema:t}}function J(t){return{required:!1,schema:t}}var L={type:H("copy"),id:H("convert"),transports:J("copy")},W={appid:J("copy"),appidExclude:J("copy"),credProps:J("copy")},B={appid:J("copy"),appidExclude:J("copy"),credProps:J("copy")},F={publicKey:H({rp:H("copy"),user:H({id:H("convert"),name:H("copy"),displayName:H("copy")}),challenge:H("convert"),pubKeyCredParams:H("copy"),timeout:J("copy"),excludeCredentials:J([L]),authenticatorSelection:J("copy"),attestation:J("copy"),extensions:J(W)}),signal:J("copy")},V={type:H("copy"),id:H("copy"),rawId:H("convert"),authenticatorAttachment:J("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(B,t=>t.getClientExtensionResults())},X={mediation:J("copy"),publicKey:H({challenge:H("convert"),timeout:J("copy"),rpId:J("copy"),allowCredentials:J([L]),userVerification:J("copy"),extensions:J(W)}),signal:J("copy")},G={type:H("copy"),id:H("copy"),rawId:H("convert"),authenticatorAttachment:J("copy"),response:H({clientDataJSON:H("convert"),authenticatorData:H("convert"),signature:H("convert"),userHandle:H("convert")}),clientExtensionResults:z(B,t=>t.getClientExtensionResults())};async function $(t){const e=await navigator.credentials.create(function(t){return M(q,F,t)}(t));return function(t){return M(K,V,t)}(e)}async function Q(t){const e=await navigator.credentials.get(function(t){return M(q,X,t)}(t));return function(t){return M(K,G,t)}(e)}var Y=/*#__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}(),Z=/*#__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 tt(t,e){try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}var et=/*#__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=Q,n._createCredential=$,n.webauthnState=new Z,n.passcodeState=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("/webauthn/login/initialize",{user_id:t})).then(function(n){function o(e){return Promise.resolve(r.client.post("/webauthn/login/finalize",i)).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 i,s=n.json();s.signal=r._createAbortSignal(),e&&(s.mediation="conditional");var a=tt(function(){return Promise.resolve(r._getCredential(s)).then(function(t){i=t})},function(t){throw new h(t)});return a&&a.then?a.then(o):o()})}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,o=e.json();o.signal=t._createAbortSignal();var i=tt(function(){return Promise.resolve(t._createCredential(o)).then(function(t){n=t})},function(t){throw new h(t)});return i&&i.then?i.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=Y.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),rt=/*#__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}(R);exports.ConfigClient=E,exports.ConflictError=u,exports.EmailAddressAlreadyExistsError=S,exports.EmailClient=rt,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.email=void 0,this.config=new E(t,e),this.user=new N(t,e),this.webauthn=new et(t,e),this.password=new D(t,e),this.passcode=new I(t,e),this.email=new rt(t,e)},exports.HankoError=a,exports.InvalidPasscodeError=d,exports.InvalidPasswordError=f,exports.InvalidWebauthnCredentialError=p,exports.MaxNumOfEmailAddressesReachedError=b,exports.MaxNumOfPasscodeAttemptsReachedError=v,exports.NotFoundError=y,exports.PasscodeClient=I,exports.PasscodeExpiredError=w,exports.PasswordClient=D,exports.RequestTimeoutError=l,exports.TechnicalError=c,exports.TooManyRequestsError=m,exports.UnauthorizedError=g,exports.UserClient=N,exports.UserVerificationError=P,exports.WebauthnClient=et,exports.WebauthnRequestCancelledError=h,exports.WebauthnSupport=Y;
|
|
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
|