@teamhanko/hanko-frontend-sdk 0.4.0-alpha → 0.5.4-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 +128 -9
- package/dist/Hanko.d.ts +5 -1
- package/dist/index.d.ts +5 -2
- package/dist/lib/Cookie.d.ts +26 -0
- package/dist/lib/Dto.d.ts +38 -19
- package/dist/lib/Throttle.d.ts +32 -0
- package/dist/lib/client/EmailClient.d.ts +3 -3
- package/dist/lib/client/HttpClient.d.ts +19 -21
- package/dist/lib/client/PasscodeClient.d.ts +2 -3
- package/dist/lib/client/PasswordClient.d.ts +4 -3
- package/dist/lib/client/UserClient.d.ts +6 -3
- package/dist/lib/client/WebauthnClient.d.ts +5 -6
- package/dist/lib/events/CustomEvents.d.ts +76 -0
- package/dist/lib/events/Dispatcher.d.ts +52 -0
- package/dist/lib/events/Listener.d.ts +137 -0
- package/dist/lib/events/Relay.d.ts +67 -0
- package/dist/lib/events/Scheduler.d.ts +43 -0
- package/dist/lib/state/State.d.ts +5 -3
- package/dist/lib/state/session/SessionState.d.ts +66 -0
- package/dist/lib/state/{PasscodeState.d.ts → users/PasscodeState.d.ts} +1 -1
- package/dist/lib/state/{UserState.d.ts → users/UserState.d.ts} +2 -1
- package/dist/lib/state/{WebauthnState.d.ts → users/WebauthnState.d.ts} +1 -1
- package/dist/sdk.cjs +1 -1
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.modern.js +1 -1
- package/dist/sdk.modern.js.map +1 -1
- package/dist/sdk.module.js +1 -1
- package/dist/sdk.module.js.map +1 -1
- package/dist/sdk.umd.js +1 -1
- package/dist/sdk.umd.js.map +1 -1
- package/package.json +2 -2
- /package/dist/lib/state/{PasswordState.d.ts → users/PasswordState.d.ts} +0 -0
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
|
-
###
|
|
50
|
+
### Client Classes
|
|
51
51
|
|
|
52
52
|
- `ConfigClient` - A class to fetch configurations.
|
|
53
53
|
- `UserClient` - A class to manage users.
|
|
@@ -57,23 +57,49 @@ 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
|
-
###
|
|
60
|
+
### Utility Classes
|
|
61
61
|
|
|
62
62
|
- `WebauthnSupport` - A class to check the browser's WebAuthn support.
|
|
63
63
|
|
|
64
|
-
###
|
|
64
|
+
### DTO Interfaces
|
|
65
65
|
|
|
66
|
-
- `Config`
|
|
67
66
|
- `PasswordConfig`
|
|
67
|
+
- `EmailConfig`
|
|
68
|
+
- `AccountConfig`
|
|
69
|
+
- `Config`
|
|
68
70
|
- `WebauthnFinalized`
|
|
69
|
-
- `
|
|
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
|
-
- `
|
|
82
|
+
- `WebauthnCredential`
|
|
83
|
+
- `WebauthnCredentials`
|
|
84
|
+
- `Identity`
|
|
85
|
+
|
|
86
|
+
### Event Interfaces
|
|
87
|
+
|
|
88
|
+
- `SessionCreatedEventDetail`
|
|
89
|
+
- `AuthFlowCompletedEventDetail`
|
|
90
|
+
|
|
91
|
+
### Event Types
|
|
92
|
+
|
|
93
|
+
- `CustomEventWithDetail`
|
|
94
|
+
- `authFlowCompletedType`
|
|
95
|
+
- `sessionResumedType`
|
|
96
|
+
- `sessionCreatedType`
|
|
97
|
+
- `sessionExpiredType`
|
|
98
|
+
- `sessionNotPresentType`
|
|
99
|
+
- `userLoggedOutType`
|
|
100
|
+
- `userDeletedType`
|
|
75
101
|
|
|
76
|
-
###
|
|
102
|
+
### Error Classes
|
|
77
103
|
|
|
78
104
|
- `HankoError`
|
|
79
105
|
- `TechnicalError`
|
|
@@ -100,7 +126,7 @@ not logged in:
|
|
|
100
126
|
```typescript
|
|
101
127
|
import { Hanko, UnauthorizedError } from "@teamhanko/hanko-frontend-sdk"
|
|
102
128
|
|
|
103
|
-
const hanko = new Hanko("
|
|
129
|
+
const hanko = new Hanko("https://[HANKO_API_URL]")
|
|
104
130
|
|
|
105
131
|
try {
|
|
106
132
|
const user = await hanko.user.getCurrent()
|
|
@@ -124,7 +150,7 @@ with a desktop computer:
|
|
|
124
150
|
```typescript
|
|
125
151
|
import { Hanko, UnauthorizedError, WebauthnRequestCancelledError } from "@teamhanko/hanko-frontend-sdk"
|
|
126
152
|
|
|
127
|
-
const hanko = new Hanko("
|
|
153
|
+
const hanko = new Hanko("https://[HANKO_API_URL]")
|
|
128
154
|
|
|
129
155
|
// By passing the user object (see example above) to `hanko.webauthn.shouldRegister(user)` you get an indication of
|
|
130
156
|
// whether a WebAuthn credential registration should be performed on the current browser. This is useful if the user has
|
|
@@ -145,6 +171,99 @@ try {
|
|
|
145
171
|
}
|
|
146
172
|
```
|
|
147
173
|
|
|
174
|
+
### Custom Events
|
|
175
|
+
|
|
176
|
+
You can bind callback functions to different custom events. The callback function will be called when the event happens
|
|
177
|
+
and an object will be passed in, containing event details. The event binding works as follows:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
// Controls the optional `once` parameter. When set to `true` the callback function will be called only once.
|
|
181
|
+
const once = false;
|
|
182
|
+
|
|
183
|
+
const removeEventListener = hanko.onSessionCreated((eventDetail) => {
|
|
184
|
+
// Your code...
|
|
185
|
+
}, once);
|
|
186
|
+
|
|
187
|
+
// Removes the event listener, the callback function will not be called anymore.
|
|
188
|
+
removeEventListener();
|
|
189
|
+
|
|
190
|
+
// Removes all event listeners.
|
|
191
|
+
hanko.removeEventListeners();
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
The following events are available:
|
|
195
|
+
|
|
196
|
+
- "hanko-auth-flow-completed": Will be triggered after a session has been created and the user has completed possible
|
|
197
|
+
additional steps (e.g. passkey registration or password recovery) via the `<hanko-auth>` element.
|
|
198
|
+
|
|
199
|
+
```js
|
|
200
|
+
hanko.onAuthFlowCompleted((authFlowCompletedDetail) => {
|
|
201
|
+
// Login, registration or recovery has been completed successfully. You can now take control and redirect the
|
|
202
|
+
// user to protected pages.
|
|
203
|
+
console.info(`User successfully completed the registration or authorization process (user-id: "${authFlowCompletedDetail.userID}")`);
|
|
204
|
+
})
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
- "hanko-session-created": Will be triggered before the "hanko-auth-flow-completed" happens, as soon as the user is technically logged in.
|
|
208
|
+
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
|
|
209
|
+
JWT is only available, when the Hanko API configuration allows to obtain the JWT. When using Hanko-Cloud
|
|
210
|
+
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
|
|
211
|
+
your backend runs under the same domain as your frontend. To do so, make sure the config parameter "session.enable_auth_token_header"
|
|
212
|
+
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
|
|
213
|
+
"session.enable_auth_token_header" when using a cross-domain setup. When it's a same-domain setup you need to turn off
|
|
214
|
+
"session.cookie.http_only" to make the JWT accessible to the frontend.
|
|
215
|
+
|
|
216
|
+
```js
|
|
217
|
+
hanko.onSessionCreated((sessionDetail) => {
|
|
218
|
+
// A new JWT has been issued.
|
|
219
|
+
console.info(`Session created or updated (user-id: "${sessionDetail.userID}", jwt: ${sessionDetail.jwt})`);
|
|
220
|
+
})
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
- "hanko-session-resumed": Will be triggered after the page has been loaded and there is a valid session, so it can be
|
|
224
|
+
utilized like the "hanko-auth-flow-completed" event, to restore the state of your page, where the user is logged in.
|
|
225
|
+
Note, that a "hanko-user-logged-out" event will be triggered instead of the "hanko-session-removed" event, after the
|
|
226
|
+
page has been loaded, when the user does not have a valid session.
|
|
227
|
+
|
|
228
|
+
```js
|
|
229
|
+
hanko.onSessionResumed((sessionDetail) => {
|
|
230
|
+
// The user is logged in, protected content can be shown.
|
|
231
|
+
console.info(`User is already logged in (user-id: "${sessionDetail.userID}", jwt: ${sessionDetail.jwt})`);
|
|
232
|
+
})
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
- "hanko-session-expired": Will be triggered when the session has expired, or when the session has been removed in
|
|
236
|
+
another browser window, because the user has logged out, or deleted the account.
|
|
237
|
+
|
|
238
|
+
```js
|
|
239
|
+
hanko.onSessionExpired(() => {
|
|
240
|
+
// You can redirect the user to a login page or show the `<hanko-auth>` element, or to prompt the user to log in again.
|
|
241
|
+
console.info("Session expired");
|
|
242
|
+
})
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
- "hanko-user-logged-out": Will be triggered, when the user actively logs out. In other browser windows, a "hanko-session-expired" event
|
|
246
|
+
will be triggered at the same time.
|
|
247
|
+
|
|
248
|
+
```js
|
|
249
|
+
hanko.onUserLoggedOut(() => {
|
|
250
|
+
// You can redirect the user to a login page or show the `<hanko-auth>` element.
|
|
251
|
+
console.info("User logged out");
|
|
252
|
+
})
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
- "hanko-user-deleted": Will be triggered when the user has deleted the account. In other browser windows, a "hanko-session-expired" event
|
|
256
|
+
will be triggered at the same time.
|
|
257
|
+
|
|
258
|
+
```js
|
|
259
|
+
hanko.onUserDeleted(() => {
|
|
260
|
+
// You can redirect the user to a login page or show the `<hanko-auth>` element.
|
|
261
|
+
console.info("User has been deleted");
|
|
262
|
+
})
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Please Take a look into the [docs](https://docs.hanko.io/jsdoc/hanko-frontend-sdk/Hanko.html) for more details.
|
|
266
|
+
|
|
148
267
|
## Bugs
|
|
149
268
|
|
|
150
269
|
Found a bug? Please report on our [GitHub](https://github.com/teamhanko/hanko/issues) page.
|
package/dist/Hanko.d.ts
CHANGED
|
@@ -6,13 +6,16 @@ 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";
|
|
9
11
|
/**
|
|
10
12
|
* A class that bundles all available SDK functions.
|
|
11
13
|
*
|
|
14
|
+
* @extends {Listener}
|
|
12
15
|
* @param {string} api - The URL of your Hanko API instance
|
|
13
16
|
* @param {number=} timeout - The request timeout in milliseconds
|
|
14
17
|
*/
|
|
15
|
-
declare class Hanko {
|
|
18
|
+
declare class Hanko extends Listener {
|
|
16
19
|
api: string;
|
|
17
20
|
config: ConfigClient;
|
|
18
21
|
user: UserClient;
|
|
@@ -22,6 +25,7 @@ declare class Hanko {
|
|
|
22
25
|
email: EmailClient;
|
|
23
26
|
thirdParty: ThirdPartyClient;
|
|
24
27
|
token: TokenClient;
|
|
28
|
+
relay: Relay;
|
|
25
29
|
constructor(api: string, timeout?: number);
|
|
26
30
|
}
|
|
27
31
|
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,
|
|
15
|
-
export type { PasswordConfig, Config, WebauthnFinalized,
|
|
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, SessionEventDetail, AuthFlowCompletedEventDetail, authFlowCompletedType, sessionCreatedType, sessionResumedType, sessionExpiredType, sessionNotPresentType, userLoggedOutType, userDeletedType } from "./lib/events/CustomEvents";
|
|
19
|
+
export type { SessionEventDetail, AuthFlowCompletedEventDetail };
|
|
20
|
+
export { authFlowCompletedType, sessionResumedType, sessionCreatedType, sessionExpiredType, sessionNotPresentType, 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
|
-
|
|
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,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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
74
|
-
* @
|
|
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
|
-
|
|
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 {
|
|
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<
|
|
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<
|
|
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>;
|