@teamhanko/hanko-frontend-sdk 0.12.0 → 1.0.1

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 (36) 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/Dto.d.ts +4 -2
  5. package/dist/lib/Session.d.ts +1 -1
  6. package/dist/lib/client/HttpClient.d.ts +3 -7
  7. package/dist/lib/events/CustomEvents.d.ts +9 -16
  8. package/dist/lib/events/Dispatcher.d.ts +1 -7
  9. package/dist/lib/events/Listener.d.ts +1 -9
  10. package/dist/lib/flow-api/BrowserFlowStorage.d.ts +6 -0
  11. package/dist/lib/flow-api/Flow.d.ts +40 -0
  12. package/dist/lib/flow-api/State.d.ts +69 -0
  13. package/dist/lib/flow-api/types/action.d.ts +92 -0
  14. package/dist/lib/flow-api/types/error.d.ts +6 -0
  15. package/dist/lib/flow-api/types/input.d.ts +77 -0
  16. package/dist/lib/flow-api/types/payload.d.ts +60 -0
  17. package/dist/lib/flow-api/types/state-handling.d.ts +54 -0
  18. package/dist/lib/state/State.d.ts +0 -2
  19. package/dist/lib/state/session/SessionState.d.ts +0 -12
  20. package/dist/sdk.cjs +1 -1
  21. package/dist/sdk.cjs.map +1 -1
  22. package/dist/sdk.modern.js +1 -1
  23. package/dist/sdk.modern.js.map +1 -1
  24. package/dist/sdk.module.js +1 -1
  25. package/dist/sdk.module.js.map +1 -1
  26. package/dist/sdk.umd.js +1 -1
  27. package/dist/sdk.umd.js.map +1 -1
  28. package/package.json +1 -1
  29. package/dist/lib/client/ConfigClient.d.ts +0 -20
  30. package/dist/lib/client/PasscodeClient.d.ts +0 -57
  31. package/dist/lib/client/PasswordClient.d.ts +0 -50
  32. package/dist/lib/client/WebauthnClient.d.ts +0 -97
  33. package/dist/lib/state/users/PasscodeState.d.ts +0 -108
  34. package/dist/lib/state/users/PasswordState.d.ts +0 -50
  35. package/dist/lib/state/users/UserState.d.ts +0 -51
  36. 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://docs.hanko.io/jsdoc/hanko-frontend-sdk).
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-auth-flow-completed": Will be triggered after a session has been created and the user has completed possible
202
- additional steps (e.g. passkey registration or password recovery) via the `<hanko-auth>` element.
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/blob/main/backend/docs/Config.md). If you want the JWT to be contained in the event details, you need to turn on
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://docs.hanko.io/jsdoc/hanko-frontend-sdk/Hanko.html) for more details.
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 { ConfigClient, UserClient, WebauthnClient, PasswordClient, PasscodeClient, EmailClient, ThirdPartyClient, TokenClient, EnterpriseClient, };
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, AuthFlowCompletedDetail, authFlowCompletedType, sessionCreatedType, sessionExpiredType, userLoggedOutType, userDeletedType } from "./lib/events/CustomEvents";
20
- export type { SessionDetail, AuthFlowCompletedDetail };
21
- export { authFlowCompletedType, sessionCreatedType, sessionExpiredType, userLoggedOutType, userDeletedType, CustomEventWithDetail, };
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/Dto.d.ts CHANGED
@@ -108,12 +108,14 @@ export interface Credential {
108
108
  * @category SDK
109
109
  * @subcategory DTO
110
110
  * @property {string} id - The user's UUID.
111
- * @property {string} email - The user's email.
111
+ * @property {string=} email - The user's email.
112
+ * @property {string=} username - The user's username.
112
113
  * @property {Credential[]} webauthn_credentials - A list of credentials that have been registered.
113
114
  */
114
115
  export interface User {
115
116
  id: string;
116
- email: string;
117
+ email?: string;
118
+ username?: string;
117
119
  webauthn_credentials: Credential[];
118
120
  }
119
121
  /**
@@ -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 details are valid, false otherwise.
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. Also, the passcode state will be
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 {string} userID - The user ID.
100
- * @param {Response} response - The HTTP response object.
96
+ * @param {XMLHttpRequest} xhr - The xhr object.
101
97
  */
102
- processResponseHeadersOnLogin(userID: string, response: Response): void;
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-auth-flow-completed` event.
27
- * @typedef {string} authFlowCompletedType
26
+ * The type of the `hanko-user-logged-in` event.
27
+ * @typedef {string} userLoggedInType
28
28
  * @memberOf Listener
29
29
  */
30
- export declare const authFlowCompletedType: "hanko-auth-flow-completed";
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, AuthFlowCompletedDetail } from "./CustomEvents";
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, AuthFlowCompletedDetail } from "./CustomEvents";
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,6 @@
1
+ import { Flow } from "./Flow";
2
+ import { State } from "./State";
3
+ export default class BrowserFlowStorage {
4
+ static save(state: State<any>, key?: string): void;
5
+ static load(flow: Flow | Flow["fetchNextState"], key?: string): State<any> | null;
6
+ }
@@ -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,6 @@
1
+ interface Error {
2
+ code: string;
3
+ message: string;
4
+ cause?: string;
5
+ }
6
+ export type { Error };
@@ -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
+ }