@teamhanko/hanko-frontend-sdk 0.2.1-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 +130 -9
- package/dist/Hanko.d.ts +7 -1
- package/dist/index.d.ts +7 -3
- package/dist/lib/Cookie.d.ts +26 -0
- package/dist/lib/Dto.d.ts +48 -18
- 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/TokenClient.d.ts +22 -0
- package/dist/lib/client/UserClient.d.ts +13 -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 +4 -4
- /package/dist/lib/state/{PasswordState.d.ts → users/PasswordState.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -47,31 +47,59 @@ 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.
|
|
54
54
|
- `WebauthnClient` - A class to handle WebAuthn-related functionalities.
|
|
55
55
|
- `PasswordClient` - A class to manage passwords and password logins.
|
|
56
56
|
- `PasscodeClient` - A class to handle passcode logins.
|
|
57
|
+
- `ThirdPartyClient` - A class to handle social logins.
|
|
58
|
+
- `TokenClient` - A class that handles the exchange of one time tokens for session JWTs.
|
|
57
59
|
|
|
58
|
-
###
|
|
60
|
+
### Utility Classes
|
|
59
61
|
|
|
60
62
|
- `WebauthnSupport` - A class to check the browser's WebAuthn support.
|
|
61
63
|
|
|
62
|
-
###
|
|
64
|
+
### DTO Interfaces
|
|
63
65
|
|
|
64
|
-
- `Config`
|
|
65
66
|
- `PasswordConfig`
|
|
67
|
+
- `EmailConfig`
|
|
68
|
+
- `AccountConfig`
|
|
69
|
+
- `Config`
|
|
66
70
|
- `WebauthnFinalized`
|
|
67
|
-
- `
|
|
71
|
+
- `TokenFinalized`
|
|
68
72
|
- `UserInfo`
|
|
73
|
+
- `Me`
|
|
74
|
+
- `Credential`
|
|
69
75
|
- `User`
|
|
76
|
+
- `UserCreated`
|
|
77
|
+
- `Passcode`
|
|
78
|
+
- `WebauthnTransports`
|
|
79
|
+
- `Attestation`
|
|
70
80
|
- `Email`
|
|
71
81
|
- `Emails`
|
|
72
|
-
- `
|
|
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`
|
|
73
101
|
|
|
74
|
-
###
|
|
102
|
+
### Error Classes
|
|
75
103
|
|
|
76
104
|
- `HankoError`
|
|
77
105
|
- `TechnicalError`
|
|
@@ -98,7 +126,7 @@ not logged in:
|
|
|
98
126
|
```typescript
|
|
99
127
|
import { Hanko, UnauthorizedError } from "@teamhanko/hanko-frontend-sdk"
|
|
100
128
|
|
|
101
|
-
const hanko = new Hanko("
|
|
129
|
+
const hanko = new Hanko("https://[HANKO_API_URL]")
|
|
102
130
|
|
|
103
131
|
try {
|
|
104
132
|
const user = await hanko.user.getCurrent()
|
|
@@ -122,7 +150,7 @@ with a desktop computer:
|
|
|
122
150
|
```typescript
|
|
123
151
|
import { Hanko, UnauthorizedError, WebauthnRequestCancelledError } from "@teamhanko/hanko-frontend-sdk"
|
|
124
152
|
|
|
125
|
-
const hanko = new Hanko("
|
|
153
|
+
const hanko = new Hanko("https://[HANKO_API_URL]")
|
|
126
154
|
|
|
127
155
|
// By passing the user object (see example above) to `hanko.webauthn.shouldRegister(user)` you get an indication of
|
|
128
156
|
// whether a WebAuthn credential registration should be performed on the current browser. This is useful if the user has
|
|
@@ -143,6 +171,99 @@ try {
|
|
|
143
171
|
}
|
|
144
172
|
```
|
|
145
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
|
+
|
|
146
267
|
## Bugs
|
|
147
268
|
|
|
148
269
|
Found a bug? Please report on our [GitHub](https://github.com/teamhanko/hanko/issues) page.
|
package/dist/Hanko.d.ts
CHANGED
|
@@ -5,13 +5,17 @@ import { UserClient } from "./lib/client/UserClient";
|
|
|
5
5
|
import { WebauthnClient } from "./lib/client/WebauthnClient";
|
|
6
6
|
import { EmailClient } from "./lib/client/EmailClient";
|
|
7
7
|
import { ThirdPartyClient } from "./lib/client/ThirdPartyClient";
|
|
8
|
+
import { TokenClient } from "./lib/client/TokenClient";
|
|
9
|
+
import { Listener } from "./lib/events/Listener";
|
|
10
|
+
import { Relay } from "./lib/events/Relay";
|
|
8
11
|
/**
|
|
9
12
|
* A class that bundles all available SDK functions.
|
|
10
13
|
*
|
|
14
|
+
* @extends {Listener}
|
|
11
15
|
* @param {string} api - The URL of your Hanko API instance
|
|
12
16
|
* @param {number=} timeout - The request timeout in milliseconds
|
|
13
17
|
*/
|
|
14
|
-
declare class Hanko {
|
|
18
|
+
declare class Hanko extends Listener {
|
|
15
19
|
api: string;
|
|
16
20
|
config: ConfigClient;
|
|
17
21
|
user: UserClient;
|
|
@@ -20,6 +24,8 @@ declare class Hanko {
|
|
|
20
24
|
passcode: PasscodeClient;
|
|
21
25
|
email: EmailClient;
|
|
22
26
|
thirdParty: ThirdPartyClient;
|
|
27
|
+
token: TokenClient;
|
|
28
|
+
relay: Relay;
|
|
23
29
|
constructor(api: string, timeout?: number);
|
|
24
30
|
}
|
|
25
31
|
export { Hanko };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,10 +7,14 @@ import { UserClient } from "./lib/client/UserClient";
|
|
|
7
7
|
import { WebauthnClient } from "./lib/client/WebauthnClient";
|
|
8
8
|
import { EmailClient } from "./lib/client/EmailClient";
|
|
9
9
|
import { ThirdPartyClient } from "./lib/client/ThirdPartyClient";
|
|
10
|
-
|
|
10
|
+
import { TokenClient } from "./lib/client/TokenClient";
|
|
11
|
+
export { ConfigClient, UserClient, WebauthnClient, PasswordClient, PasscodeClient, EmailClient, ThirdPartyClient, TokenClient, };
|
|
11
12
|
import { WebauthnSupport } from "./lib/WebauthnSupport";
|
|
12
13
|
export { WebauthnSupport };
|
|
13
|
-
import { PasswordConfig, Config, WebauthnFinalized,
|
|
14
|
-
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, };
|
|
15
16
|
import { HankoError, ConflictError, EmailAddressAlreadyExistsError, InvalidPasswordError, InvalidPasscodeError, InvalidWebauthnCredentialError, MaxNumOfEmailAddressesReachedError, MaxNumOfPasscodeAttemptsReachedError, NotFoundError, PasscodeExpiredError, RequestTimeoutError, TechnicalError, ThirdPartyError, TooManyRequestsError, UnauthorizedError, UserVerificationError, WebauthnRequestCancelledError } from "./lib/Errors";
|
|
16
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,10 +17,19 @@ 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
|
}
|
|
24
|
+
/**
|
|
25
|
+
* @interface
|
|
26
|
+
* @category SDK
|
|
27
|
+
* @subcategory DTO
|
|
28
|
+
* @property {boolean} allow_deletion - Indicates the current user is allowed to delete the account.
|
|
29
|
+
*/
|
|
30
|
+
export interface AccountConfig {
|
|
31
|
+
allow_deletion: boolean;
|
|
32
|
+
}
|
|
24
33
|
/**
|
|
25
34
|
* @interface
|
|
26
35
|
* @category SDK
|
|
@@ -28,11 +37,13 @@ interface EmailConfig {
|
|
|
28
37
|
* @property {PasswordConfig} password - The password configuration.
|
|
29
38
|
* @property {EmailConfig} emails - The email configuration.
|
|
30
39
|
* @property {string[]} providers - The enabled third party providers.
|
|
40
|
+
* @property {AccountConfig} account - Controls the behaviour regarding user accounts.
|
|
31
41
|
*/
|
|
32
|
-
interface Config {
|
|
42
|
+
export interface Config {
|
|
33
43
|
password: PasswordConfig;
|
|
34
44
|
emails: EmailConfig;
|
|
35
45
|
providers: string[];
|
|
46
|
+
account: AccountConfig;
|
|
36
47
|
}
|
|
37
48
|
/**
|
|
38
49
|
* @interface
|
|
@@ -41,10 +52,19 @@ interface Config {
|
|
|
41
52
|
* @property {string} credential_id - The ID of the credential that was used.
|
|
42
53
|
* @property {string} user_id - The ID of the user that was used.
|
|
43
54
|
*/
|
|
44
|
-
interface WebauthnFinalized {
|
|
55
|
+
export interface WebauthnFinalized {
|
|
45
56
|
credential_id: string;
|
|
46
57
|
user_id: string;
|
|
47
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
|
+
}
|
|
48
68
|
/**
|
|
49
69
|
* @interface
|
|
50
70
|
* @category SDK
|
|
@@ -54,7 +74,7 @@ interface WebauthnFinalized {
|
|
|
54
74
|
* @property {string} email_id - The UUID of the email address.
|
|
55
75
|
* @property {boolean} has_webauthn_credential - Indicates that the user has registered a WebAuthn credential in the past.
|
|
56
76
|
*/
|
|
57
|
-
interface UserInfo {
|
|
77
|
+
export interface UserInfo {
|
|
58
78
|
id: string;
|
|
59
79
|
verified: boolean;
|
|
60
80
|
email_id: string;
|
|
@@ -67,7 +87,7 @@ interface UserInfo {
|
|
|
67
87
|
* @property {string} id - The UUID of the current user.
|
|
68
88
|
* @ignore
|
|
69
89
|
*/
|
|
70
|
-
interface Me {
|
|
90
|
+
export interface Me {
|
|
71
91
|
id: string;
|
|
72
92
|
}
|
|
73
93
|
/**
|
|
@@ -76,7 +96,7 @@ interface Me {
|
|
|
76
96
|
* @subcategory DTO
|
|
77
97
|
* @property {string} id - The WebAuthn credential ID.
|
|
78
98
|
*/
|
|
79
|
-
interface Credential {
|
|
99
|
+
export interface Credential {
|
|
80
100
|
id: string;
|
|
81
101
|
}
|
|
82
102
|
/**
|
|
@@ -87,11 +107,22 @@ interface Credential {
|
|
|
87
107
|
* @property {string} email - The user's email.
|
|
88
108
|
* @property {Credential[]} webauthn_credentials - A list of credentials that have been registered.
|
|
89
109
|
*/
|
|
90
|
-
interface User {
|
|
110
|
+
export interface User {
|
|
91
111
|
id: string;
|
|
92
|
-
|
|
112
|
+
email: string;
|
|
93
113
|
webauthn_credentials: Credential[];
|
|
94
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
|
+
}
|
|
95
126
|
/**
|
|
96
127
|
* @interface
|
|
97
128
|
* @category SDK
|
|
@@ -99,7 +130,7 @@ interface User {
|
|
|
99
130
|
* @property {string} id - The UUID of the passcode.
|
|
100
131
|
* @property {number} ttl - How long the code is active in seconds.
|
|
101
132
|
*/
|
|
102
|
-
interface Passcode {
|
|
133
|
+
export interface Passcode {
|
|
103
134
|
id: string;
|
|
104
135
|
ttl: number;
|
|
105
136
|
}
|
|
@@ -109,7 +140,7 @@ interface Passcode {
|
|
|
109
140
|
* @subcategory DTO
|
|
110
141
|
* @property {string[]} - Transports which may be used by the authenticator. E.g. "internal", "ble",...
|
|
111
142
|
*/
|
|
112
|
-
interface WebauthnTransports extends Array<string> {
|
|
143
|
+
export interface WebauthnTransports extends Array<string> {
|
|
113
144
|
}
|
|
114
145
|
/**
|
|
115
146
|
* @interface
|
|
@@ -118,7 +149,7 @@ interface WebauthnTransports extends Array<string> {
|
|
|
118
149
|
* @property {WebauthnTransports} transports
|
|
119
150
|
* @ignore
|
|
120
151
|
*/
|
|
121
|
-
interface Attestation extends PublicKeyCredentialWithAttestationJSON {
|
|
152
|
+
export interface Attestation extends PublicKeyCredentialWithAttestationJSON {
|
|
122
153
|
transports: WebauthnTransports;
|
|
123
154
|
}
|
|
124
155
|
/**
|
|
@@ -131,7 +162,7 @@ interface Attestation extends PublicKeyCredentialWithAttestationJSON {
|
|
|
131
162
|
* @property {boolean} is_primary - Indicates it's the primary email address.
|
|
132
163
|
* @property {Identity} identity - Indicates that this email is linked to a third party account.
|
|
133
164
|
*/
|
|
134
|
-
interface Email {
|
|
165
|
+
export interface Email {
|
|
135
166
|
id: string;
|
|
136
167
|
address: string;
|
|
137
168
|
is_verified: boolean;
|
|
@@ -144,7 +175,7 @@ interface Email {
|
|
|
144
175
|
* @subcategory DTO
|
|
145
176
|
* @property {Email[]} - A list of emails assigned to the current user.
|
|
146
177
|
*/
|
|
147
|
-
interface Emails extends Array<Email> {
|
|
178
|
+
export interface Emails extends Array<Email> {
|
|
148
179
|
}
|
|
149
180
|
/**
|
|
150
181
|
* @interface
|
|
@@ -159,7 +190,7 @@ interface Emails extends Array<Email> {
|
|
|
159
190
|
* @property {string} created_at - Time of credential creation.
|
|
160
191
|
* @property {WebauthnTransports} transports
|
|
161
192
|
*/
|
|
162
|
-
interface WebauthnCredential {
|
|
193
|
+
export interface WebauthnCredential {
|
|
163
194
|
id: string;
|
|
164
195
|
name?: string;
|
|
165
196
|
public_key: string;
|
|
@@ -175,7 +206,7 @@ interface WebauthnCredential {
|
|
|
175
206
|
* @subcategory DTO
|
|
176
207
|
* @property {WebauthnCredential[]} - A list of WebAuthn credential assigned to the current user.
|
|
177
208
|
*/
|
|
178
|
-
interface WebauthnCredentials extends Array<WebauthnCredential> {
|
|
209
|
+
export interface WebauthnCredentials extends Array<WebauthnCredential> {
|
|
179
210
|
}
|
|
180
211
|
/**
|
|
181
212
|
* @interface
|
|
@@ -184,8 +215,7 @@ interface WebauthnCredentials extends Array<WebauthnCredential> {
|
|
|
184
215
|
* @property {id} - The subject ID with the third party provider.
|
|
185
216
|
* @property {provider} - The third party provider name.
|
|
186
217
|
*/
|
|
187
|
-
interface Identity {
|
|
218
|
+
export interface Identity {
|
|
188
219
|
id: string;
|
|
189
220
|
provider: string;
|
|
190
221
|
}
|
|
191
|
-
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>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Client } from "./Client";
|
|
2
|
+
/**
|
|
3
|
+
* Client responsible for exchanging one time tokens for session JWTs.
|
|
4
|
+
*
|
|
5
|
+
* @constructor
|
|
6
|
+
* @category SDK
|
|
7
|
+
* @subcategory Clients
|
|
8
|
+
* @extends {Client}
|
|
9
|
+
*/
|
|
10
|
+
export declare class TokenClient extends Client {
|
|
11
|
+
constructor(api: string, timeout?: number);
|
|
12
|
+
/**
|
|
13
|
+
* Validate a one time token to retrieve a session JWT. Does nothing
|
|
14
|
+
* if the current window location does not contain a 'hanko_token' in the
|
|
15
|
+
* search query.
|
|
16
|
+
*
|
|
17
|
+
* @return {Promise<void>}
|
|
18
|
+
* @throws {TechnicalError}
|
|
19
|
+
* https://docs.hanko.io/api/api/public#tag/Token/operation/token
|
|
20
|
+
*/
|
|
21
|
+
validate(): Promise<void>;
|
|
22
|
+
}
|