@teamhanko/hanko-frontend-sdk 1.0.2 → 1.2.0

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 CHANGED
@@ -8,6 +8,7 @@ import { Relay } from "./lib/events/Relay";
8
8
  import { Session } from "./lib/Session";
9
9
  import { CookieSameSite } from "./lib/Cookie";
10
10
  import { Flow } from "./lib/flow-api/Flow";
11
+ import { SessionClient } from "./lib/client/SessionClient";
11
12
  /**
12
13
  * The options for the Hanko class
13
14
  *
@@ -39,6 +40,7 @@ declare class Hanko extends Listener {
39
40
  thirdParty: ThirdPartyClient;
40
41
  enterprise: EnterpriseClient;
41
42
  token: TokenClient;
43
+ sessionClient: SessionClient;
42
44
  relay: Relay;
43
45
  session: Session;
44
46
  flow: Flow;
package/dist/index.d.ts CHANGED
@@ -5,11 +5,12 @@ import { EmailClient } from "./lib/client/EmailClient";
5
5
  import { ThirdPartyClient } from "./lib/client/ThirdPartyClient";
6
6
  import { TokenClient } from "./lib/client/TokenClient";
7
7
  import { EnterpriseClient } from "./lib/client/EnterpriseClient";
8
- export { UserClient, EmailClient, ThirdPartyClient, TokenClient, EnterpriseClient, };
8
+ import { SessionClient } from "./lib/client/SessionClient";
9
+ export { UserClient, EmailClient, ThirdPartyClient, TokenClient, EnterpriseClient, SessionClient, };
9
10
  import { WebauthnSupport } from "./lib/WebauthnSupport";
10
11
  export { WebauthnSupport };
11
- import { PasswordConfig, EmailConfig, AccountConfig, Config, WebauthnFinalized, TokenFinalized, UserInfo, Me, Credential, User, UserCreated, Passcode, WebauthnTransports, Attestation, Email, Emails, WebauthnCredential, WebauthnCredentials, Identity } from "./lib/Dto";
12
- export type { PasswordConfig, EmailConfig, AccountConfig, Config, WebauthnFinalized, TokenFinalized, UserInfo, Me, Credential, User, UserCreated, Passcode, WebauthnTransports, Attestation, Email, Emails, WebauthnCredential, WebauthnCredentials, Identity, };
12
+ import { PasswordConfig, EmailConfig, AccountConfig, Config, WebauthnFinalized, TokenFinalized, UserInfo, Me, Credential, User, UserCreated, Passcode, WebauthnTransports, Attestation, Email, Emails, WebauthnCredential, WebauthnCredentials, Identity, SessionCheckResponse } from "./lib/Dto";
13
+ export type { PasswordConfig, EmailConfig, AccountConfig, Config, WebauthnFinalized, TokenFinalized, UserInfo, Me, Credential, User, UserCreated, Passcode, WebauthnTransports, Attestation, Email, Emails, WebauthnCredential, WebauthnCredentials, Identity, SessionCheckResponse, };
13
14
  import { HankoError, ConflictError, ForbiddenError, EmailAddressAlreadyExistsError, InvalidPasswordError, InvalidPasscodeError, InvalidWebauthnCredentialError, MaxNumOfEmailAddressesReachedError, MaxNumOfPasscodeAttemptsReachedError, NotFoundError, PasscodeExpiredError, RequestTimeoutError, TechnicalError, ThirdPartyError, TooManyRequestsError, UnauthorizedError, UserVerificationError, WebauthnRequestCancelledError } from "./lib/Errors";
14
15
  export { HankoError, ConflictError, ForbiddenError, EmailAddressAlreadyExistsError, InvalidPasswordError, InvalidPasscodeError, InvalidWebauthnCredentialError, MaxNumOfEmailAddressesReachedError, MaxNumOfPasscodeAttemptsReachedError, NotFoundError, PasscodeExpiredError, RequestTimeoutError, TechnicalError, ThirdPartyError, TooManyRequestsError, UnauthorizedError, UserVerificationError, WebauthnRequestCancelledError, };
15
16
  import { CustomEventWithDetail, SessionDetail, sessionCreatedType, sessionExpiredType, userLoggedOutType, userDeletedType } from "./lib/events/CustomEvents";
package/dist/lib/Dto.d.ts CHANGED
@@ -227,3 +227,7 @@ export interface Identity {
227
227
  id: string;
228
228
  provider: string;
229
229
  }
230
+ export interface SessionCheckResponse {
231
+ is_valid: boolean;
232
+ expiration_time?: string;
233
+ }
@@ -0,0 +1,20 @@
1
+ import { Client } from "./Client";
2
+ import { SessionCheckResponse } from "../Dto";
3
+ /**
4
+ * A class that handles communication with the Hanko API for the purposes
5
+ * of sessions.
6
+ *
7
+ * @constructor
8
+ * @category SDK
9
+ * @subcategory Clients
10
+ * @extends {Client}
11
+ */
12
+ export declare class SessionClient extends Client {
13
+ /**
14
+ * Checks if the current session is still valid.
15
+ *
16
+ * @return {Promise<SessionCheckResponse>}
17
+ * @throws {TechnicalError}
18
+ */
19
+ isValid(): Promise<SessionCheckResponse>;
20
+ }
@@ -2,6 +2,7 @@ import { Client } from "../client/Client";
2
2
  import { State } from "./State";
3
3
  import { Action } from "./types/action";
4
4
  import { FlowPath, Handlers } from "./types/state-handling";
5
+ import { HankoError } from "../Errors";
5
6
  type ExtendedHandlers = Handlers & {
6
7
  onError?: (e: unknown) => any;
7
8
  };
@@ -28,7 +29,7 @@ declare class Flow extends Client {
28
29
  */
29
30
  run: (state: State<any>, handlers: ExtendedHandlers) => Promise<unknown>;
30
31
  }
