@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.
- package/README.md +6 -52
- package/dist/Hanko.d.ts +2 -8
- package/dist/index.d.ts +4 -8
- package/dist/lib/Session.d.ts +1 -1
- package/dist/lib/client/HttpClient.d.ts +3 -7
- package/dist/lib/events/CustomEvents.d.ts +9 -16
- package/dist/lib/events/Dispatcher.d.ts +1 -7
- package/dist/lib/events/Listener.d.ts +1 -9
- package/dist/lib/flow-api/BrowserFlowStorage.d.ts +6 -0
- package/dist/lib/flow-api/Flow.d.ts +40 -0
- package/dist/lib/flow-api/State.d.ts +69 -0
- package/dist/lib/flow-api/types/action.d.ts +92 -0
- package/dist/lib/flow-api/types/error.d.ts +6 -0
- package/dist/lib/flow-api/types/input.d.ts +77 -0
- package/dist/lib/flow-api/types/payload.d.ts +60 -0
- package/dist/lib/flow-api/types/state-handling.d.ts +54 -0
- package/dist/lib/state/State.d.ts +0 -2
- package/dist/lib/state/session/SessionState.d.ts +0 -12
- 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 +1 -1
- package/dist/lib/client/ConfigClient.d.ts +0 -20
- package/dist/lib/client/PasscodeClient.d.ts +0 -57
- package/dist/lib/client/PasswordClient.d.ts +0 -50
- package/dist/lib/client/WebauthnClient.d.ts +0 -97
- package/dist/lib/state/users/PasscodeState.d.ts +0 -108
- package/dist/lib/state/users/PasswordState.d.ts +0 -50
- package/dist/lib/state/users/UserState.d.ts +0 -51
- package/dist/lib/state/users/WebauthnState.d.ts +0 -60
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ const hanko = new Hanko("http://localhost:3000", defaultOptions);
|
|
|
52
52
|
|
|
53
53
|
## Documentation
|
|
54
54
|
|
|
55
|
-
To see the latest documentation, please click [here](https://
|
|
55
|
+
To see the latest documentation, please click [here](https://teamhanko.github.io/hanko/jsdoc/hanko-frontend-sdk/).
|
|
56
56
|
|
|
57
57
|
## Exports
|
|
58
58
|
|
|
@@ -62,11 +62,7 @@ To see the latest documentation, please click [here](https://docs.hanko.io/jsdoc
|
|
|
62
62
|
|
|
63
63
|
### Client Classes
|
|
64
64
|
|
|
65
|
-
- `ConfigClient` - A class to fetch configurations.
|
|
66
65
|
- `UserClient` - A class to manage users.
|
|
67
|
-
- `WebauthnClient` - A class to handle WebAuthn-related functionalities.
|
|
68
|
-
- `PasswordClient` - A class to manage passwords and password logins.
|
|
69
|
-
- `PasscodeClient` - A class to handle passcode logins.
|
|
70
66
|
- `ThirdPartyClient` - A class to handle social logins.
|
|
71
67
|
- `TokenClient` - A class that handles the exchange of one time tokens for session JWTs.
|
|
72
68
|
|
|
@@ -99,12 +95,10 @@ To see the latest documentation, please click [here](https://docs.hanko.io/jsdoc
|
|
|
99
95
|
### Event Interfaces
|
|
100
96
|
|
|
101
97
|
- `SessionDetail`
|
|
102
|
-
- `AuthFlowCompletedDetail`
|
|
103
98
|
|
|
104
99
|
### Event Types
|
|
105
100
|
|
|
106
101
|
- `CustomEventWithDetail`
|
|
107
|
-
- `authFlowCompletedType`
|
|
108
102
|
- `sessionCreatedType`
|
|
109
103
|
- `sessionExpiredType`
|
|
110
104
|
- `userLoggedOutType`
|
|
@@ -152,36 +146,6 @@ try {
|
|
|
152
146
|
}
|
|
153
147
|
```
|
|
154
148
|
|
|
155
|
-
### Register a WebAuthn credential
|
|
156
|
-
|
|
157
|
-
There are a number of situations where you may want the user to register a WebAuthn credential. For example, after user
|
|
158
|
-
creation, when a user logs in to a new browser/device, or to take advantage of the "caBLE" support and pair a smartphone
|
|
159
|
-
with a desktop computer:
|
|
160
|
-
|
|
161
|
-
```typescript
|
|
162
|
-
import { Hanko, UnauthorizedError, WebauthnRequestCancelledError } from "@teamhanko/hanko-frontend-sdk"
|
|
163
|
-
|
|
164
|
-
const hanko = new Hanko("https://[HANKO_API_URL]")
|
|
165
|
-
|
|
166
|
-
// By passing the user object (see example above) to `hanko.webauthn.shouldRegister(user)` you get an indication of
|
|
167
|
-
// whether a WebAuthn credential registration should be performed on the current browser. This is useful if the user has
|
|
168
|
-
// logged in using a method other than WebAuthn, and you then want to display a UI that allows the user to register a
|
|
169
|
-
// credential when possibly none exists.
|
|
170
|
-
|
|
171
|
-
try {
|
|
172
|
-
// Will cause the browser to present a dialog with various options depending on the WebAuthn implemention.
|
|
173
|
-
await hanko.webauthn.register()
|
|
174
|
-
|
|
175
|
-
// Credential has been registered.
|
|
176
|
-
} catch(e) {
|
|
177
|
-
if (e instanceof WebauthnRequestCancelledError) {
|
|
178
|
-
// The WebAuthn API failed. Usually in this case the user cancelled the WebAuthn dialog.
|
|
179
|
-
} else if (e instanceof UnauthorizedError) {
|
|
180
|
-
// The user needs to login to perform this action.
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
```
|
|
184
|
-
|
|
185
149
|
### Custom Events
|
|
186
150
|
|
|
187
151
|
You can bind callback functions to different custom events. The callback function will be called when the event happens
|
|
@@ -198,23 +162,13 @@ const removeEventListener = hanko.onSessionCreated((eventDetail) => {
|
|
|
198
162
|
|
|
199
163
|
The following events are available:
|
|
200
164
|
|
|
201
|
-
- "hanko-
|
|
202
|
-
additional steps (e.g. passkey registration or password recovery)
|
|
203
|
-
|
|
204
|
-
```js
|
|
205
|
-
hanko.onAuthFlowCompleted((authFlowCompletedDetail) => {
|
|
206
|
-
// Login, registration or recovery has been completed successfully. You can now take control and redirect the
|
|
207
|
-
// user to protected pages.
|
|
208
|
-
console.info(`User successfully completed the registration or authorization process (user-id: "${authFlowCompletedDetail.userID}")`);
|
|
209
|
-
})
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
- "hanko-session-created": Will be triggered before the "hanko-auth-flow-completed" happens, as soon as the user is technically logged in.
|
|
213
|
-
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
|
|
165
|
+
- "hanko-session-created": Will be triggered after a session has been created and the user has completed possible
|
|
166
|
+
additional steps (e.g. passkey registration or password recovery). It will also be triggered when the user logs in via
|
|
167
|
+
another browser window. The event can be used to obtain the JWT. Please note, that the
|
|
214
168
|
JWT is only available, when the Hanko API configuration allows to obtain the JWT. When using Hanko-Cloud
|
|
215
169
|
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
|
|
216
170
|
your backend runs under the same domain as your frontend. To do so, make sure the config parameter "session.enable_auth_token_header"
|
|
217
|
-
is turned off via the [Hanko-API configuration](https://github.com/teamhanko/hanko/
|
|
171
|
+
is turned off via the [Hanko-API configuration](https://github.com/teamhanko/hanko/wiki). If you want the JWT to be contained in the event details, you need to turn on
|
|
218
172
|
"session.enable_auth_token_header" when using a cross-domain setup. When it's a same-domain setup you need to turn off
|
|
219
173
|
"session.cookie.http_only" to make the JWT accessible to the frontend.
|
|
220
174
|
|
|
@@ -255,7 +209,7 @@ hanko.onUserDeleted(() => {
|
|
|
255
209
|
})
|
|
256
210
|
```
|
|
257
211
|
|
|
258
|
-
Please Take a look into the [docs](https://
|
|
212
|
+
Please Take a look into the [docs](https://teamhanko.github.io/hanko/jsdoc/hanko-frontend-sdk/) for more details.
|
|
259
213
|
|
|
260
214
|
## Bugs
|
|
261
215
|
|
package/dist/Hanko.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { ConfigClient } from "./lib/client/ConfigClient";
|
|
2
1
|
import { EnterpriseClient } from "./lib/client/EnterpriseClient";
|
|
3
|
-
import { PasscodeClient } from "./lib/client/PasscodeClient";
|
|
4
|
-
import { PasswordClient } from "./lib/client/PasswordClient";
|
|
5
2
|
import { UserClient } from "./lib/client/UserClient";
|
|
6
|
-
import { WebauthnClient } from "./lib/client/WebauthnClient";
|
|
7
3
|
import { EmailClient } from "./lib/client/EmailClient";
|
|
8
4
|
import { ThirdPartyClient } from "./lib/client/ThirdPartyClient";
|
|
9
5
|
import { TokenClient } from "./lib/client/TokenClient";
|
|
@@ -11,6 +7,7 @@ import { Listener } from "./lib/events/Listener";
|
|
|
11
7
|
import { Relay } from "./lib/events/Relay";
|
|
12
8
|
import { Session } from "./lib/Session";
|
|
13
9
|
import { CookieSameSite } from "./lib/Cookie";
|
|
10
|
+
import { Flow } from "./lib/flow-api/Flow";
|
|
14
11
|
/**
|
|
15
12
|
* The options for the Hanko class
|
|
16
13
|
*
|
|
@@ -37,17 +34,14 @@ export interface HankoOptions {
|
|
|
37
34
|
*/
|
|
38
35
|
declare class Hanko extends Listener {
|
|
39
36
|
api: string;
|
|
40
|
-
config: ConfigClient;
|
|
41
37
|
user: UserClient;
|
|
42
|
-
webauthn: WebauthnClient;
|
|
43
|
-
password: PasswordClient;
|
|
44
|
-
passcode: PasscodeClient;
|
|
45
38
|
email: EmailClient;
|
|
46
39
|
thirdParty: ThirdPartyClient;
|
|
47
40
|
enterprise: EnterpriseClient;
|
|
48
41
|
token: TokenClient;
|
|
49
42
|
relay: Relay;
|
|
50
43
|
session: Session;
|
|
44
|
+
flow: Flow;
|
|
51
45
|
constructor(api: string, options?: HankoOptions);
|
|
52
46
|
}
|
|
53
47
|
export interface InternalOptions {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import { Hanko } from "./Hanko";
|
|
2
2
|
export { Hanko };
|
|
3
|
-
import { ConfigClient } from "./lib/client/ConfigClient";
|
|
4
|
-
import { PasscodeClient } from "./lib/client/PasscodeClient";
|
|
5
|
-
import { PasswordClient } from "./lib/client/PasswordClient";
|
|
6
3
|
import { UserClient } from "./lib/client/UserClient";
|
|
7
|
-
import { WebauthnClient } from "./lib/client/WebauthnClient";
|
|
8
4
|
import { EmailClient } from "./lib/client/EmailClient";
|
|
9
5
|
import { ThirdPartyClient } from "./lib/client/ThirdPartyClient";
|
|
10
6
|
import { TokenClient } from "./lib/client/TokenClient";
|
|
11
7
|
import { EnterpriseClient } from "./lib/client/EnterpriseClient";
|
|
12
|
-
export {
|
|
8
|
+
export { UserClient, EmailClient, ThirdPartyClient, TokenClient, EnterpriseClient, };
|
|
13
9
|
import { WebauthnSupport } from "./lib/WebauthnSupport";
|
|
14
10
|
export { WebauthnSupport };
|
|
15
11
|
import { PasswordConfig, EmailConfig, AccountConfig, Config, WebauthnFinalized, TokenFinalized, UserInfo, Me, Credential, User, UserCreated, Passcode, WebauthnTransports, Attestation, Email, Emails, WebauthnCredential, WebauthnCredentials, Identity } from "./lib/Dto";
|
|
16
12
|
export type { PasswordConfig, EmailConfig, AccountConfig, Config, WebauthnFinalized, TokenFinalized, UserInfo, Me, Credential, User, UserCreated, Passcode, WebauthnTransports, Attestation, Email, Emails, WebauthnCredential, WebauthnCredentials, Identity, };
|
|
17
13
|
import { HankoError, ConflictError, ForbiddenError, EmailAddressAlreadyExistsError, InvalidPasswordError, InvalidPasscodeError, InvalidWebauthnCredentialError, MaxNumOfEmailAddressesReachedError, MaxNumOfPasscodeAttemptsReachedError, NotFoundError, PasscodeExpiredError, RequestTimeoutError, TechnicalError, ThirdPartyError, TooManyRequestsError, UnauthorizedError, UserVerificationError, WebauthnRequestCancelledError } from "./lib/Errors";
|
|
18
14
|
export { HankoError, ConflictError, ForbiddenError, EmailAddressAlreadyExistsError, InvalidPasswordError, InvalidPasscodeError, InvalidWebauthnCredentialError, MaxNumOfEmailAddressesReachedError, MaxNumOfPasscodeAttemptsReachedError, NotFoundError, PasscodeExpiredError, RequestTimeoutError, TechnicalError, ThirdPartyError, TooManyRequestsError, UnauthorizedError, UserVerificationError, WebauthnRequestCancelledError, };
|
|
19
|
-
import { CustomEventWithDetail, SessionDetail,
|
|
20
|
-
export type { SessionDetail
|
|
21
|
-
export {
|
|
15
|
+
import { CustomEventWithDetail, SessionDetail, sessionCreatedType, sessionExpiredType, userLoggedOutType, userDeletedType } from "./lib/events/CustomEvents";
|
|
16
|
+
export type { SessionDetail };
|
|
17
|
+
export { sessionCreatedType, sessionExpiredType, userLoggedOutType, userDeletedType, CustomEventWithDetail, };
|
|
22
18
|
import { CookieSameSite } from "./lib/Cookie";
|
|
23
19
|
export type { CookieSameSite };
|
package/dist/lib/Session.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ export declare class Session {
|
|
|
54
54
|
|
|
55
55
|
@private
|
|
56
56
|
@param {SessionDetail} detail - The session details to validate.
|
|
57
|
-
@returns {boolean} true if the session
|
|
57
|
+
@returns {boolean} true if the session is valid, false otherwise.
|
|
58
58
|
*/
|
|
59
59
|
private static validate;
|
|
60
60
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SessionState } from "../state/session/SessionState";
|
|
2
|
-
import { PasscodeState } from "../state/users/PasscodeState";
|
|
3
2
|
import { Dispatcher } from "../events/Dispatcher";
|
|
4
3
|
import { Cookie } from "../Cookie";
|
|
5
4
|
/**
|
|
@@ -87,19 +86,16 @@ declare class HttpClient {
|
|
|
87
86
|
timeout: number;
|
|
88
87
|
api: string;
|
|
89
88
|
sessionState: SessionState;
|
|
90
|
-
passcodeState: PasscodeState;
|
|
91
89
|
dispatcher: Dispatcher;
|
|
92
90
|
cookie: Cookie;
|
|
93
91
|
constructor(api: string, options: HttpClientOptions);
|
|
94
92
|
_fetch(path: string, options: RequestInit, xhr?: XMLHttpRequest): Promise<Response>;
|
|
95
93
|
/**
|
|
96
|
-
* Processes the response headers on login and extracts the JWT and expiration time.
|
|
97
|
-
* removed, the session state updated und a `hanko-session-created` event will be dispatched.
|
|
94
|
+
* Processes the response headers on login and extracts the JWT and expiration time.
|
|
98
95
|
*
|
|
99
|
-
* @param {
|
|
100
|
-
* @param {Response} response - The HTTP response object.
|
|
96
|
+
* @param {XMLHttpRequest} xhr - The xhr object.
|
|
101
97
|
*/
|
|
102
|
-
|
|
98
|
+
processHeaders(xhr: XMLHttpRequest): void;
|
|
103
99
|
/**
|
|
104
100
|
* Performs a GET request.
|
|
105
101
|
*
|
|
@@ -23,11 +23,17 @@ export declare const userLoggedOutType: "hanko-user-logged-out";
|
|
|
23
23
|
*/
|
|
24
24
|
export declare const userDeletedType: "hanko-user-deleted";
|
|
25
25
|
/**
|
|
26
|
-
* The type of the `hanko-
|
|
27
|
-
* @typedef {string}
|
|
26
|
+
* The type of the `hanko-user-logged-in` event.
|
|
27
|
+
* @typedef {string} userLoggedInType
|
|
28
28
|
* @memberOf Listener
|
|
29
29
|
*/
|
|
30
|
-
export declare const
|
|
30
|
+
export declare const userLoggedInType: "hanko-user-logged-in";
|
|
31
|
+
/**
|
|
32
|
+
* The type of the `hanko-user-created` event.
|
|
33
|
+
* @typedef {string} userCreatedType
|
|
34
|
+
* @memberOf Listener
|
|
35
|
+
*/
|
|
36
|
+
export declare const userCreatedType: "hanko-user-created";
|
|
31
37
|
/**
|
|
32
38
|
* The data passed in the `hanko-session-created` or `hanko-session-resumed` event.
|
|
33
39
|
*
|
|
@@ -36,23 +42,10 @@ export declare const authFlowCompletedType: "hanko-auth-flow-completed";
|
|
|
36
42
|
* @subcategory Events
|
|
37
43
|
* @property {string=} jwt - The JSON web token associated with the session. Only present when the Hanko-API allows the JWT to be accessible client-side.
|
|
38
44
|
* @property {number} expirationSeconds - The number of seconds until the JWT expires.
|
|
39
|
-
* @property {string} userID - The user associated with the session.
|
|
40
45
|
*/
|
|
41
46
|
export interface SessionDetail {
|
|
42
47
|
jwt?: string;
|
|
43
48
|
expirationSeconds: number;
|
|
44
|
-
userID: string;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* The data passed in the `hanko-auth-flow-completed` event.
|
|
48
|
-
*
|
|
49
|
-
* @interface
|
|
50
|
-
* @category SDK
|
|
51
|
-
* @subcategory Events
|
|
52
|
-
* @property {string} userID - The user associated with the removed session.
|
|
53
|
-
*/
|
|
54
|
-
export interface AuthFlowCompletedDetail {
|
|
55
|
-
userID: string;
|
|
56
49
|
}
|
|
57
50
|
/**
|
|
58
51
|
* A custom event that includes a detail object.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SessionDetail
|
|
1
|
+
import { SessionDetail } from "./CustomEvents";
|
|
2
2
|
import { SessionState } from "../state/session/SessionState";
|
|
3
3
|
/**
|
|
4
4
|
* Options for Dispatcher
|
|
@@ -47,11 +47,5 @@ export declare class Dispatcher {
|
|
|
47
47
|
* Dispatches a "hanko-user-deleted" event to the document.
|
|
48
48
|
*/
|
|
49
49
|
dispatchUserDeletedEvent(): void;
|
|
50
|
-
/**
|
|
51
|
-
* Dispatches a "hanko-auth-flow-completed" event to the document with the specified detail.
|
|
52
|
-
*
|
|
53
|
-
* @param {AuthFlowCompletedDetail} detail - The event detail.
|
|
54
|
-
*/
|
|
55
|
-
dispatchAuthFlowCompletedEvent(detail: AuthFlowCompletedDetail): void;
|
|
56
50
|
}
|
|
57
51
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Throttle } from "../Throttle";
|
|
2
|
-
import { SessionDetail
|
|
2
|
+
import { SessionDetail } from "./CustomEvents";
|
|
3
3
|
/**
|
|
4
4
|
* A callback function to be executed when an event is triggered.
|
|
5
5
|
*
|
|
@@ -102,13 +102,5 @@ export declare class Listener {
|
|
|
102
102
|
* @returns {CleanupFunc} This function can be called to remove the event listener.
|
|
103
103
|
*/
|
|
104
104
|
onUserDeleted(callback: CallbackFunc<null>, once?: boolean): CleanupFunc;
|
|
105
|
-
/**
|
|
106
|
-
* Adds an event listener for hanko-auth-flow-completed events. Will be triggered after the login or registration flow has been completed.
|
|
107
|
-
*
|
|
108
|
-
* @param {CallbackFunc<AuthFlowCompletedDetail>} callback - The function to be called when the event is triggered.
|
|
109
|
-
* @param {boolean=} once - Whether the event listener should be removed after being called once.
|
|
110
|
-
* @returns {CleanupFunc} This function can be called to remove the event listener.
|
|
111
|
-
*/
|
|
112
|
-
onAuthFlowCompleted(callback: CallbackFunc<AuthFlowCompletedDetail>, once?: boolean): CleanupFunc;
|
|
113
105
|
}
|
|
114
106
|
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Client } from "../client/Client";
|
|
2
|
+
import { State } from "./State";
|
|
3
|
+
import { Action } from "./types/action";
|
|
4
|
+
import { FlowPath, Handlers } from "./types/state-handling";
|
|
5
|
+
type ExtendedHandlers = Handlers & {
|
|
6
|
+
onError?: (e: unknown) => any;
|
|
7
|
+
};
|
|
8
|
+
declare class Flow extends Client {
|
|
9
|
+
init(initPath: FlowPath, handlers: ExtendedHandlers): Promise<void>;
|
|
10
|
+
fromString(init: string, handlers: ExtendedHandlers): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Runs a handler for a given state.
|
|
13
|
+
*
|
|
14
|
+
* If the handler returns an action or a state, this method will run the next
|
|
15
|
+
* appropriate handler for that state. (Recursively)
|
|
16
|
+
*
|
|
17
|
+
* If the handlers passed to `init` do not contain an `onError` handler,
|
|
18
|
+
* this method will throw.
|
|
19
|
+
*
|
|
20
|
+
* @see InvalidStateError
|
|
21
|
+
* @see HandlerNotFoundError
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const handlerResult = await run("/login", {
|
|
25
|
+
* // all login handlers are in here, one of which will be called
|
|
26
|
+
* // based on what the /login endpoint returns
|
|
27
|
+
* });
|
|
28
|
+
*/
|
|
29
|
+
run: (state: State<any>, handlers: ExtendedHandlers) => Promise<unknown>;
|
|
30
|
+
}
|
|
31
|
+
export declare class HandlerNotFoundError extends Error {
|
|
32
|
+
state: State<any>;
|
|
33
|
+
constructor(state: State<any>);
|
|
34
|
+
}
|
|
35
|
+
export declare class InvalidStateError extends Error {
|
|
36
|
+
state: State<any>;
|
|
37
|
+
constructor(state: State<any>);
|
|
38
|
+
}
|
|
39
|
+
export declare function isAction(x: any): x is Action<unknown>;
|
|
40
|
+
export { Flow };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { FetchNextState, StateName, Actions, Payloads } from "./types/state-handling";
|
|
2
|
+
import { Error } from "./types/error";
|
|
3
|
+
import { Action } from "./types/action";
|
|
4
|
+
import { Input } from "./types/input";
|
|
5
|
+
type InputValues<TInput extends Record<string, Input<any>>> = {
|
|
6
|
+
[K in keyof TInput]?: TInput[K]["value"];
|
|
7
|
+
};
|
|
8
|
+
type CreateAction<TAction extends Action<any>> = (inputs: InputValues<TAction["inputs"]>) => TAction & {
|
|
9
|
+
run: () => Promise<State<any>>;
|
|
10
|
+
validate: () => TAction;
|
|
11
|
+
tryValidate: () => ValidationError | void;
|
|
12
|
+
};
|
|
13
|
+
type ActionFunctions = {
|
|
14
|
+
[TStateName in keyof Actions]: {
|
|
15
|
+
[TActionName in keyof Actions[TStateName]]: Actions[TStateName][TActionName] extends Action<infer Inputs> ? CreateAction<Action<Inputs>> : never;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
interface StateResponse<TStateName extends StateName> {
|
|
19
|
+
name: StateName;
|
|
20
|
+
status: number;
|
|
21
|
+
payload?: Payloads[TStateName];
|
|
22
|
+
actions?: Actions[TStateName];
|
|
23
|
+
csrf_token: string;
|
|
24
|
+
error: Error;
|
|
25
|
+
}
|
|
26
|
+
declare class State<TStateName extends StateName> implements Omit<StateResponse<TStateName>, "actions"> {
|
|
27
|
+
#private;
|
|
28
|
+
readonly name: StateName;
|
|
29
|
+
readonly payload?: Payloads[TStateName];
|
|
30
|
+
readonly error: Error;
|
|
31
|
+
readonly status: number;
|
|
32
|
+
readonly csrf_token: string;
|
|
33
|
+
readonly actions: ActionFunctions[TStateName];
|
|
34
|
+
private readonly fetchNextState;
|
|
35
|
+
toJSON(): {
|
|
36
|
+
name: StateName;
|
|
37
|
+
payload: Payloads[TStateName];
|
|
38
|
+
error: Error;
|
|
39
|
+
status: number;
|
|
40
|
+
csrf_token: string;
|
|
41
|
+
actions: Actions[TStateName];
|
|
42
|
+
};
|
|
43
|
+
constructor({ name, payload, error, status, actions, csrf_token }: StateResponse<TStateName>, fetchNextState: FetchNextState);
|
|
44
|
+
runAction(action: Action<any>, csrfToken: string): Promise<State<any>>;
|
|
45
|
+
validateAction(action: Action<{
|
|
46
|
+
[key: string]: Input<unknown>;
|
|
47
|
+
}>): void;
|
|
48
|
+
}
|
|
49
|
+
export declare enum ValidationReason {
|
|
50
|
+
InvalidInputDefinition = 0,
|
|
51
|
+
MinLength = 1,
|
|
52
|
+
MaxLength = 2,
|
|
53
|
+
Required = 3
|
|
54
|
+
}
|
|
55
|
+
export declare class ValidationError<TWanted = undefined> extends Error {
|
|
56
|
+
reason: ValidationReason;
|
|
57
|
+
inputName: string;
|
|
58
|
+
wanted: TWanted;
|
|
59
|
+
actual: TWanted;
|
|
60
|
+
constructor(opts: {
|
|
61
|
+
reason: ValidationReason;
|
|
62
|
+
inputName: string;
|
|
63
|
+
wanted: TWanted;
|
|
64
|
+
actual: TWanted;
|
|
65
|
+
message: string;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export declare function isState(x: any): x is State<any>;
|
|
69
|
+
export { State };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ContinueWithLoginIdentifierInputs, EmailCreateInputs, EmailDeleteInputs, EmailSetPrimaryInputs, EmailVerifyInputs, ExchangeTokenInputs, PasskeyCredentialDelete, PasskeyCredentialRename, PasswordRecoveryInputs, PasswordInputs, RegisterClientCapabilitiesInputs, RegisterLoginIdentifierInputs, RegisterPasswordInputs, ThirdpartyOauthInputs, UsernameSetInputs, VerifyPasscodeInputs, WebauthnVerifyAssertionResponseInputs, WebauthnVerifyAttestationResponseInputs } from "./input";
|
|
2
|
+
interface Action<TInputs> {
|
|
3
|
+
name: string;
|
|
4
|
+
href: string;
|
|
5
|
+
inputs: TInputs;
|
|
6
|
+
description: string;
|
|
7
|
+
}
|
|
8
|
+
interface PreflightActions {
|
|
9
|
+
readonly register_client_capabilities: Action<RegisterClientCapabilitiesInputs>;
|
|
10
|
+
}
|
|
11
|
+
interface LoginInitActions {
|
|
12
|
+
readonly continue_with_login_identifier?: Action<ContinueWithLoginIdentifierInputs>;
|
|
13
|
+
readonly webauthn_generate_request_options?: Action<null>;
|
|
14
|
+
readonly webauthn_verify_assertion_response?: Action<WebauthnVerifyAssertionResponseInputs>;
|
|
15
|
+
readonly thirdparty_oauth?: Action<ThirdpartyOauthInputs>;
|
|
16
|
+
}
|
|
17
|
+
interface ProfileInitActions {
|
|
18
|
+
readonly account_delete?: Action<null>;
|
|
19
|
+
readonly email_create?: Action<EmailCreateInputs>;
|
|
20
|
+
readonly email_delete?: Action<EmailDeleteInputs>;
|
|
21
|
+
readonly email_verify?: Action<EmailVerifyInputs>;
|
|
22
|
+
readonly email_set_primary?: Action<EmailSetPrimaryInputs>;
|
|
23
|
+
readonly password_create?: Action<PasswordInputs>;
|
|
24
|
+
readonly password_update?: Action<PasswordInputs>;
|
|
25
|
+
readonly password_delete?: Action<null>;
|
|
26
|
+
readonly username_create?: Action<UsernameSetInputs>;
|
|
27
|
+
readonly username_delete?: Action<null>;
|
|
28
|
+
readonly username_update?: Action<UsernameSetInputs>;
|
|
29
|
+
readonly webauthn_credential_create?: Action<null>;
|
|
30
|
+
readonly webauthn_credential_rename?: Action<PasskeyCredentialRename>;
|
|
31
|
+
readonly webauthn_credential_delete?: Action<PasskeyCredentialDelete>;
|
|
32
|
+
readonly webauthn_verify_attestation_response?: Action<WebauthnVerifyAttestationResponseInputs>;
|
|
33
|
+
}
|
|
34
|
+
interface LoginMethodChooserActions {
|
|
35
|
+
readonly continue_to_password_login?: Action<null>;
|
|
36
|
+
readonly continue_to_passcode_confirmation?: Action<null>;
|
|
37
|
+
readonly back: Action<null>;
|
|
38
|
+
}
|
|
39
|
+
interface LoginPasswordActions {
|
|
40
|
+
readonly password_login: Action<PasswordInputs>;
|
|
41
|
+
readonly continue_to_passcode_confirmation_recovery?: Action<null>;
|
|
42
|
+
readonly continue_to_login_method_chooser: Action<null>;
|
|
43
|
+
readonly back: Action<null>;
|
|
44
|
+
}
|
|
45
|
+
interface LoginPasswordRecoveryActions {
|
|
46
|
+
readonly password_recovery: Action<PasswordRecoveryInputs>;
|
|
47
|
+
}
|
|
48
|
+
interface LoginPasskeyActions {
|
|
49
|
+
readonly webauthn_verify_assertion_response: Action<WebauthnVerifyAssertionResponseInputs>;
|
|
50
|
+
readonly back: Action<null>;
|
|
51
|
+
}
|
|
52
|
+
interface OnboardingCreatePasskeyActions {
|
|
53
|
+
readonly webauthn_generate_creation_options: Action<null>;
|
|
54
|
+
readonly skip?: Action<null>;
|
|
55
|
+
readonly back?: Action<null>;
|
|
56
|
+
}
|
|
57
|
+
interface OnboardingVerifyPasskeyAttestationActions {
|
|
58
|
+
readonly webauthn_verify_attestation_response: Action<WebauthnVerifyAttestationResponseInputs>;
|
|
59
|
+
readonly back: Action<null>;
|
|
60
|
+
}
|
|
61
|
+
interface RegistrationInitActions {
|
|
62
|
+
readonly register_login_identifier: Action<RegisterLoginIdentifierInputs>;
|
|
63
|
+
readonly thirdparty_oauth?: Action<ThirdpartyOauthInputs>;
|
|
64
|
+
}
|
|
65
|
+
interface PasswordCreationActions {
|
|
66
|
+
readonly register_password: Action<RegisterPasswordInputs>;
|
|
67
|
+
readonly back?: Action<null>;
|
|
68
|
+
readonly skip?: Action<null>;
|
|
69
|
+
}
|
|
70
|
+
interface PasscodeConfirmationActions {
|
|
71
|
+
readonly verify_passcode: Action<VerifyPasscodeInputs>;
|
|
72
|
+
readonly resend_passcode: Action<null>;
|
|
73
|
+
readonly back: Action<null>;
|
|
74
|
+
}
|
|
75
|
+
interface OnboardingEmailActions {
|
|
76
|
+
readonly email_address_set: Action<EmailCreateInputs>;
|
|
77
|
+
readonly skip: Action<null>;
|
|
78
|
+
}
|
|
79
|
+
interface OnboardingUsernameActions {
|
|
80
|
+
readonly username_create: Action<UsernameSetInputs>;
|
|
81
|
+
readonly skip: Action<null>;
|
|
82
|
+
}
|
|
83
|
+
interface CredentialOnboardingChooserActions {
|
|
84
|
+
readonly continue_to_passkey_registration: Action<null>;
|
|
85
|
+
readonly continue_to_password_registration: Action<null>;
|
|
86
|
+
readonly skip: Action<null>;
|
|
87
|
+
readonly back: Action<null>;
|
|
88
|
+
}
|
|
89
|
+
interface ThirdPartyActions {
|
|
90
|
+
readonly exchange_token: Action<ExchangeTokenInputs>;
|
|
91
|
+
}
|
|
92
|
+
export type { Action, PreflightActions, LoginInitActions, ProfileInitActions, LoginMethodChooserActions, LoginPasswordActions, LoginPasswordRecoveryActions, LoginPasskeyActions, OnboardingCreatePasskeyActions, OnboardingVerifyPasskeyAttestationActions, RegistrationInitActions, PasswordCreationActions, PasscodeConfirmationActions, OnboardingEmailActions, OnboardingUsernameActions, CredentialOnboardingChooserActions, ThirdPartyActions, };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Error } from "./error";
|
|
2
|
+
import { PublicKeyCredentialWithAssertionJSON, PublicKeyCredentialWithAttestationJSON } from "@github/webauthn-json";
|
|
3
|
+
export interface Input<TValue> {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly type: string;
|
|
6
|
+
value?: TValue;
|
|
7
|
+
readonly min_length?: number;
|
|
8
|
+
readonly max_length?: number;
|
|
9
|
+
readonly required?: boolean;
|
|
10
|
+
readonly hidden?: boolean;
|
|
11
|
+
readonly error?: Error;
|
|
12
|
+
readonly allowed_values?: AllowedInputValues[];
|
|
13
|
+
}
|
|
14
|
+
export interface AllowedInputValues {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly value: string;
|
|
17
|
+
}
|
|
18
|
+
export interface PasswordRecoveryInputs {
|
|
19
|
+
readonly new_password: Input<string>;
|
|
20
|
+
}
|
|
21
|
+
export interface WebauthnVerifyAssertionResponseInputs {
|
|
22
|
+
readonly assertion_response: Input<PublicKeyCredentialWithAssertionJSON>;
|
|
23
|
+
}
|
|
24
|
+
export interface WebauthnVerifyAttestationResponseInputs {
|
|
25
|
+
readonly public_key: Input<PublicKeyCredentialWithAttestationJSON>;
|
|
26
|
+
}
|
|
27
|
+
export interface RegisterLoginIdentifierInputs {
|
|
28
|
+
readonly email?: Input<string>;
|
|
29
|
+
readonly username?: Input<string>;
|
|
30
|
+
}
|
|
31
|
+
export interface RegisterPasswordInputs {
|
|
32
|
+
readonly new_password: Input<string>;
|
|
33
|
+
}
|
|
34
|
+
export interface RegisterClientCapabilitiesInputs {
|
|
35
|
+
readonly webauthn_available: Input<boolean>;
|
|
36
|
+
readonly webauthn_conditional_mediation_available: Input<boolean>;
|
|
37
|
+
}
|
|
38
|
+
export interface ContinueWithLoginIdentifierInputs {
|
|
39
|
+
readonly identifier?: Input<string>;
|
|
40
|
+
readonly email?: Input<string>;
|
|
41
|
+
readonly username?: Input<string>;
|
|
42
|
+
}
|
|
43
|
+
export interface VerifyPasscodeInputs {
|
|
44
|
+
readonly code: Input<string>;
|
|
45
|
+
}
|
|
46
|
+
export interface EmailCreateInputs {
|
|
47
|
+
readonly email: Input<string>;
|
|
48
|
+
}
|
|
49
|
+
export interface EmailDeleteInputs {
|
|
50
|
+
readonly email_id: Input<string>;
|
|
51
|
+
}
|
|
52
|
+
export interface EmailSetPrimaryInputs {
|
|
53
|
+
readonly email_id: Input<string>;
|
|
54
|
+
}
|
|
55
|
+
export interface EmailVerifyInputs {
|
|
56
|
+
readonly email_id: Input<string>;
|
|
57
|
+
}
|
|
58
|
+
export interface PasswordInputs {
|
|
59
|
+
readonly password: Input<string>;
|
|
60
|
+
}
|
|
61
|
+
export interface UsernameSetInputs {
|
|
62
|
+
readonly username: Input<string>;
|
|
63
|
+
}
|
|
64
|
+
export interface PasskeyCredentialRename {
|
|
65
|
+
readonly passkey_id: Input<string>;
|
|
66
|
+
readonly passkey_name: Input<string>;
|
|
67
|
+
}
|
|
68
|
+
export interface PasskeyCredentialDelete {
|
|
69
|
+
readonly passkey_id: Input<string>;
|
|
70
|
+
}
|
|
71
|
+
export interface ExchangeTokenInputs {
|
|
72
|
+
readonly token: Input<string>;
|
|
73
|
+
}
|
|
74
|
+
export interface ThirdpartyOauthInputs {
|
|
75
|
+
readonly provider: Input<string>;
|
|
76
|
+
readonly redirect_to: Input<string>;
|
|
77
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { CredentialCreationOptionsJSON, CredentialRequestOptionsJSON } from "@github/webauthn-json/src/webauthn-json/basic/json";
|
|
2
|
+
export interface PasscodeConfirmationPayload {
|
|
3
|
+
readonly passcode_resent: boolean;
|
|
4
|
+
readonly resend_after: number;
|
|
5
|
+
}
|
|
6
|
+
export interface LoginPasskeyPayload {
|
|
7
|
+
readonly request_options: CredentialRequestOptionsJSON;
|
|
8
|
+
}
|
|
9
|
+
export interface OnboardingVerifyPasskeyAttestationPayload {
|
|
10
|
+
readonly creation_options: CredentialCreationOptionsJSON;
|
|
11
|
+
}
|
|
12
|
+
export interface LoginInitPayload {
|
|
13
|
+
readonly request_options?: CredentialRequestOptionsJSON;
|
|
14
|
+
}
|
|
15
|
+
export interface Passkey {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
readonly name?: string;
|
|
18
|
+
readonly public_key: string;
|
|
19
|
+
readonly attestation_type: string;
|
|
20
|
+
readonly aaguid: string;
|
|
21
|
+
readonly last_used_at?: string;
|
|
22
|
+
readonly created_at: string;
|
|
23
|
+
readonly transports: string;
|
|
24
|
+
readonly backup_eligible: string;
|
|
25
|
+
readonly backup_state: string;
|
|
26
|
+
}
|
|
27
|
+
export interface Username {
|
|
28
|
+
id: string;
|
|
29
|
+
username: string;
|
|
30
|
+
created_at: string;
|
|
31
|
+
updated_at: string;
|
|
32
|
+
}
|
|
33
|
+
export interface Identity {
|
|
34
|
+
readonly id: string;
|
|
35
|
+
readonly provider: string;
|
|
36
|
+
}
|
|
37
|
+
export interface Email {
|
|
38
|
+
readonly id: string;
|
|
39
|
+
readonly address: string;
|
|
40
|
+
readonly is_verified: boolean;
|
|
41
|
+
readonly is_primary: boolean;
|
|
42
|
+
readonly identities?: Identity[];
|
|
43
|
+
}
|
|
44
|
+
export interface User {
|
|
45
|
+
readonly user_id: string;
|
|
46
|
+
readonly passkeys?: Passkey[];
|
|
47
|
+
readonly emails?: Email[];
|
|
48
|
+
readonly username?: Username;
|
|
49
|
+
readonly created_at: string;
|
|
50
|
+
readonly updated_at: string;
|
|
51
|
+
}
|
|
52
|
+
export interface ProfilePayload {
|
|
53
|
+
readonly user: User;
|
|
54
|
+
}
|
|
55
|
+
export interface SuccessPayload {
|
|
56
|
+
readonly user: User;
|
|
57
|
+
}
|
|
58
|
+
export interface ThirdPartyPayload {
|
|
59
|
+
readonly redirect_url: string;
|
|
60
|
+
}
|