@teamhanko/hanko-frontend-sdk 0.12.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +6 -52
  2. package/dist/Hanko.d.ts +2 -8
  3. package/dist/index.d.ts +4 -8
  4. package/dist/lib/Session.d.ts +1 -1
  5. package/dist/lib/client/HttpClient.d.ts +3 -7
  6. package/dist/lib/events/CustomEvents.d.ts +9 -16
  7. package/dist/lib/events/Dispatcher.d.ts +1 -7
  8. package/dist/lib/events/Listener.d.ts +1 -9
  9. package/dist/lib/flow-api/BrowserFlowStorage.d.ts +6 -0
  10. package/dist/lib/flow-api/Flow.d.ts +40 -0
  11. package/dist/lib/flow-api/State.d.ts +69 -0
  12. package/dist/lib/flow-api/types/action.d.ts +92 -0
  13. package/dist/lib/flow-api/types/error.d.ts +6 -0
  14. package/dist/lib/flow-api/types/input.d.ts +77 -0
  15. package/dist/lib/flow-api/types/payload.d.ts +60 -0
  16. package/dist/lib/flow-api/types/state-handling.d.ts +54 -0
  17. package/dist/lib/state/State.d.ts +0 -2
  18. package/dist/lib/state/session/SessionState.d.ts +0 -12
  19. package/dist/sdk.cjs +1 -1
  20. package/dist/sdk.cjs.map +1 -1
  21. package/dist/sdk.modern.js +1 -1
  22. package/dist/sdk.modern.js.map +1 -1
  23. package/dist/sdk.module.js +1 -1
  24. package/dist/sdk.module.js.map +1 -1
  25. package/dist/sdk.umd.js +1 -1
  26. package/dist/sdk.umd.js.map +1 -1
  27. package/package.json +1 -1
  28. package/dist/lib/client/ConfigClient.d.ts +0 -20
  29. package/dist/lib/client/PasscodeClient.d.ts +0 -57
  30. package/dist/lib/client/PasswordClient.d.ts +0 -50
  31. package/dist/lib/client/WebauthnClient.d.ts +0 -97
  32. package/dist/lib/state/users/PasscodeState.d.ts +0 -108
  33. package/dist/lib/state/users/PasswordState.d.ts +0 -50
  34. package/dist/lib/state/users/UserState.d.ts +0 -51
  35. package/dist/lib/state/users/WebauthnState.d.ts +0 -60
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamhanko/hanko-frontend-sdk",
3
- "version": "0.12.0",
3
+ "version": "1.0.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,20 +0,0 @@
1
- import { Config } from "../Dto";
2
- import { Client } from "./Client";
3
- /**
4
- * A class for retrieving configurations from the API.
5
- *
6
- * @category SDK
7
- * @subcategory Clients
8
- * @extends {Client}
9
- */
10
- declare class ConfigClient extends Client {
11
- /**
12
- * Retrieves the frontend configuration.
13
- * @return {Promise<Config>}
14
- * @throws {RequestTimeoutError}
15
- * @throws {TechnicalError}
16
- * @see https://docs.hanko.io/api/public#tag/.well-known/operation/getConfig
17
- */
18
- get(): Promise<Config>;
19
- }
20
- export { ConfigClient };
@@ -1,57 +0,0 @@
1
- import { PasscodeState } from "../state/users/PasscodeState";
2
- import { Passcode } from "../Dto";
3
- import { Client } from "./Client";
4
- import { HttpClientOptions } from "./HttpClient";
5
- /**
6
- * A class to handle passcodes.
7
- *
8
- * @constructor
9
- * @category SDK
10
- * @subcategory Clients
11
- * @extends {Client}
12
- */
13
- declare class PasscodeClient extends Client {
14
- state: PasscodeState;
15
- constructor(api: string, options: HttpClientOptions);
16
- /**
17
- * Causes the API to send a new passcode to the user's email address.
18
- *
19
- * @param {string} userID - The UUID of the user.
20
- * @param {string=} emailID - The UUID of the email address. If unspecified, the email will be sent to the primary email address.
21
- * @param {boolean=} force - Indicates the passcode should be sent, even if there is another active passcode.
22
- * @return {Promise<Passcode>}
23
- * @throws {RequestTimeoutError}
24
- * @throws {TechnicalError}
25
- * @throws {TooManyRequestsError}
26
- * @see https://docs.hanko.io/api/public#tag/Passcode/operation/passcodeInit
27
- */
28
- initialize(userID: string, emailID?: string, force?: boolean): Promise<Passcode>;
29
- /**
30
- * Validates the passcode obtained from the email.
31
- *
32
- * @param {string} userID - The UUID of the user.
33
- * @param {string} code - The passcode digests.
34
- * @return {Promise<void>}
35
- * @throws {InvalidPasscodeError}
36
- * @throws {MaxNumOfPasscodeAttemptsReachedError}
37
- * @throws {RequestTimeoutError}
38
- * @throws {TechnicalError}
39
- * @see https://docs.hanko.io/api/public#tag/Passcode/operation/passcodeFinal
40
- */
41
- finalize(userID: string, code: string): Promise<void>;
42
- /**
43
- * Returns the number of seconds the current passcode is active for.
44
- *
45
- * @param {string} userID - The UUID of the user.
46
- * @return {number}
47
- */
48
- getTTL(userID: string): number;
49
- /**
50
- * Returns the number of seconds the rate limiting is active for.
51
- *
52
- * @param {string} userID - The UUID of the user.
53
- * @return {number}
54
- */
55
- getResendAfter(userID: string): number;
56
- }
57
- export { PasscodeClient };
@@ -1,50 +0,0 @@
1
- import { PasswordState } from "../state/users/PasswordState";
2
- import { PasscodeState } from "../state/users/PasscodeState";
3
- import { Client } from "./Client";
4
- import { HttpClientOptions } from "./HttpClient";
5
- /**
6
- * A class to handle passwords.
7
- *
8
- * @constructor
9
- * @category SDK
10
- * @subcategory Clients
11
- * @extends {Client}
12
- */
13
- declare class PasswordClient extends Client {
14
- passwordState: PasswordState;
15
- passcodeState: PasscodeState;
16
- constructor(api: string, options: HttpClientOptions);
17
- /**
18
- * Logs in a user with a password.
19
- *
20
- * @param {string} userID - The UUID of the user.
21
- * @param {string} password - The password.
22
- * @return {Promise<void>}
23
- * @throws {InvalidPasswordError}
24
- * @throws {RequestTimeoutError}
25
- * @throws {TechnicalError}
26
- * @throws {TooManyRequestsError}
27
- * @see https://docs.hanko.io/api/public#tag/Password/operation/passwordLogin
28
- */
29
- login(userID: string, password: string): Promise<void>;
30
- /**
31
- * Updates a password.
32
- *
33
- * @param {string} userID - The UUID of the user.
34
- * @param {string} password - The new password.
35
- * @return {Promise<void>}
36
- * @throws {RequestTimeoutError}
37
- * @throws {UnauthorizedError}
38
- * @throws {TechnicalError}
39
- * @see https://docs.hanko.io/api/public#tag/Password/operation/password
40
- */
41
- update(userID: string, password: string): Promise<void>;
42
- /**
43
- * Returns the number of seconds the rate limiting is active for.
44
- *
45
- * @param {string} userID - The UUID of the user.
46
- * @return {number}
47
- */
48
- getRetryAfter(userID: string): number;
49
- }
50
- export { PasswordClient };
@@ -1,97 +0,0 @@
1
- import { create as createWebauthnCredential, get as getWebauthnCredential } from "@github/webauthn-json";
2
- import { Client } from "./Client";
3
- import { PasscodeState } from "../state/users/PasscodeState";
4
- import { WebauthnState } from "../state/users/WebauthnState";
5
- import { User, WebauthnCredentials, WebauthnFinalized } from "../Dto";
6
- import { HttpClientOptions } from "./HttpClient";
7
- /**
8
- * A class that handles WebAuthn authentication and registration.
9
- *
10
- * @constructor
11
- * @category SDK
12
- * @subcategory Clients
13
- * @extends {Client}
14
- */
15
- declare class WebauthnClient extends Client {
16
- webauthnState: WebauthnState;
17
- passcodeState: PasscodeState;
18
- controller: AbortController;
19
- _getCredential: typeof getWebauthnCredential;
20
- _createCredential: typeof createWebauthnCredential;
21
- constructor(api: string, options: HttpClientOptions);
22
- /**
23
- * Performs a WebAuthn authentication ceremony. When 'userID' is specified, the API provides a list of
24
- * allowed credentials and the browser is able to present a list of suitable credentials to the user.
25
- *
26
- * @param {string=} userID - The user's UUID.
27
- * @param {boolean=} useConditionalMediation - Enables autofill assisted login.
28
- * @return {Promise<void>}
29
- * @throws {WebauthnRequestCancelledError}
30
- * @throws {InvalidWebauthnCredentialError}
31
- * @throws {RequestTimeoutError}
32
- * @throws {TechnicalError}
33
- * @see https://docs.hanko.io/api/public#tag/WebAuthn/operation/webauthnLoginInit
34
- * @see https://docs.hanko.io/api/public#tag/WebAuthn/operation/webauthnLoginFinal
35
- * @see https://www.w3.org/TR/webauthn-2/#authentication-ceremony
36
- * @return {WebauthnFinalized}
37
- */
38
- login(userID?: string, useConditionalMediation?: boolean): Promise<WebauthnFinalized>;
39
- /**
40
- * Performs a WebAuthn registration ceremony.
41
- *
42
- * @return {Promise<void>}
43
- * @throws {WebauthnRequestCancelledError}
44
- * @throws {RequestTimeoutError}
45
- * @throws {UnauthorizedError}
46
- * @throws {TechnicalError}
47
- * @throws {UserVerificationError}
48
- * @see https://docs.hanko.io/api/public#tag/WebAuthn/operation/webauthnRegInit
49
- * @see https://docs.hanko.io/api/public#tag/WebAuthn/operation/webauthnRegFinal
50
- * @see https://www.w3.org/TR/webauthn-2/#sctn-registering-a-new-credential
51
- */
52
- register(): Promise<void>;
53
- /**
54
- * Returns a list of all WebAuthn credentials assigned to the current user.
55
- *
56
- * @return {Promise<WebauthnCredentials>}
57
- * @throws {UnauthorizedError}
58
- * @throws {RequestTimeoutError}
59
- * @throws {TechnicalError}
60
- * @see https://docs.hanko.io/api/public#tag/WebAuthn/operation/listCredentials
61
- */
62
- listCredentials(): Promise<WebauthnCredentials>;
63
- /**
64
- * Updates the WebAuthn credential.
65
- *
66
- * @param {string=} credentialID - The credential's UUID.
67
- * @param {string} name - The new credential name.
68
- * @return {Promise<void>}
69
- * @throws {UnauthorizedError}
70
- * @throws {RequestTimeoutError}
71
- * @throws {TechnicalError}
72
- * @see https://docs.hanko.io/api/public#tag/WebAuthn/operation/updateCredential
73
- */
74
- updateCredential(credentialID: string, name: string): Promise<void>;
75
- /**
76
- * Deletes the WebAuthn credential.
77
- *
78
- * @param {string=} credentialID - The credential's UUID.
79
- * @return {Promise<void>}
80
- * @throws {UnauthorizedError}
81
- * @throws {RequestTimeoutError}
82
- * @throws {TechnicalError}
83
- * @see https://docs.hanko.io/api/public#tag/WebAuthn/operation/deleteCredential
84
- */
85
- deleteCredential(credentialID: string): Promise<void>;
86
- /**
87
- * Determines whether a credential registration ceremony should be performed. Returns 'true' when WebAuthn
88
- * is supported and the user's credentials do not intersect with the credentials already known on the
89
- * current browser/device.
90
- *
91
- * @param {User} user - The user object.
92
- * @return {Promise<boolean>}
93
- */
94
- shouldRegister(user: User): Promise<boolean>;
95
- _createAbortSignal(): AbortSignal;
96
- }
97
- export { WebauthnClient };
@@ -1,108 +0,0 @@
1
- import { UserState } from "./UserState";
2
- /**
3
- * @interface
4
- * @category SDK
5
- * @subcategory Internal
6
- * @property {string=} id - The UUID of the active passcode.
7
- * @property {number=} ttl - Timestamp until when the passcode is valid in seconds (since January 1, 1970 00:00:00 UTC).
8
- * @property {number=} resendAfter - Seconds until a passcode can be resent.
9
- * @property {emailID=} emailID - The email address ID.
10
- */
11
- export interface LocalStoragePasscode {
12
- id?: string;
13
- ttl?: number;
14
- resendAfter?: number;
15
- emailID?: string;
16
- }
17
- /**
18
- * A class that manages passcodes via local storage.
19
- *
20
- * @extends UserState
21
- * @category SDK
22
- * @subcategory Internal
23
- */
24
- declare class PasscodeState extends UserState {
25
- /**
26
- * Get the passcode state.
27
- *
28
- * @private
29
- * @param {string} userID - The UUID of the user.
30
- * @return {LocalStoragePasscode}
31
- */
32
- private getState;
33
- /**
34
- * Reads the current state.
35
- *
36
- * @public
37
- * @return {PasscodeState}
38
- */
39
- read(): PasscodeState;
40
- /**
41
- * Gets the UUID of the active passcode.
42
- *
43
- * @param {string} userID - The UUID of the user.
44
- * @return {string}
45
- */
46
- getActiveID(userID: string): string;
47
- /**
48
- * Sets the UUID of the active passcode.
49
- *
50
- * @param {string} userID - The UUID of the user.
51
- * @param {string} passcodeID - The UUID of the passcode to be set as active.
52
- * @return {PasscodeState}
53
- */
54
- setActiveID(userID: string, passcodeID: string): PasscodeState;
55
- /**
56
- * Gets the UUID of the email address.
57
- *
58
- * @param {string} userID - The UUID of the user.
59
- * @return {string}
60
- */
61
- getEmailID(userID: string): string;
62
- /**
63
- * Sets the UUID of the email address.
64
- *
65
- * @param {string} userID - The UUID of the user.
66
- * @param {string} emailID - The UUID of the email address.
67
- * @return {PasscodeState}
68
- */
69
- setEmailID(userID: string, emailID: string): PasscodeState;
70
- /**
71
- * Removes the active passcode.
72
- *
73
- * @param {string} userID - The UUID of the user.
74
- * @return {PasscodeState}
75
- */
76
- reset(userID: string): PasscodeState;
77
- /**
78
- * Gets the TTL in seconds. When the seconds expire, the code is invalid.
79
- *
80
- * @param {string} userID - The UUID of the user.
81
- * @return {number}
82
- */
83
- getTTL(userID: string): number;
84
- /**
85
- * Sets the passcode's TTL and stores it to the local storage.
86
- *
87
- * @param {string} userID - The UUID of the user.
88
- * @param {string} seconds - Number of seconds the passcode is valid for.
89
- * @return {PasscodeState}
90
- */
91
- setTTL(userID: string, seconds: number): PasscodeState;
92
- /**
93
- * Gets the number of seconds until when the next passcode can be sent.
94
- *
95
- * @param {string} userID - The UUID of the user.
96
- * @return {number}
97
- */
98
- getResendAfter(userID: string): number;
99
- /**
100
- * Sets the number of seconds until a new passcode can be sent.
101
- *
102
- * @param {string} userID - The UUID of the user.
103
- * @param {number} seconds - Number of seconds the passcode is valid for.
104
- * @return {PasscodeState}
105
- */
106
- setResendAfter(userID: string, seconds: number): PasscodeState;
107
- }
108
- export { PasscodeState };
@@ -1,50 +0,0 @@
1
- import { UserState } from "./UserState";
2
- /**
3
- * @interface
4
- * @category SDK
5
- * @subcategory Internal
6
- * @property {number=} retryAfter - Timestamp (in seconds since January 1, 1970 00:00:00 UTC) indicating when the next password login can be attempted.
7
- */
8
- export interface LocalStoragePassword {
9
- retryAfter?: number;
10
- }
11
- /**
12
- * A class that manages the password login state.
13
- *
14
- * @extends UserState
15
- * @category SDK
16
- * @subcategory Internal
17
- */
18
- declare class PasswordState extends UserState {
19
- /**
20
- * Get the password state.
21
- *
22
- * @private
23
- * @param {string} userID - The UUID of the user.
24
- * @return {LocalStoragePassword}
25
- */
26
- private getState;
27
- /**
28
- * Reads the current state.
29
- *
30
- * @public
31
- * @return {PasswordState}
32
- */
33
- read(): PasswordState;
34
- /**
35
- * Gets the number of seconds until when a new password login can be attempted.
36
- *
37
- * @param {string} userID - The UUID of the user.
38
- * @return {number}
39
- */
40
- getRetryAfter(userID: string): number;
41
- /**
42
- * Sets the number of seconds until a new password login can be attempted.
43
- *
44
- * @param {string} userID - The UUID of the user.
45
- * @param {string} seconds - Number of seconds the passcode is valid for.
46
- * @return {PasswordState}
47
- */
48
- setRetryAfter(userID: string, seconds: number): PasswordState;
49
- }
50
- export { PasswordState };
@@ -1,51 +0,0 @@
1
- /**
2
- * @interface
3
- * @category SDK
4
- * @subcategory Internal
5
- * @property {Object.<string, LocalStorageUser>} - A dictionary for mapping users to their states.
6
- */
7
- import { State } from "../State";
8
- import { LocalStorageWebauthn } from "./WebauthnState";
9
- import { LocalStoragePasscode } from "./PasscodeState";
10
- import { LocalStoragePassword } from "./PasswordState";
11
- /**
12
- * @interface
13
- * @category SDK
14
- * @subcategory Internal
15
- * @property {LocalStorageWebauthn=} webauthn - Information about WebAuthn credentials.
16
- * @property {LocalStoragePasscode=} passcode - Information about the active passcode.
17
- * @property {LocalStoragePassword=} password - Information about the password login attempts.
18
- */
19
- interface LocalStorageUser {
20
- webauthn?: LocalStorageWebauthn;
21
- passcode?: LocalStoragePasscode;
22
- password?: LocalStoragePassword;
23
- }
24
- /**
25
- * @interface
26
- * @category SDK
27
- * @subcategory Internal
28
- * @property {Object.<string, LocalStorageUser>} - A dictionary for mapping users to their states.
29
- */
30
- export interface LocalStorageUsers {
31
- [userID: string]: LocalStorageUser;
32
- }
33
- /**
34
- * A class to read and write local storage contents.
35
- *
36
- * @abstract
37
- * @extends State
38
- * @param {string} key - The local storage key.
39
- * @category SDK
40
- * @subcategory Internal
41
- */
42
- declare abstract class UserState extends State {
43
- /**
44
- * Gets the state of the specified user.
45
- *
46
- * @param {string} userID - The UUID of the user.
47
- * @return {LocalStorageUser}
48
- */
49
- getUserState(userID: string): LocalStorageUser;
50
- }
51
- export { UserState };
@@ -1,60 +0,0 @@
1
- import { UserState } from "./UserState";
2
- import { Credential } from "../../Dto";
3
- /**
4
- * @interface
5
- * @category SDK
6
- * @subcategory Internal
7
- * @property {string[]?} credentials - A list of known credential IDs on the current browser.
8
- */
9
- export interface LocalStorageWebauthn {
10
- credentials?: string[];
11
- }
12
- /**
13
- * A class that manages WebAuthn credentials via local storage.
14
- *
15
- * @extends UserState
16
- * @category SDK
17
- * @subcategory Internal
18
- */
19
- declare class WebauthnState extends UserState {
20
- /**
21
- * Gets the WebAuthn state.
22
- *
23
- * @private
24
- * @param {string} userID - The UUID of the user.
25
- * @return {LocalStorageWebauthn}
26
- */
27
- private getState;
28
- /**
29
- * Reads the current state.
30
- *
31
- * @public
32
- * @return {WebauthnState}
33
- */
34
- read(): WebauthnState;
35
- /**
36
- * Gets the list of known credentials on the current browser.
37
- *
38
- * @param {string} userID - The UUID of the user.
39
- * @return {string[]}
40
- */
41
- getCredentials(userID: string): string[];
42
- /**
43
- * Adds the credential to the list of known credentials.
44
- *
45
- * @param {string} userID - The UUID of the user.
46
- * @param {string} credentialID - The WebAuthn credential ID.
47
- * @return {WebauthnState}
48
- */
49
- addCredential(userID: string, credentialID: string): WebauthnState;
50
- /**
51
- * Returns the intersection between the specified list of credentials and the known credentials stored in
52
- * the local storage.
53
- *
54
- * @param {string} userID - The UUID of the user.
55
- * @param {Credential[]} match - A list of credential IDs to be matched against the local storage.
56
- * @return {Credential[]}
57
- */
58
- matchCredentials(userID: string, match: Credential[]): Credential[];
59
- }
60
- export { WebauthnState };