@teamhanko/hanko-frontend-sdk 0.4.0-alpha → 0.8.0-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -47,7 +47,7 @@ To see the latest documentation, please click [here](https://docs.hanko.io/jsdoc
47
47
 
48
48
  - `Hanko` - A class that bundles all functionalities.
49
49
 
50
- ### Clients
50
+ ### Client Classes
51
51
 
52
52
  - `ConfigClient` - A class to fetch configurations.
53
53
  - `UserClient` - A class to manage users.
@@ -57,23 +57,47 @@ To see the latest documentation, please click [here](https://docs.hanko.io/jsdoc
57
57
  - `ThirdPartyClient` - A class to handle social logins.
58
58
  - `TokenClient` - A class that handles the exchange of one time tokens for session JWTs.
59
59
 
60
- ### Utilities
60
+ ### Utility Classes
61
61
 
62
62
  - `WebauthnSupport` - A class to check the browser's WebAuthn support.
63
63
 
64
- ### DTOs
64
+ ### DTO Interfaces
65
65
 
66
- - `Config`
67
66
  - `PasswordConfig`
67
+ - `EmailConfig`
68
+ - `AccountConfig`
69
+ - `Config`
68
70
  - `WebauthnFinalized`
69
- - `Credential`
71
+ - `TokenFinalized`
70
72
  - `UserInfo`
73
+ - `Me`
74
+ - `Credential`
71
75
  - `User`
76
+ - `UserCreated`
77
+ - `Passcode`
78
+ - `WebauthnTransports`
79
+ - `Attestation`
72
80
  - `Email`
73
81
  - `Emails`
74
- - `Passcode`
82
+ - `WebauthnCredential`
83
+ - `WebauthnCredentials`
84
+ - `Identity`
85
+
86
+ ### Event Interfaces
87
+
88
+ - `SessionDetail`
89
+ - `AuthFlowCompletedDetail`
90
+
91
+ ### Event Types
75
92
 
76
- ### Errors
93
+ - `CustomEventWithDetail`
94
+ - `authFlowCompletedType`
95
+ - `sessionCreatedType`
96
+ - `sessionExpiredType`
97
+ - `userLoggedOutType`
98
+ - `userDeletedType`
99
+
100
+ ### Error Classes
77
101
 
78
102
  - `HankoError`
79
103
  - `TechnicalError`
@@ -100,7 +124,7 @@ not logged in:
100
124
  ```typescript
101
125
  import { Hanko, UnauthorizedError } from "@teamhanko/hanko-frontend-sdk"
102
126
 
103
- const hanko = new Hanko("http://localhost:3000")
127
+ const hanko = new Hanko("https://[HANKO_API_URL]")
104
128
 
105
129
  try {
106
130
  const user = await hanko.user.getCurrent()
@@ -124,7 +148,7 @@ with a desktop computer:
124
148
  ```typescript
125
149
  import { Hanko, UnauthorizedError, WebauthnRequestCancelledError } from "@teamhanko/hanko-frontend-sdk"
126
150
 
127
- const hanko = new Hanko("http://localhost:3000")
151
+ const hanko = new Hanko("https://[HANKO_API_URL]")
128
152
 
129
153
  // By passing the user object (see example above) to `hanko.webauthn.shouldRegister(user)` you get an indication of
130
154
  // whether a WebAuthn credential registration should be performed on the current browser. This is useful if the user has
@@ -145,6 +169,81 @@ try {
145
169
  }
146
170
  ```
147
171
 
172
+ ### Custom Events
173
+
174
+ You can bind callback functions to different custom events. The callback function will be called when the event happens
175
+ and an object will be passed in, containing event details. The event binding works as follows:
176
+
177
+ ```typescript
178
+ // Controls the optional `once` parameter. When set to `true` the callback function will be called only once.
179
+ const once = false;
180
+
181
+ const removeEventListener = hanko.onSessionCreated((eventDetail) => {
182
+ // Your code...
183
+ }, once);
184
+ ```
185
+
186
+ The following events are available:
187
+
188
+ - "hanko-auth-flow-completed": Will be triggered after a session has been created and the user has completed possible
189
+ additional steps (e.g. passkey registration or password recovery) via the `<hanko-auth>` element.
190
+
191
+ ```js
192
+ hanko.onAuthFlowCompleted((authFlowCompletedDetail) => {
193
+ // Login, registration or recovery has been completed successfully. You can now take control and redirect the
194
+ // user to protected pages.
195
+ console.info(`User successfully completed the registration or authorization process (user-id: "${authFlowCompletedDetail.userID}")`);
196
+ })
197
+ ```
198
+
199
+ - "hanko-session-created": Will be triggered before the "hanko-auth-flow-completed" happens, as soon as the user is technically logged in.
200
+ It will also be triggered when the user logs in via another browser window. The event can be used to obtain the JWT. Please note, that the
201
+ JWT is only available, when the Hanko API configuration allows to obtain the JWT. When using Hanko-Cloud
202
+ the JWT is always present, for self-hosted Hanko-APIs you can restrict the cookie to be readable by the backend only, as long as
203
+ your backend runs under the same domain as your frontend. To do so, make sure the config parameter "session.enable_auth_token_header"
204
+ is turned off via the [Hanko-API configuration](https://github.com/teamhanko/hanko/blob/main/backend/docs/Config.md). If you want the JWT to be contained in the event details, you need to turn on
205
+ "session.enable_auth_token_header" when using a cross-domain setup. When it's a same-domain setup you need to turn off
206
+ "session.cookie.http_only" to make the JWT accessible to the frontend.
207
+
208
+ ```js
209
+ hanko.onSessionCreated((sessionDetail) => {
210
+ // A new JWT has been issued.
211
+ console.info(`Session created or updated (user-id: "${sessionDetail.userID}", jwt: ${sessionDetail.jwt})`);
212
+ })
213
+ ```
214
+
215
+ - "hanko-session-expired": Will be triggered when the session has expired, or when the session has been removed in
216
+ another browser window, because the user has logged out, or deleted the account.
217
+
218
+ ```js
219
+ hanko.onSessionExpired(() => {
220
+ // You can redirect the user to a login page or show the `<hanko-auth>` element, or to prompt the user to log in again.
221
+ console.info("Session expired");
222
+ })
223
+ ```
224
+
225
+ - "hanko-user-logged-out": Will be triggered, when the user actively logs out. In other browser windows, a "hanko-session-expired" event
226
+ will be triggered at the same time.
227
+
228
+ ```js
229
+ hanko.onUserLoggedOut(() => {
230
+ // You can redirect the user to a login page or show the `<hanko-auth>` element.
231
+ console.info("User logged out");
232
+ })
233
+ ```
234
+
235
+ - "hanko-user-deleted": Will be triggered when the user has deleted the account. In other browser windows, a "hanko-session-expired" event
236
+ will be triggered at the same time.
237
+
238
+ ```js
239
+ hanko.onUserDeleted(() => {
240
+ // You can redirect the user to a login page or show the `<hanko-auth>` element.
241
+ console.info("User has been deleted");
242
+ })
243
+ ```
244
+
245
+ Please Take a look into the [docs](https://docs.hanko.io/jsdoc/hanko-frontend-sdk/Hanko.html) for more details.
246
+
148
247
  ## Bugs
149
248
 
150
249
  Found a bug? Please report on our [GitHub](https://github.com/teamhanko/hanko/issues) page.
package/dist/Hanko.d.ts CHANGED
@@ -6,13 +6,17 @@ import { WebauthnClient } from "./lib/client/WebauthnClient";
6
6
  import { EmailClient } from "./lib/client/EmailClient";
7
7
  import { ThirdPartyClient } from "./lib/client/ThirdPartyClient";
8
8
  import { TokenClient } from "./lib/client/TokenClient";
9
+ import { Listener } from "./lib/events/Listener";
10
+ import { Relay } from "./lib/events/Relay";
11
+ import { Session } from "./lib/Session";
9
12
  /**
10
13
  * A class that bundles all available SDK functions.
11
14
  *
15
+ * @extends {Listener}
12
16
  * @param {string} api - The URL of your Hanko API instance
13
17
  * @param {number=} timeout - The request timeout in milliseconds
14
18
  */
15
- declare class Hanko {
19
+ declare class Hanko extends Listener {
16
20
  api: string;
17
21
  config: ConfigClient;
18
22
  user: UserClient;
@@ -22,6 +26,8 @@ declare class Hanko {
22
26
  email: EmailClient;
23
27
  thirdParty: ThirdPartyClient;
24
28
  token: TokenClient;
29
+ relay: Relay;
30
+ session: Session;
25
31
  constructor(api: string, timeout?: number);
26
32
  }
27
33
  export { Hanko };
package/dist/index.d.ts CHANGED
@@ -11,7 +11,10 @@ import { TokenClient } from "./lib/client/TokenClient";
11
11
  export { ConfigClient, UserClient, WebauthnClient, PasswordClient, PasscodeClient, EmailClient, ThirdPartyClient, TokenClient, };
12
12
  import { WebauthnSupport } from "./lib/WebauthnSupport";
13
13
  export { WebauthnSupport };
14
- import { PasswordConfig, Config, WebauthnFinalized, Credential, UserInfo, User, Email, Emails, WebauthnCredential, WebauthnCredentials, Passcode, Identity } from "./lib/Dto";
15
- export type { PasswordConfig, Config, WebauthnFinalized, Credential, UserInfo, User, Email, Emails, WebauthnCredential, WebauthnCredentials, Passcode, Identity, };
14
+ import { PasswordConfig, EmailConfig, AccountConfig, Config, WebauthnFinalized, TokenFinalized, UserInfo, Me, Credential, User, UserCreated, Passcode, WebauthnTransports, Attestation, Email, Emails, WebauthnCredential, WebauthnCredentials, Identity } from "./lib/Dto";
15
+ export type { PasswordConfig, EmailConfig, AccountConfig, Config, WebauthnFinalized, TokenFinalized, UserInfo, Me, Credential, User, UserCreated, Passcode, WebauthnTransports, Attestation, Email, Emails, WebauthnCredential, WebauthnCredentials, Identity, };
16
16
  import { HankoError, ConflictError, EmailAddressAlreadyExistsError, InvalidPasswordError, InvalidPasscodeError, InvalidWebauthnCredentialError, MaxNumOfEmailAddressesReachedError, MaxNumOfPasscodeAttemptsReachedError, NotFoundError, PasscodeExpiredError, RequestTimeoutError, TechnicalError, ThirdPartyError, TooManyRequestsError, UnauthorizedError, UserVerificationError, WebauthnRequestCancelledError } from "./lib/Errors";
17
17
  export { HankoError, ConflictError, EmailAddressAlreadyExistsError, InvalidPasswordError, InvalidPasscodeError, InvalidWebauthnCredentialError, MaxNumOfEmailAddressesReachedError, MaxNumOfPasscodeAttemptsReachedError, NotFoundError, PasscodeExpiredError, RequestTimeoutError, TechnicalError, ThirdPartyError, TooManyRequestsError, UnauthorizedError, UserVerificationError, WebauthnRequestCancelledError, };
18
+ import { CustomEventWithDetail, SessionDetail, AuthFlowCompletedDetail, authFlowCompletedType, sessionCreatedType, sessionExpiredType, userLoggedOutType, userDeletedType } from "./lib/events/CustomEvents";
19
+ export type { SessionDetail, AuthFlowCompletedDetail };
20
+ export { authFlowCompletedType, sessionCreatedType, sessionExpiredType, userLoggedOutType, userDeletedType, CustomEventWithDetail, };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * A class to manage cookies.
3
+ *
4
+ * @category SDK
5
+ * @subcategory Internal
6
+ */
7
+ export declare class Cookie {
8
+ authCookieName: string;
9
+ /**
10
+ * Returns the authentication token that was stored in the cookie.
11
+ *
12
+ * @return {string}
13
+ */
14
+ getAuthCookie(): string;
15
+ /**
16
+ * Stores the authentication token to the cookie.
17
+ *
18
+ * @param {string} token - The authentication token to be stored.
19
+ * @param {boolean=} secure - Indicates a secure cookie should be set. Default is `true`.
20
+ */
21
+ setAuthCookie(token: string, secure?: boolean): void;
22
+ /**
23
+ * Removes the cookie used for authentication.
24
+ */
25
+ removeAuthCookie(): void;
26
+ }
package/dist/lib/Dto.d.ts CHANGED
@@ -6,7 +6,7 @@ import { PublicKeyCredentialWithAttestationJSON } from "@github/webauthn-json";
6
6
  * @property {boolean} enabled - Indicates passwords are enabled, so the API accepts login attempts using passwords.
7
7
  * @property {number} min_password_length - The minimum length of a password. To be used for password validation.
8
8
  */
9
- interface PasswordConfig {
9
+ export interface PasswordConfig {
10
10
  enabled: boolean;
11
11
  min_password_length: number;
12
12
  }
@@ -17,7 +17,7 @@ interface PasswordConfig {
17
17
  * @property {boolean} require_verification - Indicates that email addresses must be verified.
18
18
  * @property {number} max_num_of_addresses - The maximum number of email addresses a user can have.
19
19
  */
20
- interface EmailConfig {
20
+ export interface EmailConfig {
21
21
  require_verification: boolean;
22
22
  max_num_of_addresses: number;
23
23
  }
@@ -27,7 +27,7 @@ interface EmailConfig {
27
27
  * @subcategory DTO
28
28
  * @property {boolean} allow_deletion - Indicates the current user is allowed to delete the account.
29
29
  */
30
- interface AccountConfig {
30
+ export interface AccountConfig {
31
31
  allow_deletion: boolean;
32
32
  }
33
33
  /**
@@ -39,7 +39,7 @@ interface AccountConfig {
39
39
  * @property {string[]} providers - The enabled third party providers.
40
40
  * @property {AccountConfig} account - Controls the behaviour regarding user accounts.
41
41
  */
42
- interface Config {
42
+ export interface Config {
43
43
  password: PasswordConfig;
44
44
  emails: EmailConfig;
45
45
  providers: string[];
@@ -52,10 +52,19 @@ interface Config {
52
52
  * @property {string} credential_id - The ID of the credential that was used.
53
53
  * @property {string} user_id - The ID of the user that was used.
54
54
  */
55
- interface WebauthnFinalized {
55
+ export interface WebauthnFinalized {
56
56
  credential_id: string;
57
57
  user_id: string;
58
58
  }
59
+ /**
60
+ * @interface
61
+ * @category SDK
62
+ * @subcategory DTO
63
+ * @property {string} user_id - The ID of the user associated with the token.
64
+ */
65
+ export interface TokenFinalized {
66
+ user_id: string;
67
+ }
59
68
  /**
60
69
  * @interface
61
70
  * @category SDK
@@ -65,7 +74,7 @@ interface WebauthnFinalized {
65
74
  * @property {string} email_id - The UUID of the email address.
66
75
  * @property {boolean} has_webauthn_credential - Indicates that the user has registered a WebAuthn credential in the past.
67
76
  */
68
- interface UserInfo {
77
+ export interface UserInfo {
69
78
  id: string;
70
79
  verified: boolean;
71
80
  email_id: string;
@@ -78,7 +87,7 @@ interface UserInfo {
78
87
  * @property {string} id - The UUID of the current user.
79
88
  * @ignore
80
89
  */
81
- interface Me {
90
+ export interface Me {
82
91
  id: string;
83
92
  }
84
93
  /**
@@ -87,7 +96,7 @@ interface Me {
87
96
  * @subcategory DTO
88
97
  * @property {string} id - The WebAuthn credential ID.
89
98
  */
90
- interface Credential {
99
+ export interface Credential {
91
100
  id: string;
92
101
  }
93
102
  /**
@@ -98,11 +107,22 @@ interface Credential {
98
107
  * @property {string} email - The user's email.
99
108
  * @property {Credential[]} webauthn_credentials - A list of credentials that have been registered.
100
109
  */
101
- interface User {
110
+ export interface User {
102
111
  id: string;
103
- email_id: string;
112
+ email: string;
104
113
  webauthn_credentials: Credential[];
105
114
  }
115
+ /**
116
+ * @interface
117
+ * @category SDK
118
+ * @subcategory DTO
119
+ * @property {string} user_id - The user's UUID.
120
+ * @property {string} email_id - The ID of the new email.
121
+ */
122
+ export interface UserCreated {
123
+ user_id: string;
124
+ email_id: string;
125
+ }
106
126
  /**
107
127
  * @interface
108
128
  * @category SDK
@@ -110,7 +130,7 @@ interface User {
110
130
  * @property {string} id - The UUID of the passcode.
111
131
  * @property {number} ttl - How long the code is active in seconds.
112
132
  */
113
- interface Passcode {
133
+ export interface Passcode {
114
134
  id: string;
115
135
  ttl: number;
116
136
  }
@@ -120,7 +140,7 @@ interface Passcode {
120
140
  * @subcategory DTO
121
141
  * @property {string[]} - Transports which may be used by the authenticator. E.g. "internal", "ble",...
122
142
  */
123
- interface WebauthnTransports extends Array<string> {
143
+ export interface WebauthnTransports extends Array<string> {
124
144
  }
125
145
  /**
126
146
  * @interface
@@ -129,7 +149,7 @@ interface WebauthnTransports extends Array<string> {
129
149
  * @property {WebauthnTransports} transports
130
150
  * @ignore
131
151
  */
132
- interface Attestation extends PublicKeyCredentialWithAttestationJSON {
152
+ export interface Attestation extends PublicKeyCredentialWithAttestationJSON {
133
153
  transports: WebauthnTransports;
134
154
  }
135
155
  /**
@@ -142,7 +162,7 @@ interface Attestation extends PublicKeyCredentialWithAttestationJSON {
142
162
  * @property {boolean} is_primary - Indicates it's the primary email address.
143
163
  * @property {Identity} identity - Indicates that this email is linked to a third party account.
144
164
  */
145
- interface Email {
165
+ export interface Email {
146
166
  id: string;
147
167
  address: string;
148
168
  is_verified: boolean;
@@ -155,7 +175,7 @@ interface Email {
155
175
  * @subcategory DTO
156
176
  * @property {Email[]} - A list of emails assigned to the current user.
157
177
  */
158
- interface Emails extends Array<Email> {
178
+ export interface Emails extends Array<Email> {
159
179
  }
160
180
  /**
161
181
  * @interface
@@ -170,7 +190,7 @@ interface Emails extends Array<Email> {
170
190
  * @property {string} created_at - Time of credential creation.
171
191
  * @property {WebauthnTransports} transports
172
192
  */
173
- interface WebauthnCredential {
193
+ export interface WebauthnCredential {
174
194
  id: string;
175
195
  name?: string;
176
196
  public_key: string;
@@ -186,7 +206,7 @@ interface WebauthnCredential {
186
206
  * @subcategory DTO
187
207
  * @property {WebauthnCredential[]} - A list of WebAuthn credential assigned to the current user.
188
208
  */
189
- interface WebauthnCredentials extends Array<WebauthnCredential> {
209
+ export interface WebauthnCredentials extends Array<WebauthnCredential> {
190
210
  }
191
211
  /**
192
212
  * @interface
@@ -195,8 +215,7 @@ interface WebauthnCredentials extends Array<WebauthnCredential> {
195
215
  * @property {id} - The subject ID with the third party provider.
196
216
  * @property {provider} - The third party provider name.
197
217
  */
198
- interface Identity {
218
+ export interface Identity {
199
219
  id: string;
200
220
  provider: string;
201
221
  }
202
- export type { PasswordConfig, Config, WebauthnFinalized, Credential, UserInfo, Me, User, Email, Emails, Passcode, Attestation, WebauthnCredential, WebauthnCredentials, Identity, };
@@ -0,0 +1,47 @@
1
+ import { SessionDetail } from "./events/CustomEvents";
2
+ import { SessionState } from "./state/session/SessionState";
3
+ import { Cookie } from "./Cookie";
4
+ /**
5
+ A class representing a session.
6
+
7
+ @category SDK
8
+ @subcategory Session
9
+ */
10
+ export declare class Session {
11
+ _sessionState: SessionState;
12
+ _cookie: Cookie;
13
+ constructor();
14
+ /**
15
+ Retrieves the session details.
16
+
17
+ @returns {SessionDetail} The session details.
18
+ */
19
+ get(): SessionDetail;
20
+ /**
21
+ Checks if the user is logged in.
22
+
23
+ @returns {boolean} true if the user is logged in, false otherwise.
24
+ */
25
+ isValid(): boolean;
26
+ /**
27
+ Retrieves the session details.
28
+
29
+ @ignore
30
+ @returns {SessionDetail} The session details.
31
+ */
32
+ _get(): SessionDetail;
33
+ /**
34
+ Checks if the auth flow is completed. The value resets after the next login attempt.
35
+
36
+ @returns {boolean} Returns true if the authentication flow is completed, false otherwise
37
+ */
38
+ isAuthFlowCompleted(): boolean;
39
+ /**
40
+ Validates the session.
41
+
42
+ @private
43
+ @param {SessionDetail} detail - The session details to validate.
44
+ @returns {boolean} true if the session details are valid, false otherwise.
45
+ */
46
+ private static validate;
47
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @interface
3
+ * @category SDK
4
+ * @subcategory Internal
5
+ * @property {boolean=} leading - Whether to allow the function to be called on the leading edge of the wait timeout.
6
+ * @property {boolean=} trailing - Whether to allow the function to be called on the trailing edge of the wait timeout.
7
+ */
8
+ interface ThrottleOptions {
9
+ leading?: boolean;
10
+ trailing?: boolean;
11
+ }
12
+ type ThrottledFunction<T extends (...args: any[]) => any> = (...args: Parameters<T>) => void;
13
+ /**
14
+ * Provides throttle functionality.
15
+ *
16
+ * @hideconstructor
17
+ * @category SDK
18
+ * @subcategory Internal
19
+ */
20
+ export declare class Throttle {
21
+ /**
22
+ * Throttles a function, ensuring that it can only be called once per `wait` milliseconds.
23
+ *
24
+ * @static
25
+ * @param {function} func - The function to throttle.
26
+ * @param {number} wait - The number of milliseconds to wait between function invocations.
27
+ * @param {ThrottleOptions} options - Optional configuration for the throttle.
28
+ * @returns {function} A throttled version of the original function.
29
+ */
30
+ static throttle<T extends (...args: any[]) => any>(func: T, wait: number, options?: ThrottleOptions): ThrottledFunction<T>;
31
+ }
32
+ export {};
@@ -26,9 +26,9 @@ declare class EmailClient extends Client {
26
26
  * @return {Promise<Email>}
27
27
  * @throws {EmailAddressAlreadyExistsError}
28
28
  * @throws {MaxNumOfEmailAddressesReachedError}
29
- * @throws {UnauthorizedError}
30
29
  * @throws {RequestTimeoutError}
31
30
  * @throws {TechnicalError}
31
+ * @throws {UnauthorizedError}
32
32
  * @see https://docs.hanko.io/api/public#tag/Email-Management/operation/createEmail
33
33
  */
34
34
  create(address: string): Promise<Email>;
@@ -37,9 +37,9 @@ declare class EmailClient extends Client {
37
37
  *
38
38
  * @param {string} emailID - The ID of the email address to be updated
39
39
  * @return {Promise<void>}
40
- * @throws {UnauthorizedError}
41
40
  * @throws {RequestTimeoutError}
42
41
  * @throws {TechnicalError}
42
+ * @throws {UnauthorizedError}
43
43
  * @see https://docs.hanko.io/api/public#tag/Email-Management/operation/setPrimaryEmail
44
44
  */
45
45
  setPrimaryEmail(emailID: string): Promise<void>;
@@ -48,9 +48,9 @@ declare class EmailClient extends Client {
48
48
  *
49
49
  * @param {string} emailID - The ID of the email address to be deleted
50
50
  * @return {Promise<void>}
51
- * @throws {UnauthorizedError}
52
51
  * @throws {RequestTimeoutError}
53
52
  * @throws {TechnicalError}
53
+ * @throws {UnauthorizedError}
54
54
  * @see https://docs.hanko.io/api/public#tag/Email-Management/operation/deleteEmail
55
55
  */
56
56
  delete(emailID: string): Promise<void>;
@@ -1,3 +1,7 @@
1
+ import { SessionState } from "../state/session/SessionState";
2
+ import { PasscodeState } from "../state/users/PasscodeState";
3
+ import { Dispatcher } from "../events/Dispatcher";
4
+ import { Cookie } from "../Cookie";
1
5
  /**
2
6
  * This class wraps an XMLHttpRequest to maintain compatibility with the fetch API.
3
7
  *
@@ -15,7 +19,7 @@ declare class Headers {
15
19
  * @param {string} name
16
20
  * @return {string}
17
21
  */
18
- get(name: string): string;
22
+ getResponseHeader(name: string): string;
19
23
  }
20
24
  /**
21
25
  * This class wraps an XMLHttpRequest to maintain compatibility with the fetch API.
@@ -32,7 +36,7 @@ declare class Response {
32
36
  statusText: string;
33
37
  url: string;
34
38
  _decodedJSON: any;
35
- private xhr;
39
+ xhr: XMLHttpRequest;
36
40
  constructor(xhr: XMLHttpRequest);
37
41
  /**
38
42
  * Returns the JSON decoded response.
@@ -41,11 +45,13 @@ declare class Response {
41
45
  */
42
46
  json(): any;
43
47
  /**
44
- * Returns the value for Retry-After contained in the response header.
48
+ * Returns the response header value with the given `name` as a number. When the value is not a number the return
49
+ * value will be 0.
45
50
  *
51
+ * @param {string} name - The name of the header field
46
52
  * @return {number}
47
53
  */
48
- parseRetryAfterHeader(): number;
54
+ parseNumericHeader(name: string): number;
49
55
  }
50
56
  /**
51
57
  * Internally used for communication with the Hanko API. It also handles authorization tokens to enable authorized
@@ -64,28 +70,20 @@ declare class Response {
64
70
  declare class HttpClient {
65
71
  timeout: number;
66
72
  api: string;
67
- authCookieName: string;
73
+ sessionState: SessionState;
74
+ passcodeState: PasscodeState;
75
+ dispatcher: Dispatcher;
76
+ cookie: Cookie;
68
77
  constructor(api: string, timeout?: number);
69
78
  _fetch(path: string, options: RequestInit, xhr?: XMLHttpRequest): Promise<Response>;
70
79
  /**
71
- * Returns the authentication token that was stored in the cookie.
80
+ * Processes the response headers on login and extracts the JWT and expiration time. Also, the passcode state will be
81
+ * removed, the session state updated und a `hanko-session-created` event will be dispatched.
72
82
  *
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.
83
+ * @param {string} userID - The user ID.
84
+ * @param {Response} response - The HTTP response object.
87
85
  */
88
- removeAuthCookie(): void;
86
+ processResponseHeadersOnLogin(userID: string, response: Response): void;
89
87
  /**
90
88
  * Performs a GET request.
91
89
  *
@@ -1,4 +1,4 @@
1
- import { PasscodeState } from "../state/PasscodeState";
1
+ import { PasscodeState } from "../state/users/PasscodeState";
2
2
  import { Passcode } from "../Dto";
3
3
  import { Client } from "./Client";
4
4
  /**
@@ -19,10 +19,9 @@ declare class PasscodeClient extends Client {
19
19
  * @param {string=} emailID - The UUID of the email address. If unspecified, the email will be sent to the primary email address.
20
20
  * @param {boolean=} force - Indicates the passcode should be sent, even if there is another active passcode.
21
21
  * @return {Promise<Passcode>}
22
- * @throws {TooManyRequestsError}
23
22
  * @throws {RequestTimeoutError}
24
- * @throws {UnauthorizedError}
25
23
  * @throws {TechnicalError}
24
+ * @throws {TooManyRequestsError}
26
25
  * @see https://docs.hanko.io/api/public#tag/Passcode/operation/passcodeInit
27
26
  */
28
27
  initialize(userID: string, emailID?: string, force?: boolean): Promise<Passcode>;
@@ -1,5 +1,5 @@
1
- import { PasswordState } from "../state/PasswordState";
2
- import { PasscodeState } from "../state/PasscodeState";
1
+ import { PasswordState } from "../state/users/PasswordState";
2
+ import { PasscodeState } from "../state/users/PasscodeState";
3
3
  import { Client } from "./Client";
4
4
  /**
5
5
  * A class to handle passwords.
@@ -19,9 +19,10 @@ declare class PasswordClient extends Client {
19
19
  * @param {string} userID - The UUID of the user.
20
20
  * @param {string} password - The password.
21
21
  * @return {Promise<void>}
22
- * @throws {TooManyRequestsError}
22
+ * @throws {InvalidPasswordError}
23
23
  * @throws {RequestTimeoutError}
24
24
  * @throws {TechnicalError}
25
+ * @throws {TooManyRequestsError}
25
26
  * @see https://docs.hanko.io/api/public#tag/Password/operation/passwordLogin
26
27
  */
27
28
  login(userID: string, password: string): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { User, UserInfo } from "../Dto";
1
+ import { User, UserInfo, UserCreated } from "../Dto";
2
2
  import { Client } from "./Client";
3
3
  /**
4
4
  * A class to manage user information.
@@ -26,13 +26,13 @@ declare class UserClient extends Client {
26
26
  * occurred, you may want to prompt the user to log in.
27
27
  *
28
28
  * @param {string} email - The email address of the user to be created.
29
- * @return {Promise<User>}
29
+ * @return {Promise<UserCreated>}
30
30
  * @throws {ConflictError}
31
31
  * @throws {RequestTimeoutError}
32
32
  * @throws {TechnicalError}
33
33
  * @see https://docs.hanko.io/api/public#tag/User-Management/operation/createUser
34
34
  */
35
- create(email: string): Promise<User>;
35
+ create(email: string): Promise<UserCreated>;
36
36
  /**
37
37
  * Fetches the current user.
38
38
  *
@@ -48,13 +48,16 @@ declare class UserClient extends Client {
48
48
  * Deletes the current user and expires the existing session cookie.
49
49
  *
50
50
  * @return {Promise<void>}
51
+ * @throws {RequestTimeoutError}
51
52
  * @throws {TechnicalError}
53
+ * @throws {UnauthorizedError}
52
54
  */
53
55
  delete(): Promise<void>;
54
56
  /**
55
57
  * Logs out the current user and expires the existing session cookie. A valid session cookie is required to call the logout endpoint.
56
58
  *
57
59
  * @return {Promise<void>}
60
+ * @throws {RequestTimeoutError}
58
61
  * @throws {TechnicalError}
59
62
  */
60
63
  logout(): Promise<void>;