31
- export declare class HandlerNotFoundError extends Error {
32
+ export declare class HandlerNotFoundError extends HankoError {
32
33
  state: State<any>;
33
34
  constructor(state: State<any>);
34
35
  }
@@ -1,92 +1,118 @@
1
- import { ContinueWithLoginIdentifierInputs, EmailCreateInputs, EmailDeleteInputs, EmailSetPrimaryInputs, EmailVerifyInputs, ExchangeTokenInputs, PasskeyCredentialDelete, PasskeyCredentialRename, PasswordRecoveryInputs, PasswordInputs, RegisterClientCapabilitiesInputs, RegisterLoginIdentifierInputs, RegisterPasswordInputs, ThirdpartyOauthInputs, UsernameSetInputs, VerifyPasscodeInputs, WebauthnVerifyAssertionResponseInputs, WebauthnVerifyAttestationResponseInputs } from "./input";
2
- interface Action<TInputs> {
1
+ import { ContinueWithLoginIdentifierInputs, EmailCreateInputs, EmailDeleteInputs, EmailSetPrimaryInputs, EmailVerifyInputs, ExchangeTokenInputs, PasskeyCredentialDeleteInputs, PasskeyCredentialRenameInputs, PasswordRecoveryInputs, PasswordInputs, RegisterClientCapabilitiesInputs, RegisterLoginIdentifierInputs, RegisterPasswordInputs, ThirdpartyOauthInputs, UsernameSetInputs, VerifyPasscodeInputs, WebauthnVerifyAssertionResponseInputs, WebauthnVerifyAttestationResponseInputs, SessionDeleteInputs, OTPCodeInputs, SecurityKeyDeleteInputs } from "./input";
2
+ export interface Action<TInputs> {
3
3
  name: string;
4
4
  href: string;
5
5
  inputs: TInputs;
6
6
  description: string;
7
7
  }
8
- interface PreflightActions {
8
+ export interface PreflightActions {
9
9
  readonly register_client_capabilities: Action<RegisterClientCapabilitiesInputs>;
10
10
  }
11
- interface LoginInitActions {
11
+ export interface LoginInitActions {
12
12
  readonly continue_with_login_identifier?: Action<ContinueWithLoginIdentifierInputs>;
13
13
  readonly webauthn_generate_request_options?: Action<null>;
14
14
  readonly webauthn_verify_assertion_response?: Action<WebauthnVerifyAssertionResponseInputs>;
15
15
  readonly thirdparty_oauth?: Action<ThirdpartyOauthInputs>;
16
16
  }
17
- interface ProfileInitActions {
17
+ export interface ProfileInitActions {
18
18
  readonly account_delete?: Action<null>;
19
+ readonly continue_to_otp_secret_creation?: Action<null>;
19
20
  readonly email_create?: Action<EmailCreateInputs>;
20
21
  readonly email_delete?: Action<EmailDeleteInputs>;
21
22
  readonly email_verify?: Action<EmailVerifyInputs>;
22
23
  readonly email_set_primary?: Action<EmailSetPrimaryInputs>;
24
+ readonly otp_secret_delete?: Action<null>;
23
25
  readonly password_create?: Action<PasswordInputs>;
24
26
  readonly password_update?: Action<PasswordInputs>;
25
27
  readonly password_delete?: Action<null>;
28
+ readonly security_key_create?: Action<null>;
29
+ readonly security_key_delete?: Action<SecurityKeyDeleteInputs>;
26
30
  readonly username_create?: Action<UsernameSetInputs>;
27
31
  readonly username_delete?: Action<null>;
28
32
  readonly username_update?: Action<UsernameSetInputs>;
29
33
  readonly webauthn_credential_create?: Action<null>;
30
- readonly webauthn_credential_rename?: Action<PasskeyCredentialRename>;
31
- readonly webauthn_credential_delete?: Action<PasskeyCredentialDelete>;
34
+ readonly webauthn_credential_rename?: Action<PasskeyCredentialRenameInputs>;
35
+ readonly webauthn_credential_delete?: Action<PasskeyCredentialDeleteInputs>;
32
36
  readonly webauthn_verify_attestation_response?: Action<WebauthnVerifyAttestationResponseInputs>;
37
+ readonly session_delete?: Action<SessionDeleteInputs>;
33
38
  }
34
- interface LoginMethodChooserActions {
39
+ export interface LoginMethodChooserActions {
35
40
  readonly continue_to_password_login?: Action<null>;
36
41
  readonly continue_to_passcode_confirmation?: Action<null>;
37
42
  readonly back: Action<null>;
38
43
  }
39
- interface LoginPasswordActions {
44
+ export interface LoginOTPActions {
45
+ readonly otp_code_validate: Action<OTPCodeInputs>;
46
+ readonly continue_to_login_security_key?: Action<null>;
47
+ }
48
+ export interface LoginPasswordActions {
40
49
  readonly password_login: Action<PasswordInputs>;
41
50
  readonly continue_to_passcode_confirmation_recovery?: Action<null>;
42
51
  readonly continue_to_login_method_chooser: Action<null>;
43
52
  readonly back: Action<null>;
44
53
  }
45
- interface LoginPasswordRecoveryActions {
54
+ export interface LoginPasswordRecoveryActions {
46
55
  readonly password_recovery: Action<PasswordRecoveryInputs>;
47
56
  }
48
- interface LoginPasskeyActions {
57
+ export interface LoginPasskeyActions {
49
58
  readonly webauthn_verify_assertion_response: Action<WebauthnVerifyAssertionResponseInputs>;
50
59
  readonly back: Action<null>;
51
60
  }
52
- interface OnboardingCreatePasskeyActions {
61
+ export interface LoginSecurityKeyActions {
62
+ readonly webauthn_generate_request_options: Action<null>;
63
+ readonly continue_to_login_otp?: Action<null>;
64
+ }
65
+ export interface MFAMethodChooserActions {
66
+ readonly continue_to_otp_secret_creation?: Action<null>;
67
+ readonly continue_to_security_key_creation?: Action<null>;
68
+ readonly skip?: Action<null>;
69
+ readonly back?: Action<null>;
70
+ }
71
+ export interface MFAAOTPSecretCreationActions {
72
+ readonly otp_code_verify: Action<OTPCodeInputs>;
73
+ readonly back: Action<null>;
74
+ }
75
+ export interface MFASecurityKeyCreationActions {
76
+ readonly webauthn_generate_creation_options: Action<null>;
77
+ readonly back: Action<null>;
78
+ }
79
+ export interface OnboardingCreatePasskeyActions {
53
80
  readonly webauthn_generate_creation_options: Action<null>;
54
81
  readonly skip?: Action<null>;
55
82
  readonly back?: Action<null>;
56
83
  }
57
- interface OnboardingVerifyPasskeyAttestationActions {
84
+ export interface OnboardingVerifyPasskeyAttestationActions {
58
85
  readonly webauthn_verify_attestation_response: Action<WebauthnVerifyAttestationResponseInputs>;
59
86
  readonly back: Action<null>;
60
87
  }
61
- interface RegistrationInitActions {
88
+ export interface RegistrationInitActions {
62
89
  readonly register_login_identifier: Action<RegisterLoginIdentifierInputs>;
63
90
  readonly thirdparty_oauth?: Action<ThirdpartyOauthInputs>;
64
91
  }
65
- interface PasswordCreationActions {
92
+ export interface PasswordCreationActions {
66
93
  readonly register_password: Action<RegisterPasswordInputs>;
67
94
  readonly back?: Action<null>;
68
95
  readonly skip?: Action<null>;
69
96
  }
70
- interface PasscodeConfirmationActions {
97
+ export interface PasscodeConfirmationActions {
71
98
  readonly verify_passcode: Action<VerifyPasscodeInputs>;
72
99
  readonly resend_passcode: Action<null>;
73
100
  readonly back: Action<null>;
74
101
  }
75
- interface OnboardingEmailActions {
102
+ export interface OnboardingEmailActions {
76
103
  readonly email_address_set: Action<EmailCreateInputs>;
77
104
  readonly skip: Action<null>;
78
105
  }
79
- interface OnboardingUsernameActions {
106
+ export interface OnboardingUsernameActions {
80
107
  readonly username_create: Action<UsernameSetInputs>;
81
108
  readonly skip: Action<null>;
82
109
  }
83
- interface CredentialOnboardingChooserActions {
110
+ export interface CredentialOnboardingChooserActions {
84
111
  readonly continue_to_passkey_registration: Action<null>;
85
112
  readonly continue_to_password_registration: Action<null>;
86
113
  readonly skip: Action<null>;
87
114
  readonly back: Action<null>;
88
115
  }
89
- interface ThirdPartyActions {
116
+ export interface ThirdPartyActions {
90
117
  readonly exchange_token: Action<ExchangeTokenInputs>;
91
118
  }
92
- export type { Action, PreflightActions, LoginInitActions, ProfileInitActions, LoginMethodChooserActions, LoginPasswordActions, LoginPasswordRecoveryActions, LoginPasskeyActions, OnboardingCreatePasskeyActions, OnboardingVerifyPasskeyAttestationActions, RegistrationInitActions, PasswordCreationActions, PasscodeConfirmationActions, OnboardingEmailActions, OnboardingUsernameActions, CredentialOnboardingChooserActions, ThirdPartyActions, };
@@ -34,6 +34,7 @@ export interface RegisterPasswordInputs {
34
34
  export interface RegisterClientCapabilitiesInputs {
35
35
  readonly webauthn_available: Input<boolean>;
36
36
  readonly webauthn_conditional_mediation_available: Input<boolean>;
37
+ readonly webauthn_platform_authenticator_available: Input<boolean>;
37
38
  }
38
39
  export interface ContinueWithLoginIdentifierInputs {
39
40
  readonly identifier?: Input<string>;
@@ -61,11 +62,14 @@ export interface PasswordInputs {
61
62
  export interface UsernameSetInputs {
62
63
  readonly username: Input<string>;
63
64
  }
64
- export interface PasskeyCredentialRename {
65
+ export interface SecurityKeyDeleteInputs {
66
+ readonly security_key_id: Input<string>;
67
+ }
68
+ export interface PasskeyCredentialRenameInputs {
65
69
  readonly passkey_id: Input<string>;
66
70
  readonly passkey_name: Input<string>;
67
71
  }
68
- export interface PasskeyCredentialDelete {
72
+ export interface PasskeyCredentialDeleteInputs {
69
73
  readonly passkey_id: Input<string>;
70
74
  }
71
75
  export interface ExchangeTokenInputs {
@@ -75,3 +79,9 @@ export interface ThirdpartyOauthInputs {
75
79
  readonly provider: Input<string>;
76
80
  readonly redirect_to: Input<string>;
77
81
  }
82
+ export interface SessionDeleteInputs {
83
+ readonly session_id: Input<string>;
84
+ }
85
+ export interface OTPCodeInputs {
86
+ readonly otp_code: Input<string>;
87
+ }
@@ -6,13 +6,17 @@ export interface PasscodeConfirmationPayload {
6
6
  export interface LoginPasskeyPayload {
7
7
  readonly request_options: CredentialRequestOptionsJSON;
8
8
  }
9
+ export interface MFAOTPSecretCreationPayload {
10
+ readonly otp_secret: string;
11
+ readonly otp_image_source: string;
12
+ }
9
13
  export interface OnboardingVerifyPasskeyAttestationPayload {
10
14
  readonly creation_options: CredentialCreationOptionsJSON;
11
15
  }
12
16
  export interface LoginInitPayload {
13
17
  readonly request_options?: CredentialRequestOptionsJSON;
14
18
  }
15
- export interface Passkey {
19
+ export interface WebauthnCredential {
16
20
  readonly id: string;
17
21
  readonly name?: string;
18
22
  readonly public_key: string;
@@ -41,19 +45,44 @@ export interface Email {
41
45
  readonly is_primary: boolean;
42
46
  readonly identities?: Identity[];
43
47
  }
48
+ export interface MFAConfig {
49
+ readonly auth_app_set_up: boolean;
50
+ readonly totp_enabled: boolean;
51
+ readonly security_keys_enabled: boolean;
52
+ }
44
53
  export interface User {
45
54
  readonly user_id: string;
46
- readonly passkeys?: Passkey[];
55
+ readonly passkeys?: WebauthnCredential[];
56
+ readonly security_keys?: WebauthnCredential[];
57
+ readonly mfa_config?: MFAConfig;
47
58
  readonly emails?: Email[];
48
59
  readonly username?: Username;
49
60
  readonly created_at: string;
50
61
  readonly updated_at: string;
51
62
  }
63
+ export interface Session {
64
+ readonly id: string;
65
+ readonly user_agent: string;
66
+ readonly user_agent_raw: string;
67
+ readonly ip_address: string;
68
+ readonly created_at: string;
69
+ readonly last_used: string;
70
+ readonly current: boolean;
71
+ }
52
72
  export interface ProfilePayload {
53
73
  readonly user: User;
74
+ readonly sessions?: Session[];
75
+ }
76
+ export type LoginMethod = "password" | "passkey" | "passcode" | "third_party";
77
+ export type MFAMethod = "totp" | "security_key";
78
+ export interface LastLogin {
79
+ readonly login_method: LoginMethod;
80
+ readonly mfa_method?: MFAMethod;
81
+ readonly third_party_provider?: string;
54
82
  }
55
83
  export interface SuccessPayload {
56
84
  readonly user: User;
85
+ readonly last_login?: LastLogin;
57
86
  }
58
87
  export interface ThirdPartyPayload {
59
88
  readonly redirect_url: string;
@@ -1,16 +1,21 @@
1
1
  import { State } from "../State";
2
- import { CredentialOnboardingChooserActions, LoginInitActions, LoginMethodChooserActions, LoginPasskeyActions, LoginPasswordActions, LoginPasswordRecoveryActions, OnboardingCreatePasskeyActions, OnboardingEmailActions, OnboardingUsernameActions, OnboardingVerifyPasskeyAttestationActions, PasscodeConfirmationActions, PasswordCreationActions, PreflightActions, ProfileInitActions, RegistrationInitActions, ThirdPartyActions } from "./action";
3
- import { LoginInitPayload, LoginPasskeyPayload, OnboardingVerifyPasskeyAttestationPayload, PasscodeConfirmationPayload, ProfilePayload, SuccessPayload, ThirdPartyPayload } from "./payload";
4
- export type StateName = "account_deleted" | "credential_onboarding_chooser" | "error" | "login_init" | "login_method_chooser" | "login_passkey" | "login_password" | "login_password_recovery" | "onboarding_create_passkey" | "onboarding_email" | "onboarding_username" | "onboarding_verify_passkey_attestation" | "passcode_confirmation" | "password_creation" | "preflight" | "profile_init" | "registration_init" | "success" | "thirdparty" | "webauthn_credential_verification";
2
+ import { CredentialOnboardingChooserActions, LoginInitActions, LoginMethodChooserActions, LoginOTPActions, LoginPasskeyActions, LoginPasswordActions, LoginPasswordRecoveryActions, LoginSecurityKeyActions, MFAAOTPSecretCreationActions, MFAMethodChooserActions, MFASecurityKeyCreationActions, OnboardingCreatePasskeyActions, OnboardingEmailActions, OnboardingUsernameActions, OnboardingVerifyPasskeyAttestationActions, PasscodeConfirmationActions, PasswordCreationActions, PreflightActions, ProfileInitActions, RegistrationInitActions, ThirdPartyActions } from "./action";
3
+ import { LoginInitPayload, LoginPasskeyPayload, MFAOTPSecretCreationPayload, OnboardingVerifyPasskeyAttestationPayload, PasscodeConfirmationPayload, ProfilePayload, SuccessPayload, ThirdPartyPayload } from "./payload";
4
+ export type StateName = "account_deleted" | "credential_onboarding_chooser" | "error" | "login_init" | "login_method_chooser" | "login_otp" | "login_passkey" | "login_password" | "login_password_recovery" | "login_security_key" | "mfa_method_chooser" | "mfa_otp_secret_creation" | "mfa_security_key_creation" | "onboarding_create_passkey" | "onboarding_email" | "onboarding_username" | "onboarding_verify_passkey_attestation" | "passcode_confirmation" | "password_creation" | "preflight" | "profile_init" | "registration_init" | "success" | "thirdparty" | "webauthn_credential_verification";
5
5
  export interface Actions {
6
6
  readonly account_deleted: null;
7
7
  readonly credential_onboarding_chooser: CredentialOnboardingChooserActions;
8
8
  readonly error: null;
9
9
  readonly login_init: LoginInitActions;
10
10
  readonly login_method_chooser: LoginMethodChooserActions;
11
+ readonly login_otp: LoginOTPActions;
11
12
  readonly login_passkey: LoginPasskeyActions;
12
13
  readonly login_password: LoginPasswordActions;
13
14
  readonly login_password_recovery: LoginPasswordRecoveryActions;
15
+ readonly login_security_key: LoginSecurityKeyActions;
16
+ readonly mfa_method_chooser: MFAMethodChooserActions;
17
+ readonly mfa_otp_secret_creation: MFAAOTPSecretCreationActions;
18
+ readonly mfa_security_key_creation: MFASecurityKeyCreationActions;
14
19
  readonly onboarding_create_passkey: OnboardingCreatePasskeyActions;
15
20
  readonly onboarding_email: OnboardingEmailActions;
16
21
  readonly onboarding_username: OnboardingUsernameActions;
@@ -30,9 +35,14 @@ export interface Payloads {
30
35
  readonly error: null;
31
36
  readonly login_init: LoginInitPayload;
32
37
  readonly login_method_chooser: null;
38
+ readonly login_otp: null;
33
39
  readonly login_passkey: LoginPasskeyPayload;
34
40
  readonly login_password: null;
35
41
  readonly login_password_recovery: null;
42
+ readonly login_security_key: null;
43
+ readonly mfa_method_chooser: null;
44
+ readonly mfa_otp_secret_creation: MFAOTPSecretCreationPayload;
45
+ readonly mfa_security_key_creation: null;
36
46
  readonly onboarding_create_passkey: null;
37
47
  readonly onboarding_email: null;
38
48
  readonly onboarding_username: null;
package/dist/sdk.cjs CHANGED
@@ -1,2 +1,2 @@
1
- function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},e.apply(this,arguments)}function t(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,r(e,t)}function n(e){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},n(e)}function r(e,t){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},r(e,t)}function i(e,t,n){return i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}()?Reflect.construct.bind():function(e,t,n){var i=[null];i.push.apply(i,t);var o=new(Function.bind.apply(e,i));return n&&r(o,n.prototype),o},i.apply(null,arguments)}function o(e){var t="function"==typeof Map?new Map:void 0;return o=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,o)}function o(){return i(e,arguments,n(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),r(o,e)},o(e)}function s(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var a=0;function u(e){return"__private_"+a+++"_"+e}function c(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var h=/*#__PURE__*/function(e){function n(t,r,i){var o;return(o=e.call(this,t)||this).code=void 0,o.cause=void 0,o.code=r,o.cause=i,Object.setPrototypeOf(s(o),n.prototype),o}return t(n,e),n}(/*#__PURE__*/o(Error)),l=/*#__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}(h),d=/*#__PURE__*/function(e){function n(t,r){var i;return i=e.call(this,"Conflict error","conflict",r)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),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}(h),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}(h),v=/*#__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}(h),m=/*#__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}(h),w=/*#__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}(h),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}(h),g=/*#__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}(h),E=/*#__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}(h),P=/*#__PURE__*/function(e){function n(t,r){var i;return(i=e.call(this,"Too many requests error","tooManyRequests",r)||this).retryAfter=void 0,i.retryAfter=t,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),k=/*#__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}(h),x=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Forbidden error","forbidden",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),S=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"User verification error","userVerification",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),b=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Maximum number of email addresses reached error","maxNumOfEmailAddressesReached",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),_=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"The email address already exists","emailAddressAlreadyExistsError",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),O=/*#__PURE__*/function(e){function n(t,r){var i;return i=e.call(this,"An error occurred during third party sign up/sign in",t,r)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),C=/*#__PURE__*/function(){function e(e){this.key=void 0,this.ls=void 0,this.key=e,this.ls={}}var t=e.prototype;return t.read=function(){var e;try{var t=localStorage.getItem(this.key),n=decodeURIComponent(decodeURI(window.atob(t)));e=JSON.parse(n)}catch(e){return this.ls={},this}return this.ls=e,this},t.write=function(){var e=JSON.stringify(this.ls),t=window.btoa(encodeURI(encodeURIComponent(e)));return localStorage.setItem(this.key,t),this},e.timeToRemainingSeconds=function(e){return void 0===e&&(e=0),e-Math.floor(Date.now()/1e3)},e.remainingSecondsToTime=function(e){return void 0===e&&(e=0),Math.floor(Date.now()/1e3)+e},e}(),j=/*#__PURE__*/function(e){function n(t){return e.call(this,t.localStorageKey+"_session")||this}t(n,e);var r=n.prototype;return r.read=function(){return e.prototype.read.call(this),this},r.getState=function(){var e;return(e=this.ls).session||(e.session={expiry:0,authFlowCompleted:!1}),this.ls.session},r.getExpirationSeconds=function(){return C.timeToRemainingSeconds(this.getState().expiry)},r.setExpirationSeconds=function(e){return this.getState().expiry=C.remainingSecondsToTime(e),this},r.getAuthFlowCompleted=function(){return this.getState().authFlowCompleted},r.setAuthFlowCompleted=function(e){return this.getState().authFlowCompleted=e,this},r.reset=function(){return delete this.getState().expiry,this},n}(C),A="hanko-session-created",T="hanko-session-expired",R="hanko-user-logged-out",N="hanko-user-deleted",D=/*#__PURE__*/function(e){function n(t,n){return e.call(this,t,{detail:n})||this}return t(n,e),n}(/*#__PURE__*/o(CustomEvent)),L=/*#__PURE__*/function(){function t(t){this._dispatchEvent=document.dispatchEvent.bind(document),this._sessionState=void 0,this._sessionState=new j(e({},t))}var n=t.prototype;return n.dispatch=function(e,t){this._dispatchEvent(new D(e,t))},n.dispatchSessionCreatedEvent=function(e){this.dispatch(A,e)},n.dispatchSessionExpiredEvent=function(){this.dispatch(T,null)},n.dispatchUserLoggedOutEvent=function(){this.dispatch(R,null)},n.dispatchUserDeletedEvent=function(){this.dispatch(N,null)},t}();function U(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}var W,I=function e(t,n){function r(e,r,i){if("undefined"!=typeof document){"number"==typeof(i=U({},n,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var o="";for(var s in i)i[s]&&(o+="; "+s,!0!==i[s]&&(o+="="+i[s].split(";")[0]));return document.cookie=e+"="+t.write(r,e)+o}}return Object.create({set:r,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var n=document.cookie?document.cookie.split("; "):[],r={},i=0;i<n.length;i++){var o=n[i].split("="),s=o.slice(1).join("=");try{var a=decodeURIComponent(o[0]);if(r[a]=t.read(s,a),e===a)break}catch(e){}}return e?r[e]:r}},remove:function(e,t){r(e,"",U({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,U({},this.attributes,t))},withConverter:function(t){return e(U({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"}),q=/*#__PURE__*/function(){function t(e){var t;this.authCookieName=void 0,this.authCookieDomain=void 0,this.authCookieSameSite=void 0,this.authCookieName=e.cookieName,this.authCookieDomain=e.cookieDomain,this.authCookieSameSite=null!=(t=e.cookieSameSite)?t:"lax"}var n=t.prototype;return n.getAuthCookie=function(){return I.get(this.authCookieName)},n.setAuthCookie=function(t,n){var r={secure:!0,sameSite:this.authCookieSameSite};void 0!==this.authCookieDomain&&(r.domain=this.authCookieDomain);var i=e({},r,n);if(("none"===i.sameSite||"None"===i.sameSite)&&!1===i.secure)throw new l(new Error("Secure attribute must be set when SameSite=None"));I.set(this.authCookieName,t,i)},n.removeAuthCookie=function(){I.remove(this.authCookieName)},t}(),M=/*#__PURE__*/function(){function e(e){this._xhr=void 0,this._xhr=e}return e.prototype.getResponseHeader=function(e){return this._xhr.getResponseHeader(e)},e}(),F=/*#__PURE__*/function(){function e(e){this.headers=void 0,this.ok=void 0,this.status=void 0,this.statusText=void 0,this.url=void 0,this._decodedJSON=void 0,this.xhr=void 0,this.headers=new M(e),this.ok=e.status>=200&&e.status<=299,this.status=e.status,this.statusText=e.statusText,this.url=e.responseURL,this.xhr=e}var t=e.prototype;return t.json=function(){return this._decodedJSON||(this._decodedJSON=JSON.parse(this.xhr.response)),this._decodedJSON},t.parseNumericHeader=function(e){var t=parseInt(this.headers.getResponseHeader(e),10);return isNaN(t)?0:t},e}(),K=/*#__PURE__*/function(){function t(t,n){this.timeout=void 0,this.api=void 0,this.sessionState=void 0,this.dispatcher=void 0,this.cookie=void 0,this.api=t,this.timeout=n.timeout,this.sessionState=new j(e({},n)),this.dispatcher=new L(e({},n)),this.cookie=new q(e({},n))}var n=t.prototype;return n._fetch=function(e,t,n){void 0===n&&(n=new XMLHttpRequest);var r=this,i=this.api+e,o=this.timeout,s=this.cookie.getAuthCookie();return new Promise(function(e,a){n.open(t.method,i,!0),n.setRequestHeader("Accept","application/json"),n.setRequestHeader("Content-Type","application/json"),s&&n.setRequestHeader("Authorization","Bearer "+s),n.timeout=o,n.withCredentials=!0,n.onload=function(){r.processHeaders(n),e(new F(n))},n.onerror=function(){a(new l)},n.ontimeout=function(){a(new f)},n.send(t.body?t.body.toString():null)})},n.processHeaders=function(e){var t="",n=0;if(e.getAllResponseHeaders().split("\r\n").forEach(function(r){var i=r.toLowerCase();i.startsWith("x-auth-token")?t=e.getResponseHeader("X-Auth-Token"):i.startsWith("x-session-lifetime")&&(n=parseInt(e.getResponseHeader("X-Session-Lifetime"),10))}),t){var r=new RegExp("^https://"),i=!!this.api.match(r)&&!!window.location.href.match(r),o=new Date((new Date).getTime()+1e3*n);this.cookie.setAuthCookie(t,{secure:i,expires:o})}n>0&&(this.sessionState.read(),this.sessionState.setExpirationSeconds(n),this.sessionState.setAuthFlowCompleted(!1),this.sessionState.write())},n.get=function(e){return this._fetch(e,{method:"GET"})},n.post=function(e,t){return this._fetch(e,{method:"POST",body:JSON.stringify(t)})},n.put=function(e,t){return this._fetch(e,{method:"PUT",body:JSON.stringify(t)})},n.patch=function(e,t){return this._fetch(e,{method:"PATCH",body:JSON.stringify(t)})},n.delete=function(e){return this._fetch(e,{method:"DELETE"})},t}(),H=function(e,t){this.client=void 0,this.client=new K(e,t)},J=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var r=n.prototype;return r.getDomain=function(e){if(!e)throw new O("somethingWentWrong",new Error("email missing from request"));var t=e.split("@");if(2!==t.length)throw new O("somethingWentWrong",new Error("email is not in a valid email format."));var n=t[1].trim();if(""===n)throw new O("somethingWentWrong",new Error("email is not in a valid email format."));return n},r.hasProvider=function(e){try{var t=this.getDomain(e);return Promise.resolve(this.client.get("/saml/provider?domain="+t).then(function(e){if(404==e.status)throw new E(new Error("provider not found"));if(!e.ok)throw new l(new Error("unable to fetch provider"));return e.ok}))}catch(e){return Promise.reject(e)}},r.auth=function(e,t){var n=new URL("/saml/auth",this.client.api),r=this.getDomain(e);if(!t)throw new O("somethingWentWrong",new Error("redirectTo missing from request"));n.searchParams.append("domain",r),n.searchParams.append("redirect_to",t),window.location.assign(n.href)},r.getError=function(){var e=new URLSearchParams(window.location.search),t=e.get("error"),n=e.get("error_description");if(t){var r;switch(t){case"access_denied":r="enterpriseAccessDenied";break;case"user_conflict":r="emailAddressAlreadyExistsError";break;case"multiple_accounts":r="enterpriseMultipleAccounts";break;case"unverified_email":r="enterpriseUnverifiedEmail";break;case"email_maxnum":r="maxNumOfEmailAddressesReached";break;default:r="somethingWentWrong"}return new O(r,new Error(n))}},n}(H),B=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var r=n.prototype;return r.getInfo=function(e){try{return Promise.resolve(this.client.post("/user",{email:e})).then(function(e){if(404===e.status)throw new E;if(!e.ok)throw new l;return e.json()})}catch(e){return Promise.reject(e)}},r.create=function(e){try{return Promise.resolve(this.client.post("/users",{email:e})).then(function(e){if(409===e.status)throw new d;if(403===e.status)throw new x;if(!e.ok)throw new l;return e.json()})}catch(e){return Promise.reject(e)}},r.getCurrent=function(){try{var e=this;return Promise.resolve(e.client.get("/me")).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new k;if(!t.ok)throw new l;var n=t.json();return Promise.resolve(e.client.get("/users/"+n.id)).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new k;if(!t.ok)throw new l;return t.json()})})}catch(e){return Promise.reject(e)}},r.delete=function(){try{var e=this;return Promise.resolve(e.client.delete("/user")).then(function(t){if(t.ok)return e.client.cookie.removeAuthCookie(),e.client.sessionState.reset().write(),void e.client.dispatcher.dispatchUserDeletedEvent();if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new k;throw new l})}catch(e){return Promise.reject(e)}},r.logout=function(){try{var e=this;return Promise.resolve(e.client.post("/logout")).then(function(t){if(e.client.cookie.removeAuthCookie(),e.client.sessionState.reset().write(),e.client.dispatcher.dispatchUserLoggedOutEvent(),401===t.status);else if(!t.ok)throw new l})}catch(e){return Promise.reject(e)}},n}(H),V=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var r=n.prototype;return r.list=function(){try{var e=this;return Promise.resolve(e.client.get("/emails")).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new k;if(!t.ok)throw new l;return t.json()})}catch(e){return Promise.reject(e)}},r.create=function(e){try{var t=this;return Promise.resolve(t.client.post("/emails",{address:e})).then(function(e){if(e.ok)return e.json();if(400===e.status)throw new _;if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new k;if(409===e.status)throw new b;throw new l})}catch(e){return Promise.reject(e)}},r.setPrimaryEmail=function(e){try{var t=this;return Promise.resolve(t.client.post("/emails/"+e+"/set_primary")).then(function(e){if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new k;if(!e.ok)throw new l})}catch(e){return Promise.reject(e)}},r.delete=function(e){try{var t=this;return Promise.resolve(t.client.delete("/emails/"+e)).then(function(e){if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new k;if(!e.ok)throw new l})}catch(e){return Promise.reject(e)}},n}(H),z=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var r=n.prototype;return r.auth=function(e,t){try{var n=new URL("/thirdparty/auth",this.client.api);if(!e)throw new O("somethingWentWrong",new Error("provider missing from request"));if(!t)throw new O("somethingWentWrong",new Error("redirectTo missing from request"));return n.searchParams.append("provider",e),n.searchParams.append("redirect_to",t),window.location.assign(n.href),Promise.resolve()}catch(e){return Promise.reject(e)}},r.getError=function(){var e=new URLSearchParams(window.location.search),t=e.get("error"),n=e.get("error_description");if(t){var r="";switch(t){case"access_denied":r="thirdPartyAccessDenied";break;case"user_conflict":r="emailAddressAlreadyExistsError";break;case"multiple_accounts":r="thirdPartyMultipleAccounts";break;case"unverified_email":r="thirdPartyUnverifiedEmail";break;case"email_maxnum":r="maxNumOfEmailAddressesReached";break;case"signup_disabled":r="signupDisabled";break;default:r="somethingWentWrong"}return new O(r,new Error(n))}},n}(H),X=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n.prototype.validate=function(){try{var e=new URLSearchParams(window.location.search).get("hanko_token");return e?(window.history.replaceState(null,null,window.location.pathname),Promise.resolve(this.client.post("/token",{value:e})).then(function(e){if(!e.ok)throw new l;return e.json()})):Promise.resolve()}catch(e){return Promise.reject(e)}},n}(H),G=/*#__PURE__*/function(){function e(){}return e.throttle=function(e,t,n){void 0===n&&(n={});var r,i,o,s=n.leading,a=void 0===s||s,u=n.trailing,c=void 0===u||u,h=0,l=function(){h=!1===a?0:Date.now(),o=null,e.apply(r,i)};return function(){var n=Date.now();h||!1!==a||(h=n);var s=t-(n-h);r=this,i=[].slice.call(arguments),s<=0||s>t?(o&&(window.clearTimeout(o),o=null),h=n,e.apply(r,i)):o||!1===c||(o=window.setTimeout(l,s))}},e}(),Q=/*#__PURE__*/function(){function e(){this.throttleLimit=1e3,this._addEventListener=document.addEventListener.bind(document),this._removeEventListener=document.removeEventListener.bind(document),this._throttle=G.throttle}var t=e.prototype;return t.wrapCallback=function(e,t){var n=function(t){e(t.detail)};return t?this._throttle(n,this.throttleLimit,{leading:!0,trailing:!1}):n},t.addEventListenerWithType=function(e){var t=this,n=e.type,r=e.once,i=void 0!==r&&r,o=e.throttle,s=this.wrapCallback(e.callback,void 0!==o&&o);return this._addEventListener(n,s,{once:i}),function(){return t._removeEventListener(n,s)}},e.mapAddEventListenerParams=function(e,t,n){return{type:e,callback:t.callback,once:t.once,throttle:n}},t.addEventListener=function(t,n,r){return this.addEventListenerWithType(e.mapAddEventListenerParams(t,n,r))},t.onSessionCreated=function(e,t){return this.addEventListener(A,{callback:e,once:t},!0)},t.onSessionExpired=function(e,t){return this.addEventListener(T,{callback:e,once:t},!0)},t.onUserLoggedOut=function(e,t){return this.addEventListener(R,{callback:e,once:t})},t.onUserDeleted=function(e,t){return this.addEventListener(N,{callback:e,once:t})},e}(),Y=/*#__PURE__*/function(){function e(){this._tasks=[]}var t=e.prototype;return t.removeTask=function(e){window.clearTimeout(e.timeoutID),this._tasks=this._tasks.filter(function(t){return t!==e})},t.removeTasksWithType=function(e){var t=this;this._tasks.filter(function(t){return t.type===e}).forEach(function(e){return t.removeTask(e)})},t.scheduleTask=function(e,t,n){var r=this,i={timeoutID:window.setTimeout(function(){t(),r.removeTask(i)},1e3*n),type:e,func:t};this._tasks.push(i)},e}(),Z=/*#__PURE__*/function(){function t(t){this._sessionState=void 0,this._cookie=void 0,this._sessionState=new j(e({},t)),this._cookie=new q(e({},t))}var n=t.prototype;return n.get=function(){var e=this._get();return t.validate(e)?e:null},n.isValid=function(){var e=this._get();return t.validate(e)},n._get=function(){return this._sessionState.read(),{expirationSeconds:this._sessionState.getExpirationSeconds(),jwt:this._cookie.getAuthCookie()}},n.isAuthFlowCompleted=function(){return this._sessionState.read(),this._sessionState.getAuthFlowCompleted()},t.validate=function(e){return e.expirationSeconds>0},t}(),$=/*#__PURE__*/function(n){function r(t){var r;return(r=n.call(this,e({},t))||this)._listener=new Q,r._scheduler=new Y,r._session=void 0,r.scheduleSessionExpiredEvent=function(e){r._scheduler.removeTasksWithType(T),r._scheduler.scheduleTask(T,function(){return r.dispatchSessionExpiredEvent()},e.expirationSeconds)},r.cancelSessionExpiredEvent=function(){r._scheduler.removeTasksWithType(T)},r.handleStorageEvent=function(e){if("hanko_session"===e.key){var t=r._session.get();t?r.dispatchSessionCreatedEvent(t):r.dispatchSessionExpiredEvent()}},r._session=new Z(e({},t)),r.listenEventDependencies(),r}return t(r,n),r.prototype.listenEventDependencies=function(){this._listener.onSessionCreated(this.scheduleSessionExpiredEvent),this._listener.onSessionExpired(this.cancelSessionExpiredEvent),this._listener.onUserDeleted(this.cancelSessionExpiredEvent),this._listener.onUserLoggedOut(this.cancelSessionExpiredEvent),window.addEventListener("storage",this.handleStorageEvent);var e=this._session.get();e&&this.scheduleSessionExpiredEvent(e)},r}(L),ee=/*#__PURE__*/u("actionDefinitions"),te=/*#__PURE__*/u("createActionsProxy"),ne=/*#__PURE__*/function(){var e=t.prototype;function t(e,t){var n=e.name,r=e.payload,i=e.error,o=e.status,s=e.actions,a=e.csrf_token;Object.defineProperty(this,te,{value:re}),this.name=void 0,this.payload=void 0,this.error=void 0,this.status=void 0,this.csrf_token=void 0,Object.defineProperty(this,ee,{writable:!0,value:void 0}),this.actions=void 0,this.fetchNextState=void 0,this.name=n,this.payload=r,this.error=i,this.status=o,this.csrf_token=a,c(this,ee)[ee]=s,this.actions=c(this,te)[te](s,a),this.fetchNextState=t}return e.toJSON=function(){return{name:this.name,payload:this.payload,error:this.error,status:this.status,csrf_token:this.csrf_token,actions:c(this,ee)[ee]}},e.runAction=function(e,t){var n={};if("inputs"in e&&"object"==typeof e.inputs&&null!==e.inputs){var r=e.inputs;for(var i in e.inputs){var o=r[i];o&&"value"in o&&(n[i]=o.value)}}return this.fetchNextState(e.href,{input_data:n,csrf_token:t})},e.validateAction=function(e){if("inputs"in e){var t=function(t){var n=e.inputs[t];function r(e,n,r,i){throw new ie({reason:e,inputName:t,wanted:r,actual:i,message:n})}var i=n.value;n.required&&!i&&r(W.Required,"is required"),(null!=n.min_length||null!=n.max_length)&&("length"in i||r(W.InvalidInputDefinition,'has min/max length requirement, but is missing "length" property',"string",typeof i),null!=n.min_length&&i<n.min_length&&r(W.MinLength,"too short (min "+n.min_length+")",n.min_length,i.length),null!=n.max_length&&i>n.max_length&&r(W.MaxLength,"too long (max "+n.max_length+")",n.max_length,i.length))};for(var n in e.inputs)t(n)}},t}();function re(e,t){var n=this,r=function(e){return n.validateAction(e)};return new Proxy(e,{get:function(e,i){if("symbol"==typeof i)return e[i];var o=e[i];return null==o?null:function(e){var i=Object.assign(JSON.parse(JSON.stringify(o)),{validate:function(){return r(i),i},tryValidate:function(){try{r(i)}catch(e){if(e instanceof ie)return e;throw e}},run:function(){return function(e){return n.runAction(e,t)}(i)}});if(null!==i&&"object"==typeof i&&"inputs"in i)for(var s in e){var a=i.inputs;a[s]||(a[s]={name:s,type:""}),a[s].value=e[s]}return i}}})}!function(e){e[e.InvalidInputDefinition=0]="InvalidInputDefinition",e[e.MinLength=1]="MinLength",e[e.MaxLength=2]="MaxLength",e[e.Required=3]="Required"}(W||(W={}));var ie=/*#__PURE__*/function(e){function n(t){var n;return(n=e.call(this,'"'+t.inputName+'" '+t.message)||this).reason=void 0,n.inputName=void 0,n.wanted=void 0,n.actual=void 0,n.name="ValidationError",n.reason=t.reason,n.inputName=t.inputName,n.wanted=t.wanted,n.actual=t.actual,n}return t(n,e),n}(/*#__PURE__*/o(Error));function oe(e){return"object"==typeof e&&null!==e&&"status"in e&&"error"in e&&"name"in e&&Boolean(e.name)&&Boolean(e.status)}function se(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var ae=/*#__PURE__*/function(e){function n(){for(var t,n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];return(t=e.call.apply(e,[this].concat(r))||this).run=function(e,n){try{return Promise.resolve(se(function(){if(!oe(e))throw new ce(e);var r=n[e.name];if(!r)throw new ue(e);return Promise.resolve(r(e)).then(function(e){function r(){if(oe(e))return t.run(e,n)}var i=function(){if("object"==typeof(t=e)&&null!==t&&"href"in t&&"inputs"in t)return Promise.resolve(e.run()).then(function(t){e=t});var t}();return i&&i.then?i.then(r):r()})},function(e){if("function"==typeof n.onError)return n.onError(e)}))}catch(e){return Promise.reject(e)}},t}t(n,e);var r=n.prototype;return r.init=function(e,t){var n=this;return Promise.resolve(function e(r,i){try{return Promise.resolve(se(function(){return Promise.resolve(n.client.post(r,i)).then(function(t){return new ne(t.json(),e)})},function(e){null==t.onError||t.onError(e)}))}catch(e){return Promise.reject(e)}}(e)).then(function(e){return Promise.resolve(n.run(e,t)).then(function(){})})},r.fromString=function(e,t){try{var n=this,r=new ne(JSON.parse(e),function e(r,i){try{return Promise.resolve(se(function(){return Promise.resolve(n.client.post(r,i)).then(function(t){return new ne(t.json(),e)})},function(e){null==t.onError||t.onError(e)}))}catch(e){return Promise.reject(e)}});return Promise.resolve(n.run(r,t)).then(function(){})}catch(e){return Promise.reject(e)}},n}(H),ue=/*#__PURE__*/function(e){function n(t){var n;return(n=e.call(this,"No handler found for state: "+("string"==typeof t.name?'"'+t.name+'"':"("+typeof t.name+")"))||this).state=void 0,n.state=t,n}return t(n,e),n}(/*#__PURE__*/o(Error)),ce=/*#__PURE__*/function(e){function n(t){var n;return(n=e.call(this,"Invalid state: "+("string"==typeof t.name?'"'+t.name+'"':"("+typeof t.name+")"))||this).state=void 0,n.state=t,n}return t(n,e),n}(/*#__PURE__*/o(Error)),he=/*#__PURE__*/function(n){function r(t,r){var i;(i=n.call(this)||this).api=void 0,i.user=void 0,i.email=void 0,i.thirdParty=void 0,i.enterprise=void 0,i.token=void 0,i.relay=void 0,i.session=void 0,i.flow=void 0;var o={timeout:13e3,cookieName:"hanko",localStorageKey:"hanko"};return void 0!==(null==r?void 0:r.cookieName)&&(o.cookieName=r.cookieName),void 0!==(null==r?void 0:r.timeout)&&(o.timeout=r.timeout),void 0!==(null==r?void 0:r.localStorageKey)&&(o.localStorageKey=r.localStorageKey),void 0!==(null==r?void 0:r.cookieDomain)&&(o.cookieDomain=r.cookieDomain),void 0!==(null==r?void 0:r.cookieSameSite)&&(o.cookieSameSite=r.cookieSameSite),i.api=t,i.user=new B(t,o),i.email=new V(t,o),i.thirdParty=new z(t,o),i.enterprise=new J(t,o),i.token=new X(t,o),i.relay=new $(e({},o)),i.session=new Z(e({},o)),i.flow=new ae(t,o),i}return t(r,n),r}(Q),le=/*#__PURE__*/function(){function e(){}return e.supported=function(){return!!(navigator.credentials&&navigator.credentials.create&&navigator.credentials.get&&window.PublicKeyCredential)},e.isPlatformAuthenticatorAvailable=function(){try{return this.supported()&&window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?Promise.resolve(window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()):Promise.resolve(!1)}catch(e){return Promise.reject(e)}},e.isSecurityKeySupported=function(){try{return void 0!==window.PublicKeyCredential&&window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported?Promise.resolve(window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported()):Promise.resolve(this.supported())}catch(e){return Promise.reject(e)}},e.isConditionalMediationAvailable=function(){try{return window.PublicKeyCredential&&window.PublicKeyCredential.isConditionalMediationAvailable?Promise.resolve(window.PublicKeyCredential.isConditionalMediationAvailable()):Promise.resolve(!1)}catch(e){return Promise.reject(e)}},e}();exports.ConflictError=d,exports.CustomEventWithDetail=D,exports.EmailAddressAlreadyExistsError=_,exports.EmailClient=V,exports.EnterpriseClient=J,exports.ForbiddenError=x,exports.Hanko=he,exports.HankoError=h,exports.InvalidPasscodeError=m,exports.InvalidPasswordError=v,exports.InvalidWebauthnCredentialError=w,exports.MaxNumOfEmailAddressesReachedError=b,exports.MaxNumOfPasscodeAttemptsReachedError=g,exports.NotFoundError=E,exports.PasscodeExpiredError=y,exports.RequestTimeoutError=f,exports.TechnicalError=l,exports.ThirdPartyClient=z,exports.ThirdPartyError=O,exports.TokenClient=X,exports.TooManyRequestsError=P,exports.UnauthorizedError=k,exports.UserClient=B,exports.UserVerificationError=S,exports.WebauthnRequestCancelledError=p,exports.WebauthnSupport=le,exports.sessionCreatedType=A,exports.sessionExpiredType=T,exports.userDeletedType=N,exports.userLoggedOutType=R;
1
+ function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},e.apply(this,arguments)}function t(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,r(e,t)}function n(e){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},n(e)}function r(e,t){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},r(e,t)}function i(e,t,n){return i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}()?Reflect.construct.bind():function(e,t,n){var i=[null];i.push.apply(i,t);var o=new(Function.bind.apply(e,i));return n&&r(o,n.prototype),o},i.apply(null,arguments)}function o(e){var t="function"==typeof Map?new Map:void 0;return o=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,o)}function o(){return i(e,arguments,n(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),r(o,e)},o(e)}function s(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var a=0;function u(e){return"__private_"+a+++"_"+e}function c(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var h=/*#__PURE__*/function(e){function n(t,r,i){var o;return(o=e.call(this,t)||this).code=void 0,o.cause=void 0,o.code=r,o.cause=i,Object.setPrototypeOf(s(o),n.prototype),o}return t(n,e),n}(/*#__PURE__*/o(Error)),l=/*#__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}(h),d=/*#__PURE__*/function(e){function n(t,r){var i;return i=e.call(this,"Conflict error","conflict",r)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),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}(h),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}(h),v=/*#__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}(h),m=/*#__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}(h),y=/*#__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}(h),w=/*#__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}(h),g=/*#__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}(h),E=/*#__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}(h),P=/*#__PURE__*/function(e){function n(t,r){var i;return(i=e.call(this,"Too many requests error","tooManyRequests",r)||this).retryAfter=void 0,i.retryAfter=t,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),k=/*#__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}(h),x=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Forbidden error","forbidden",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),S=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"User verification error","userVerification",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),b=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"Maximum number of email addresses reached error","maxNumOfEmailAddressesReached",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),_=/*#__PURE__*/function(e){function n(t){var r;return r=e.call(this,"The email address already exists","emailAddressAlreadyExistsError",t)||this,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),O=/*#__PURE__*/function(e){function n(t,r){var i;return i=e.call(this,"An error occurred during third party sign up/sign in",t,r)||this,Object.setPrototypeOf(s(i),n.prototype),i}return t(n,e),n}(h),C=/*#__PURE__*/function(){function e(e){this.key=void 0,this.ls=void 0,this.key=e,this.ls={}}var t=e.prototype;return t.read=function(){var e;try{var t=localStorage.getItem(this.key),n=decodeURIComponent(decodeURI(window.atob(t)));e=JSON.parse(n)}catch(e){return this.ls={},this}return this.ls=e,this},t.write=function(){var e=JSON.stringify(this.ls),t=window.btoa(encodeURI(encodeURIComponent(e)));return localStorage.setItem(this.key,t),this},e.timeToRemainingSeconds=function(e){return void 0===e&&(e=0),e-Math.floor(Date.now()/1e3)},e.remainingSecondsToTime=function(e){return void 0===e&&(e=0),Math.floor(Date.now()/1e3)+e},e}(),j=/*#__PURE__*/function(e){function n(t){return e.call(this,t.localStorageKey+"_session")||this}t(n,e);var r=n.prototype;return r.read=function(){return e.prototype.read.call(this),this},r.getState=function(){var e;return(e=this.ls).session||(e.session={expiry:0,authFlowCompleted:!1}),this.ls.session},r.getExpirationSeconds=function(){return C.timeToRemainingSeconds(this.getState().expiry)},r.setExpirationSeconds=function(e){return this.getState().expiry=C.remainingSecondsToTime(e),this},r.getAuthFlowCompleted=function(){return this.getState().authFlowCompleted},r.setAuthFlowCompleted=function(e){return this.getState().authFlowCompleted=e,this},r.reset=function(){return delete this.getState().expiry,this},n}(C),A="hanko-session-created",T="hanko-session-expired",R="hanko-user-logged-out",N="hanko-user-deleted",D=/*#__PURE__*/function(e){function n(t,n){return e.call(this,t,{detail:n})||this}return t(n,e),n}(/*#__PURE__*/o(CustomEvent)),L=/*#__PURE__*/function(){function t(t){this._dispatchEvent=document.dispatchEvent.bind(document),this._sessionState=void 0,this._sessionState=new j(e({},t))}var n=t.prototype;return n.dispatch=function(e,t){this._dispatchEvent(new D(e,t))},n.dispatchSessionCreatedEvent=function(e){this.dispatch(A,e)},n.dispatchSessionExpiredEvent=function(){this.dispatch(T,null)},n.dispatchUserLoggedOutEvent=function(){this.dispatch(R,null)},n.dispatchUserDeletedEvent=function(){this.dispatch(N,null)},t}();function U(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}var W,I=function e(t,n){function r(e,r,i){if("undefined"!=typeof document){"number"==typeof(i=U({},n,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var o="";for(var s in i)i[s]&&(o+="; "+s,!0!==i[s]&&(o+="="+i[s].split(";")[0]));return document.cookie=e+"="+t.write(r,e)+o}}return Object.create({set:r,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var n=document.cookie?document.cookie.split("; "):[],r={},i=0;i<n.length;i++){var o=n[i].split("="),s=o.slice(1).join("=");try{var a=decodeURIComponent(o[0]);if(r[a]=t.read(s,a),e===a)break}catch(e){}}return e?r[e]:r}},remove:function(e,t){r(e,"",U({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,U({},this.attributes,t))},withConverter:function(t){return e(U({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"}),q=/*#__PURE__*/function(){function t(e){var t;this.authCookieName=void 0,this.authCookieDomain=void 0,this.authCookieSameSite=void 0,this.authCookieName=e.cookieName,this.authCookieDomain=e.cookieDomain,this.authCookieSameSite=null!=(t=e.cookieSameSite)?t:"lax"}var n=t.prototype;return n.getAuthCookie=function(){return I.get(this.authCookieName)},n.setAuthCookie=function(t,n){var r={secure:!0,sameSite:this.authCookieSameSite};void 0!==this.authCookieDomain&&(r.domain=this.authCookieDomain);var i=e({},r,n);if(("none"===i.sameSite||"None"===i.sameSite)&&!1===i.secure)throw new l(new Error("Secure attribute must be set when SameSite=None"));I.set(this.authCookieName,t,i)},n.removeAuthCookie=function(){I.remove(this.authCookieName)},t}(),M=/*#__PURE__*/function(){function e(e){this._xhr=void 0,this._xhr=e}return e.prototype.getResponseHeader=function(e){return this._xhr.getResponseHeader(e)},e}(),F=/*#__PURE__*/function(){function e(e){this.headers=void 0,this.ok=void 0,this.status=void 0,this.statusText=void 0,this.url=void 0,this._decodedJSON=void 0,this.xhr=void 0,this.headers=new M(e),this.ok=e.status>=200&&e.status<=299,this.status=e.status,this.statusText=e.statusText,this.url=e.responseURL,this.xhr=e}var t=e.prototype;return t.json=function(){return this._decodedJSON||(this._decodedJSON=JSON.parse(this.xhr.response)),this._decodedJSON},t.parseNumericHeader=function(e){var t=parseInt(this.headers.getResponseHeader(e),10);return isNaN(t)?0:t},e}(),K=/*#__PURE__*/function(){function t(t,n){this.timeout=void 0,this.api=void 0,this.sessionState=void 0,this.dispatcher=void 0,this.cookie=void 0,this.api=t,this.timeout=n.timeout,this.sessionState=new j(e({},n)),this.dispatcher=new L(e({},n)),this.cookie=new q(e({},n))}var n=t.prototype;return n._fetch=function(e,t,n){void 0===n&&(n=new XMLHttpRequest);var r=this,i=this.api+e,o=this.timeout,s=this.cookie.getAuthCookie();return new Promise(function(e,a){n.open(t.method,i,!0),n.setRequestHeader("Accept","application/json"),n.setRequestHeader("Content-Type","application/json"),s&&n.setRequestHeader("Authorization","Bearer "+s),n.timeout=o,n.withCredentials=!0,n.onload=function(){r.processHeaders(n),e(new F(n))},n.onerror=function(){a(new l)},n.ontimeout=function(){a(new f)},n.send(t.body?t.body.toString():null)})},n.processHeaders=function(e){var t="",n=0;if(e.getAllResponseHeaders().split("\r\n").forEach(function(r){var i=r.toLowerCase();i.startsWith("x-auth-token")?t=e.getResponseHeader("X-Auth-Token"):i.startsWith("x-session-lifetime")&&(n=parseInt(e.getResponseHeader("X-Session-Lifetime"),10))}),t){var r=new RegExp("^https://"),i=!!this.api.match(r)&&!!window.location.href.match(r),o=new Date((new Date).getTime()+1e3*n);this.cookie.setAuthCookie(t,{secure:i,expires:o})}n>0&&(this.sessionState.read(),this.sessionState.setExpirationSeconds(n),this.sessionState.setAuthFlowCompleted(!1),this.sessionState.write())},n.get=function(e){return this._fetch(e,{method:"GET"})},n.post=function(e,t){return this._fetch(e,{method:"POST",body:JSON.stringify(t)})},n.put=function(e,t){return this._fetch(e,{method:"PUT",body:JSON.stringify(t)})},n.patch=function(e,t){return this._fetch(e,{method:"PATCH",body:JSON.stringify(t)})},n.delete=function(e){return this._fetch(e,{method:"DELETE"})},t}(),H=function(e,t){this.client=void 0,this.client=new K(e,t)},J=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var r=n.prototype;return r.getDomain=function(e){if(!e)throw new O("somethingWentWrong",new Error("email missing from request"));var t=e.split("@");if(2!==t.length)throw new O("somethingWentWrong",new Error("email is not in a valid email format."));var n=t[1].trim();if(""===n)throw new O("somethingWentWrong",new Error("email is not in a valid email format."));return n},r.hasProvider=function(e){try{var t=this.getDomain(e);return Promise.resolve(this.client.get("/saml/provider?domain="+t).then(function(e){if(404==e.status)throw new E(new Error("provider not found"));if(!e.ok)throw new l(new Error("unable to fetch provider"));return e.ok}))}catch(e){return Promise.reject(e)}},r.auth=function(e,t){var n=new URL("/saml/auth",this.client.api),r=this.getDomain(e);if(!t)throw new O("somethingWentWrong",new Error("redirectTo missing from request"));n.searchParams.append("domain",r),n.searchParams.append("redirect_to",t),window.location.assign(n.href)},r.getError=function(){var e=new URLSearchParams(window.location.search),t=e.get("error"),n=e.get("error_description");if(t){var r;switch(t){case"access_denied":r="enterpriseAccessDenied";break;case"user_conflict":r="emailAddressAlreadyExistsError";break;case"multiple_accounts":r="enterpriseMultipleAccounts";break;case"unverified_email":r="enterpriseUnverifiedEmail";break;case"email_maxnum":r="maxNumOfEmailAddressesReached";break;default:r="somethingWentWrong"}return new O(r,new Error(n))}},n}(H),B=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var r=n.prototype;return r.getInfo=function(e){try{return Promise.resolve(this.client.post("/user",{email:e})).then(function(e){if(404===e.status)throw new E;if(!e.ok)throw new l;return e.json()})}catch(e){return Promise.reject(e)}},r.create=function(e){try{return Promise.resolve(this.client.post("/users",{email:e})).then(function(e){if(409===e.status)throw new d;if(403===e.status)throw new x;if(!e.ok)throw new l;return e.json()})}catch(e){return Promise.reject(e)}},r.getCurrent=function(){try{var e=this;return Promise.resolve(e.client.get("/me")).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new k;if(!t.ok)throw new l;var n=t.json();return Promise.resolve(e.client.get("/users/"+n.id)).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new k;if(!t.ok)throw new l;return t.json()})})}catch(e){return Promise.reject(e)}},r.delete=function(){try{var e=this;return Promise.resolve(e.client.delete("/user")).then(function(t){if(t.ok)return e.client.cookie.removeAuthCookie(),e.client.sessionState.reset().write(),void e.client.dispatcher.dispatchUserDeletedEvent();if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new k;throw new l})}catch(e){return Promise.reject(e)}},r.logout=function(){try{var e=this;return Promise.resolve(e.client.post("/logout")).then(function(t){if(e.client.cookie.removeAuthCookie(),e.client.sessionState.reset().write(),e.client.dispatcher.dispatchUserLoggedOutEvent(),401===t.status);else if(!t.ok)throw new l})}catch(e){return Promise.reject(e)}},n}(H),V=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var r=n.prototype;return r.list=function(){try{var e=this;return Promise.resolve(e.client.get("/emails")).then(function(t){if(401===t.status)throw e.client.dispatcher.dispatchSessionExpiredEvent(),new k;if(!t.ok)throw new l;return t.json()})}catch(e){return Promise.reject(e)}},r.create=function(e){try{var t=this;return Promise.resolve(t.client.post("/emails",{address:e})).then(function(e){if(e.ok)return e.json();if(400===e.status)throw new _;if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new k;if(409===e.status)throw new b;throw new l})}catch(e){return Promise.reject(e)}},r.setPrimaryEmail=function(e){try{var t=this;return Promise.resolve(t.client.post("/emails/"+e+"/set_primary")).then(function(e){if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new k;if(!e.ok)throw new l})}catch(e){return Promise.reject(e)}},r.delete=function(e){try{var t=this;return Promise.resolve(t.client.delete("/emails/"+e)).then(function(e){if(401===e.status)throw t.client.dispatcher.dispatchSessionExpiredEvent(),new k;if(!e.ok)throw new l})}catch(e){return Promise.reject(e)}},n}(H),z=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}t(n,e);var r=n.prototype;return r.auth=function(e,t){try{var n=new URL("/thirdparty/auth",this.client.api);if(!e)throw new O("somethingWentWrong",new Error("provider missing from request"));if(!t)throw new O("somethingWentWrong",new Error("redirectTo missing from request"));return n.searchParams.append("provider",e),n.searchParams.append("redirect_to",t),window.location.assign(n.href),Promise.resolve()}catch(e){return Promise.reject(e)}},r.getError=function(){var e=new URLSearchParams(window.location.search),t=e.get("error"),n=e.get("error_description");if(t){var r="";switch(t){case"access_denied":r="thirdPartyAccessDenied";break;case"user_conflict":r="emailAddressAlreadyExistsError";break;case"multiple_accounts":r="thirdPartyMultipleAccounts";break;case"unverified_email":r="thirdPartyUnverifiedEmail";break;case"email_maxnum":r="maxNumOfEmailAddressesReached";break;case"signup_disabled":r="signupDisabled";break;default:r="somethingWentWrong"}return new O(r,new Error(n))}},n}(H),X=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n.prototype.validate=function(){try{var e=new URLSearchParams(window.location.search).get("hanko_token");return e?(window.history.replaceState(null,null,window.location.pathname),Promise.resolve(this.client.post("/token",{value:e})).then(function(e){if(!e.ok)throw new l;return e.json()})):Promise.resolve()}catch(e){return Promise.reject(e)}},n}(H),G=/*#__PURE__*/function(){function e(){}return e.throttle=function(e,t,n){void 0===n&&(n={});var r,i,o,s=n.leading,a=void 0===s||s,u=n.trailing,c=void 0===u||u,h=0,l=function(){h=!1===a?0:Date.now(),o=null,e.apply(r,i)};return function(){var n=Date.now();h||!1!==a||(h=n);var s=t-(n-h);r=this,i=[].slice.call(arguments),s<=0||s>t?(o&&(window.clearTimeout(o),o=null),h=n,e.apply(r,i)):o||!1===c||(o=window.setTimeout(l,s))}},e}(),Q=/*#__PURE__*/function(){function e(){this.throttleLimit=1e3,this._addEventListener=document.addEventListener.bind(document),this._removeEventListener=document.removeEventListener.bind(document),this._throttle=G.throttle}var t=e.prototype;return t.wrapCallback=function(e,t){var n=function(t){e(t.detail)};return t?this._throttle(n,this.throttleLimit,{leading:!0,trailing:!1}):n},t.addEventListenerWithType=function(e){var t=this,n=e.type,r=e.once,i=void 0!==r&&r,o=e.throttle,s=this.wrapCallback(e.callback,void 0!==o&&o);return this._addEventListener(n,s,{once:i}),function(){return t._removeEventListener(n,s)}},e.mapAddEventListenerParams=function(e,t,n){return{type:e,callback:t.callback,once:t.once,throttle:n}},t.addEventListener=function(t,n,r){return this.addEventListenerWithType(e.mapAddEventListenerParams(t,n,r))},t.onSessionCreated=function(e,t){return this.addEventListener(A,{callback:e,once:t},!0)},t.onSessionExpired=function(e,t){return this.addEventListener(T,{callback:e,once:t},!0)},t.onUserLoggedOut=function(e,t){return this.addEventListener(R,{callback:e,once:t})},t.onUserDeleted=function(e,t){return this.addEventListener(N,{callback:e,once:t})},e}(),Y=/*#__PURE__*/function(){function e(){this._tasks=[]}var t=e.prototype;return t.removeTask=function(e){window.clearTimeout(e.timeoutID),this._tasks=this._tasks.filter(function(t){return t!==e})},t.removeTasksWithType=function(e){var t=this;this._tasks.filter(function(t){return t.type===e}).forEach(function(e){return t.removeTask(e)})},t.scheduleTask=function(e,t,n){var r=this,i={timeoutID:window.setTimeout(function(){t(),r.removeTask(i)},1e3*n),type:e,func:t};this._tasks.push(i)},e}(),Z=/*#__PURE__*/function(){function t(t){this._sessionState=void 0,this._cookie=void 0,this._sessionState=new j(e({},t)),this._cookie=new q(e({},t))}var n=t.prototype;return n.get=function(){var e=this._get();return t.validate(e)?e:null},n.isValid=function(){var e=this._get();return t.validate(e)},n._get=function(){return this._sessionState.read(),{expirationSeconds:this._sessionState.getExpirationSeconds(),jwt:this._cookie.getAuthCookie()}},n.isAuthFlowCompleted=function(){return this._sessionState.read(),this._sessionState.getAuthFlowCompleted()},t.validate=function(e){return e.expirationSeconds>0},t}(),$=/*#__PURE__*/function(n){function r(t){var r;return(r=n.call(this,e({},t))||this)._listener=new Q,r._scheduler=new Y,r._session=void 0,r.scheduleSessionExpiredEvent=function(e){r._scheduler.removeTasksWithType(T),r._scheduler.scheduleTask(T,function(){return r.dispatchSessionExpiredEvent()},e.expirationSeconds)},r.cancelSessionExpiredEvent=function(){r._scheduler.removeTasksWithType(T)},r.handleStorageEvent=function(e){if("hanko_session"===e.key){var t=r._session.get();t?r.dispatchSessionCreatedEvent(t):r.dispatchSessionExpiredEvent()}},r._session=new Z(e({},t)),r.listenEventDependencies(),r}return t(r,n),r.prototype.listenEventDependencies=function(){this._listener.onSessionCreated(this.scheduleSessionExpiredEvent),this._listener.onSessionExpired(this.cancelSessionExpiredEvent),this._listener.onUserDeleted(this.cancelSessionExpiredEvent),this._listener.onUserLoggedOut(this.cancelSessionExpiredEvent),window.addEventListener("storage",this.handleStorageEvent);var e=this._session.get();e&&this.scheduleSessionExpiredEvent(e)},r}(L),ee=/*#__PURE__*/u("actionDefinitions"),te=/*#__PURE__*/u("createActionsProxy"),ne=/*#__PURE__*/function(){var e=t.prototype;function t(e,t){var n=e.name,r=e.payload,i=e.error,o=e.status,s=e.actions,a=e.csrf_token;Object.defineProperty(this,te,{value:re}),this.name=void 0,this.payload=void 0,this.error=void 0,this.status=void 0,this.csrf_token=void 0,Object.defineProperty(this,ee,{writable:!0,value:void 0}),this.actions=void 0,this.fetchNextState=void 0,this.name=n,this.payload=r,this.error=i,this.status=o,this.csrf_token=a,c(this,ee)[ee]=s,this.actions=c(this,te)[te](s,a),this.fetchNextState=t}return e.toJSON=function(){return{name:this.name,payload:this.payload,error:this.error,status:this.status,csrf_token:this.csrf_token,actions:c(this,ee)[ee]}},e.runAction=function(e,t){var n={};if("inputs"in e&&"object"==typeof e.inputs&&null!==e.inputs){var r=e.inputs;for(var i in e.inputs){var o=r[i];o&&"value"in o&&(n[i]=o.value)}}return this.fetchNextState(e.href,{input_data:n,csrf_token:t})},e.validateAction=function(e){if("inputs"in e){var t=function(t){var n=e.inputs[t];function r(e,n,r,i){throw new ie({reason:e,inputName:t,wanted:r,actual:i,message:n})}var i=n.value;n.required&&!i&&r(W.Required,"is required"),(null!=n.min_length||null!=n.max_length)&&("length"in i||r(W.InvalidInputDefinition,'has min/max length requirement, but is missing "length" property',"string",typeof i),null!=n.min_length&&i<n.min_length&&r(W.MinLength,"too short (min "+n.min_length+")",n.min_length,i.length),null!=n.max_length&&i>n.max_length&&r(W.MaxLength,"too long (max "+n.max_length+")",n.max_length,i.length))};for(var n in e.inputs)t(n)}},t}();function re(e,t){var n=this,r=function(e){return n.validateAction(e)};return new Proxy(e,{get:function(e,i){if("symbol"==typeof i)return e[i];var o=e[i];return null==o?null:function(e){var i=Object.assign(JSON.parse(JSON.stringify(o)),{validate:function(){return r(i),i},tryValidate:function(){try{r(i)}catch(e){if(e instanceof ie)return e;throw e}},run:function(){return function(e){return n.runAction(e,t)}(i)}});if(null!==i&&"object"==typeof i&&"inputs"in i)for(var s in e){var a=i.inputs;a[s]||(a[s]={name:s,type:""}),a[s].value=e[s]}return i}}})}!function(e){e[e.InvalidInputDefinition=0]="InvalidInputDefinition",e[e.MinLength=1]="MinLength",e[e.MaxLength=2]="MaxLength",e[e.Required=3]="Required"}(W||(W={}));var ie=/*#__PURE__*/function(e){function n(t){var n;return(n=e.call(this,'"'+t.inputName+'" '+t.message)||this).reason=void 0,n.inputName=void 0,n.wanted=void 0,n.actual=void 0,n.name="ValidationError",n.reason=t.reason,n.inputName=t.inputName,n.wanted=t.wanted,n.actual=t.actual,n}return t(n,e),n}(/*#__PURE__*/o(Error));function oe(e){return"object"==typeof e&&null!==e&&"status"in e&&"error"in e&&"name"in e&&Boolean(e.name)&&Boolean(e.status)}function se(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var ae=/*#__PURE__*/function(e){function n(){for(var t,n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];return(t=e.call.apply(e,[this].concat(r))||this).run=function(e,n){try{return Promise.resolve(se(function(){if(!oe(e))throw new ce(e);var r=n[e.name];if(!r)throw new ue(e);return Promise.resolve(r(e)).then(function(e){function r(){if(oe(e))return t.run(e,n)}var i=function(){if("object"==typeof(t=e)&&null!==t&&"href"in t&&"inputs"in t)return Promise.resolve(e.run()).then(function(t){e=t});var t}();return i&&i.then?i.then(r):r()})},function(e){if("function"==typeof n.onError)return n.onError(e)}))}catch(e){return Promise.reject(e)}},t}t(n,e);var r=n.prototype;return r.init=function(e,t){var n=this;return Promise.resolve(function e(r,i){try{return Promise.resolve(se(function(){return Promise.resolve(n.client.post(r,i)).then(function(t){return new ne(t.json(),e)})},function(e){null==t.onError||t.onError(e)}))}catch(e){return Promise.reject(e)}}(e)).then(function(e){return Promise.resolve(n.run(e,t)).then(function(){})})},r.fromString=function(e,t){try{var n=this,r=new ne(JSON.parse(e),function e(r,i){try{return Promise.resolve(se(function(){return Promise.resolve(n.client.post(r,i)).then(function(t){return new ne(t.json(),e)})},function(e){null==t.onError||t.onError(e)}))}catch(e){return Promise.reject(e)}});return Promise.resolve(n.run(r,t)).then(function(){})}catch(e){return Promise.reject(e)}},n}(H),ue=/*#__PURE__*/function(e){function n(t){var r;return(r=e.call(this,"No handler found for state: "+("string"==typeof t.name?'"'+t.name+'"':"("+typeof t.name+")"),"handlerNotFoundError")||this).state=void 0,r.state=t,Object.setPrototypeOf(s(r),n.prototype),r}return t(n,e),n}(h),ce=/*#__PURE__*/function(e){function n(t){var n;return(n=e.call(this,"Invalid state: "+("string"==typeof t.name?'"'+t.name+'"':"("+typeof t.name+")"))||this).state=void 0,n.state=t,n}return t(n,e),n}(/*#__PURE__*/o(Error)),he=/*#__PURE__*/function(e){function n(){return e.apply(this,arguments)||this}return t(n,e),n.prototype.isValid=function(){try{return Promise.resolve(this.client.get("/sessions/validate")).then(function(e){if(!e.ok)throw new l;return e.json()})}catch(e){return Promise.reject(e)}},n}(H),le=/*#__PURE__*/function(n){function r(t,r){var i;(i=n.call(this)||this).api=void 0,i.user=void 0,i.email=void 0,i.thirdParty=void 0,i.enterprise=void 0,i.token=void 0,i.sessionClient=void 0,i.relay=void 0,i.session=void 0,i.flow=void 0;var o={timeout:13e3,cookieName:"hanko",localStorageKey:"hanko"};return void 0!==(null==r?void 0:r.cookieName)&&(o.cookieName=r.cookieName),void 0!==(null==r?void 0:r.timeout)&&(o.timeout=r.timeout),void 0!==(null==r?void 0:r.localStorageKey)&&(o.localStorageKey=r.localStorageKey),void 0!==(null==r?void 0:r.cookieDomain)&&(o.cookieDomain=r.cookieDomain),void 0!==(null==r?void 0:r.cookieSameSite)&&(o.cookieSameSite=r.cookieSameSite),i.api=t,i.user=new B(t,o),i.email=new V(t,o),i.thirdParty=new z(t,o),i.enterprise=new J(t,o),i.token=new X(t,o),i.sessionClient=new he(t,o),i.relay=new $(e({},o)),i.session=new Z(e({},o)),i.flow=new ae(t,o),i}return t(r,n),r}(Q),de=/*#__PURE__*/function(){function e(){}return e.supported=function(){return!!(navigator.credentials&&navigator.credentials.create&&navigator.credentials.get&&window.PublicKeyCredential)},e.isPlatformAuthenticatorAvailable=function(){try{return this.supported()&&window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?Promise.resolve(window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()):Promise.resolve(!1)}catch(e){return Promise.reject(e)}},e.isSecurityKeySupported=function(){try{return void 0!==window.PublicKeyCredential&&window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported?Promise.resolve(window.PublicKeyCredential.isExternalCTAP2SecurityKeySupported()):Promise.resolve(this.supported())}catch(e){return Promise.reject(e)}},e.isConditionalMediationAvailable=function(){try{return window.PublicKeyCredential&&window.PublicKeyCredential.isConditionalMediationAvailable?Promise.resolve(window.PublicKeyCredential.isConditionalMediationAvailable()):Promise.resolve(!1)}catch(e){return Promise.reject(e)}},e}();exports.ConflictError=d,exports.CustomEventWithDetail=D,exports.EmailAddressAlreadyExistsError=_,exports.EmailClient=V,exports.EnterpriseClient=J,exports.ForbiddenError=x,exports.Hanko=le,exports.HankoError=h,exports.InvalidPasscodeError=m,exports.InvalidPasswordError=v,exports.InvalidWebauthnCredentialError=y,exports.MaxNumOfEmailAddressesReachedError=b,exports.MaxNumOfPasscodeAttemptsReachedError=g,exports.NotFoundError=E,exports.PasscodeExpiredError=w,exports.RequestTimeoutError=f,exports.SessionClient=he,exports.TechnicalError=l,exports.ThirdPartyClient=z,exports.ThirdPartyError=O,exports.TokenClient=X,exports.TooManyRequestsError=P,exports.UnauthorizedError=k,exports.UserClient=B,exports.UserVerificationError=S,exports.WebauthnRequestCancelledError=p,exports.WebauthnSupport=de,exports.sessionCreatedType=A,exports.sessionExpiredType=T,exports.userDeletedType=N,exports.userLoggedOutType=R;
2
2
  //# sourceMappingURL=sdk.cjs.map