@teamhanko/hanko-frontend-sdk 1.5.2 → 2.1.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 +453 -97
- package/dist/Hanko.d.ts +57 -29
- package/dist/index.d.ts +16 -9
- package/dist/lib/Cookie.d.ts +2 -2
- package/dist/lib/Dto.d.ts +11 -184
- package/dist/lib/client/HttpClient.d.ts +7 -9
- package/dist/lib/client/SessionClient.d.ts +0 -11
- package/dist/lib/client/UserClient.d.ts +1 -35
- package/dist/lib/events/CustomEvents.d.ts +25 -0
- package/dist/lib/events/Dispatcher.d.ts +9 -1
- package/dist/lib/events/Listener.d.ts +3 -1
- package/dist/lib/events/Relay.d.ts +3 -3
- package/dist/lib/flow-api/State.d.ts +192 -62
- package/dist/lib/flow-api/WebauthnManager.d.ts +47 -0
- package/dist/lib/flow-api/auto-steps.d.ts +2 -0
- package/dist/lib/flow-api/passkey-autofill-activation.d.ts +2 -0
- package/dist/lib/flow-api/types/action.d.ts +4 -2
- package/dist/lib/flow-api/types/flow.d.ts +25 -0
- package/dist/lib/flow-api/types/{error.d.ts → flowError.d.ts} +1 -2
- package/dist/lib/flow-api/types/input.d.ts +6 -4
- package/dist/lib/flow-api/types/payload.d.ts +5 -0
- package/dist/lib/flow-api/types/{state-handling.d.ts → state.d.ts} +0 -7
- 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/EmailClient.d.ts +0 -58
- package/dist/lib/client/EnterpriseClient.d.ts +0 -41
- package/dist/lib/client/ThirdPartyClient.d.ts +0 -28
- package/dist/lib/client/TokenClient.d.ts +0 -21
- package/dist/lib/flow-api/BrowserFlowStorage.d.ts +0 -6
- package/dist/lib/flow-api/Flow.d.ts +0 -41
- package/dist/lib/state/State.d.ts +0 -50
|
@@ -1,69 +1,199 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Action } from "./types/action";
|
|
1
|
+
import { Hanko } from "../../Hanko";
|
|
2
|
+
import { Actions, Payloads, StateName } from "./types/state";
|
|
4
3
|
import { Input } from "./types/input";
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import { FlowError } from "./types/flowError";
|
|
5
|
+
import { Action as ActionType } from "./types/action";
|
|
6
|
+
import { AnyState, FlowName, FlowResponse } from "./types/flow";
|
|
7
|
+
import { autoSteps } from "./auto-steps";
|
|
8
|
+
import { passkeyAutofillActivationHandlers } from "./passkey-autofill-activation";
|
|
9
|
+
export type AutoSteppedStates = keyof typeof autoSteps;
|
|
10
|
+
export type PasskeyAutofillStates = keyof typeof passkeyAutofillActivationHandlers;
|
|
11
|
+
export type AutoStepExclusion = AutoSteppedStates[] | "all";
|
|
12
|
+
export type ActionMap<TState extends StateName> = {
|
|
13
|
+
[K in keyof Actions[TState]]: Action<Actions[TState][K] extends ActionType<infer TInputs> ? TInputs : never>;
|
|
7
14
|
};
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
tryValidate: () => ValidationError | void;
|
|
15
|
+
export type ActionInfo = {
|
|
16
|
+
name: string;
|
|
17
|
+
relatedStateName: StateName;
|
|
12
18
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
name: StateName;
|
|
20
|
-
status: number;
|
|
21
|
-
payload?: Payloads[TStateName];
|
|
22
|
-
actions?: Actions[TStateName];
|
|
23
|
-
csrf_token: string;
|
|
24
|
-
error: Error;
|
|
19
|
+
export interface StateInitConfig {
|
|
20
|
+
dispatchAfterStateChangeEvent?: boolean;
|
|
21
|
+
excludeAutoSteps?: AutoStepExclusion;
|
|
22
|
+
previousAction?: ActionInfo;
|
|
23
|
+
isCached?: boolean;
|
|
24
|
+
cacheKey?: string;
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
export type StateCreateConfig = Pick<StateInitConfig, "dispatchAfterStateChangeEvent" | "excludeAutoSteps" | "cacheKey"> & {
|
|
27
|
+
loadFromCache?: boolean;
|
|
28
|
+
};
|
|
29
|
+
export type ActionRunConfig = Pick<StateInitConfig, "dispatchAfterStateChangeEvent">;
|
|
30
|
+
type SerializedState = FlowResponse<any> & {
|
|
31
|
+
flow_name: FlowName;
|
|
32
|
+
previous_action?: ActionInfo;
|
|
33
|
+
is_cached?: boolean;
|
|
34
|
+
};
|
|
35
|
+
type ExtractInputValues<TInputs> = {
|
|
36
|
+
[K in keyof TInputs]: TInputs[K] extends Input<infer TValue> ? TValue : never;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Represents a state in a flow with associated actions and properties.
|
|
40
|
+
* @template TState - The specific state name type.
|
|
41
|
+
* @constructor
|
|
42
|
+
* @param {Hanko} hanko - The Hanko instance for API interactions.
|
|
43
|
+
* @param {FlowName} flowName - The name of the flow this state belongs to.
|
|
44
|
+
* @param {FlowResponse<TState>} response - The flow response containing state data.
|
|
45
|
+
* @param {StateInitConfig} [options={}] - Configuration options for state initialization.
|
|
46
|
+
* @category SDK
|
|
47
|
+
* @subcategory FlowAPI
|
|
48
|
+
*/
|
|
49
|
+
export declare class State<TState extends StateName = StateName> {
|
|
50
|
+
readonly name: TState;
|
|
51
|
+
readonly flowName: FlowName;
|
|
52
|
+
error?: FlowError;
|
|
53
|
+
readonly payload?: Payloads[TState];
|
|
54
|
+
readonly actions: ActionMap<TState>;
|
|
55
|
+
readonly csrfToken: string;
|
|
31
56
|
readonly status: number;
|
|
32
|
-
readonly
|
|
33
|
-
readonly
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
readonly previousAction?: ActionInfo;
|
|
58
|
+
readonly isCached: boolean;
|
|
59
|
+
readonly cacheKey: string;
|
|
60
|
+
readonly hanko: Hanko;
|
|
61
|
+
invokedAction?: ActionInfo;
|
|
62
|
+
readonly excludeAutoSteps: AutoStepExclusion;
|
|
63
|
+
readonly autoStep?: TState extends AutoSteppedStates ? () => Promise<AnyState> : never;
|
|
64
|
+
readonly passkeyAutofillActivation: TState extends PasskeyAutofillStates ? () => Promise<void> : never;
|
|
65
|
+
/**
|
|
66
|
+
* Constructs a new State instance.
|
|
67
|
+
* @param {Hanko} hanko - The Hanko instance for API interactions.
|
|
68
|
+
* @param {FlowName} flowName - The name of the flow this state belongs to.
|
|
69
|
+
* @param {FlowResponse<TState>} response - The flow response containing state data.
|
|
70
|
+
* @param {StateInitConfig} [options={}] - Configuration options for state initialization.
|
|
71
|
+
*/
|
|
72
|
+
constructor(hanko: Hanko, flowName: FlowName, response: FlowResponse<TState>, options?: StateInitConfig);
|
|
73
|
+
/**
|
|
74
|
+
* Builds the action map for this state, wrapping it in a Proxy to handle undefined actions.
|
|
75
|
+
* @param {Actions} actions - The actions available in this state.
|
|
76
|
+
* @returns {ActionMap<TState>} The action map for the state.
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
private buildActionMap;
|
|
80
|
+
/**
|
|
81
|
+
* Dispatches an event after the state has changed.
|
|
82
|
+
*/
|
|
83
|
+
dispatchAfterStateChangeEvent(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Serializes the current state into a storable format.
|
|
86
|
+
* @returns {SerializedState} The serialized state object.
|
|
87
|
+
*/
|
|
88
|
+
serialize(): SerializedState;
|
|
89
|
+
/**
|
|
90
|
+
* Saves the current state to localStorage.
|
|
91
|
+
* @returns {void}
|
|
92
|
+
*/
|
|
93
|
+
saveToLocalStorage(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Removes the current state from localStorage.
|
|
96
|
+
* @returns {void}
|
|
97
|
+
*/
|
|
98
|
+
removeFromLocalStorage(): void;
|
|
99
|
+
/**
|
|
100
|
+
* Initializes a flow state, processing auto-steps if applicable.
|
|
101
|
+
* @param {Hanko} hanko - The Hanko instance for API interactions.
|
|
102
|
+
* @param {FlowName} flowName - The name of the flow.
|
|
103
|
+
* @param {FlowResponse<any>} response - The initial flow response.
|
|
104
|
+
* @param {StateInitConfig} [options={}] - Configuration options.
|
|
105
|
+
* @param {boolean} [options.dispatchAfterStateChangeEvent=true] - Whether to dispatch an event after state change.
|
|
106
|
+
* @param {AutoStepExclusion} [options.excludeAutoSteps=null] - States to exclude from auto-step processing, or "all".
|
|
107
|
+
* @param {ActionInfo} [options.previousAction=null] - Information about the previous action.
|
|
108
|
+
* @param {boolean} [options.isCached=false] - Whether the state is loaded from cache.
|
|
109
|
+
* @param {string} [options.cacheKey="hanko-flow-state"] - Key for localStorage caching.
|
|
110
|
+
* @returns {Promise<AnyState>} A promise resolving to the initialized state.
|
|
111
|
+
*/
|
|
112
|
+
static initializeFlowState(hanko: Hanko, flowName: FlowName, response: FlowResponse<any>, options?: StateInitConfig): Promise<AnyState>;
|
|
113
|
+
/**
|
|
114
|
+
* Retrieves and parses state data from localStorage.
|
|
115
|
+
* @param {string} cacheKey - The key used to store the state in localStorage.
|
|
116
|
+
* @returns {SerializedState | undefined} The parsed serialized state, or undefined if not found or invalid.
|
|
117
|
+
*/
|
|
118
|
+
static readFromLocalStorage(cacheKey: string): SerializedState | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* Creates a new state instance, using cached or fetched data.
|
|
121
|
+
* @param {Hanko} hanko - The Hanko instance for API interactions.
|
|
122
|
+
* @param {FlowName} flowName - The name of the flow.
|
|
123
|
+
* @param {StateCreateConfig} [config={}] - Configuration options.
|
|
124
|
+
* @param {boolean} [config.dispatchAfterStateChangeEvent=true] - Whether to dispatch an event after state change.
|
|
125
|
+
* @param {AutoStepExclusion} [config.excludeAutoSteps=null] - States to exclude from auto-step processing, or "all".
|
|
126
|
+
* @param {string} [config.cacheKey="hanko-flow-state"] - Key for localStorage caching.
|
|
127
|
+
* @param {boolean} [config.loadFromCache=true] - Whether to attempt loading from cache.
|
|
128
|
+
* @returns {Promise<AnyState>} A promise resolving to the created state.
|
|
129
|
+
*/
|
|
130
|
+
static create(hanko: Hanko, flowName: FlowName, config?: StateCreateConfig): Promise<AnyState>;
|
|
131
|
+
/**
|
|
132
|
+
* Deserializes a state from a serialized state object.
|
|
133
|
+
* @param {Hanko} hanko - The Hanko instance for API interactions.
|
|
134
|
+
* @param {SerializedState} serializedState - The serialized state data.
|
|
135
|
+
* @param {StateCreateConfig} [config={}] - Configuration options.
|
|
136
|
+
* @param {boolean} [config.dispatchAfterStateChangeEvent=true] - Whether to dispatch an event after state change.
|
|
137
|
+
* @param {AutoStepExclusion} [config.excludeAutoSteps=null] - States to exclude from auto-step processing, or "all".
|
|
138
|
+
* @param {string} [config.cacheKey="hanko-flow-state"] - Key for localStorage caching.
|
|
139
|
+
* @param {boolean} [config.loadFromCache=true] - Whether to attempt loading from cache.
|
|
140
|
+
* @returns {Promise<AnyState>} A promise resolving to the deserialized state.
|
|
141
|
+
*/
|
|
142
|
+
static deserialize(hanko: Hanko, serializedState: SerializedState, config?: StateCreateConfig): Promise<AnyState>;
|
|
143
|
+
/**
|
|
144
|
+
* Fetches state data from the server.
|
|
145
|
+
* @param {Hanko} hanko - The Hanko instance for API interactions.
|
|
146
|
+
* @param {string} href - The endpoint to fetch from.
|
|
147
|
+
* @param {any} [body] - Optional request body.
|
|
148
|
+
* @returns {Promise<FlowResponse<any>>} A promise resolving to the flow response.
|
|
149
|
+
*/
|
|
150
|
+
static fetchState(hanko: Hanko, href: string, body?: any): Promise<FlowResponse<any>>;
|
|
151
|
+
/**
|
|
152
|
+
* Creates an error flow response.
|
|
153
|
+
* @param {FlowError} error - The error to include in the response.
|
|
154
|
+
* @returns {FlowResponse<"error">} A flow response with error details.
|
|
155
|
+
* @private
|
|
156
|
+
*/
|
|
157
|
+
private static createErrorResponse;
|
|
54
158
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Represents an actionable operation within a state.
|
|
161
|
+
* @template TInputs - The type of inputs required for the action.
|
|
162
|
+
* @param {ActionType<TInputs>} action - The action type definition.
|
|
163
|
+
* @param {State} parentState - The state this action belongs to.
|
|
164
|
+
* @param {boolean} [enabled=true] - Whether the action is enabled.
|
|
165
|
+
* @category SDK
|
|
166
|
+
* @subcategory FlowAPI
|
|
167
|
+
*/
|
|
168
|
+
export declare class Action<TInputs> {
|
|
169
|
+
readonly enabled: boolean;
|
|
170
|
+
readonly href: string;
|
|
171
|
+
readonly name: string;
|
|
172
|
+
readonly inputs: TInputs;
|
|
173
|
+
private readonly parentState;
|
|
174
|
+
/**
|
|
175
|
+
* Constructs a new Action instance.
|
|
176
|
+
* @param {ActionType<TInputs>} action - The action type definition.
|
|
177
|
+
* @param {State} parentState - The state this action belongs to.
|
|
178
|
+
* @param {boolean} [enabled=true] - Whether the action is enabled.
|
|
179
|
+
*/
|
|
180
|
+
constructor(action: ActionType<TInputs>, parentState: State, enabled?: boolean);
|
|
181
|
+
/**
|
|
182
|
+
* Creates a disabled action instance.
|
|
183
|
+
* @template TInputs - The type of inputs (inferred as empty).
|
|
184
|
+
* @param {string} name - The name of the action.
|
|
185
|
+
* @param {State} parentState - The state this action belongs to.
|
|
186
|
+
* @returns {Action<TInputs>} A disabled action instance.
|
|
187
|
+
*/
|
|
188
|
+
static createDisabled<TInputs>(name: string, parentState: State): Action<TInputs>;
|
|
189
|
+
/**
|
|
190
|
+
* Executes the action, transitioning to a new state.
|
|
191
|
+
* @param {ExtractInputValues<TInputs>} [inputValues=null] - Values for the action's inputs.
|
|
192
|
+
* @param {ActionRunConfig} [config={}] - Configuration options.
|
|
193
|
+
* @param {boolean} [config.dispatchAfterStateChangeEvent=true] - Whether to dispatch an event after state change.
|
|
194
|
+
* @returns {Promise<AnyState>} A promise resolving to the next state.
|
|
195
|
+
* @throws {FlowError} If the action is disabled or already invoked.
|
|
196
|
+
*/
|
|
197
|
+
run(inputValues?: ExtractInputValues<TInputs>, config?: ActionRunConfig): Promise<AnyState>;
|
|
67
198
|
}
|
|
68
|
-
export
|
|
69
|
-
export { State };
|
|
199
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CredentialRequestOptionsJSON, CredentialCreationOptionsJSON, PublicKeyCredentialWithAssertionJSON, PublicKeyCredentialWithAttestationJSON } from "@github/webauthn-json";
|
|
2
|
+
/**
|
|
3
|
+
* Manages WebAuthn credential operations as a singleton, ensuring only one active request at a time.
|
|
4
|
+
* Uses an internal AbortController to cancel previous requests when a new one is initiated.
|
|
5
|
+
*/
|
|
6
|
+
declare class WebauthnManager {
|
|
7
|
+
private static instance;
|
|
8
|
+
private abortController;
|
|
9
|
+
private constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Gets the singleton instance of WebauthnManager.
|
|
12
|
+
* Creates a new instance if one doesn't exist, otherwise returns the existing one.
|
|
13
|
+
* @returns {WebauthnManager} The singleton instance
|
|
14
|
+
*/
|
|
15
|
+
static getInstance(): WebauthnManager;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new abort signal, aborting any ongoing WebAuthn request.
|
|
18
|
+
* @private
|
|
19
|
+
* @returns {AbortSignal} The new abort signal
|
|
20
|
+
*/
|
|
21
|
+
private createAbortSignal;
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves a WebAuthn credential using the provided options.
|
|
24
|
+
* Aborts any previous request before starting a new one.
|
|
25
|
+
* @param {CredentialRequestOptionsJSON} options - The options for credential retrieval
|
|
26
|
+
* @returns {Promise<PublicKeyCredentialWithAssertionJSON>} A promise resolving to the retrieved credential
|
|
27
|
+
* @throws {DOMException} If the WebAuthn request fails (e.g., aborted, not allowed)
|
|
28
|
+
*/
|
|
29
|
+
getWebauthnCredential(options: CredentialRequestOptionsJSON): Promise<PublicKeyCredentialWithAssertionJSON>;
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves a WebAuthn credential with conditional UI mediation.
|
|
32
|
+
* Aborts any previous request before starting a new one.
|
|
33
|
+
* @param {CredentialRequestOptionsJSON} publicKey - The public key options for conditional retrieval
|
|
34
|
+
* @returns {Promise<PublicKeyCredentialWithAssertionJSON>} A promise resolving to the retrieved credential
|
|
35
|
+
* @throws {DOMException} If the WebAuthn request fails (e.g., aborted, not allowed)
|
|
36
|
+
*/
|
|
37
|
+
getConditionalWebauthnCredential(publicKey: CredentialRequestOptionsJSON["publicKey"]): Promise<PublicKeyCredentialWithAssertionJSON>;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new WebAuthn credential using the provided options.
|
|
40
|
+
* Aborts any previous request before starting a new one.
|
|
41
|
+
* @param {CredentialCreationOptionsJSON} options - The options for credential creation
|
|
42
|
+
* @returns {Promise<PublicKeyCredentialWithAttestationJSON>} A promise resolving to the created credential
|
|
43
|
+
* @throws {DOMException} If the WebAuthn request fails (e.g., aborted, not allowed)
|
|
44
|
+
*/
|
|
45
|
+
createWebauthnCredential(options: CredentialCreationOptionsJSON): Promise<PublicKeyCredentialWithAttestationJSON>;
|
|
46
|
+
}
|
|
47
|
+
export default WebauthnManager;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ContinueWithLoginIdentifierInputs, EmailCreateInputs, EmailDeleteInputs, EmailSetPrimaryInputs, EmailVerifyInputs, ExchangeTokenInputs, PasskeyCredentialDeleteInputs, PasskeyCredentialRenameInputs, PasswordRecoveryInputs, PasswordInputs, RegisterClientCapabilitiesInputs, RegisterLoginIdentifierInputs, RegisterPasswordInputs, ThirdpartyOauthInputs, UsernameSetInputs, VerifyPasscodeInputs, WebauthnVerifyAssertionResponseInputs, WebauthnVerifyAttestationResponseInputs, SessionDeleteInputs, OTPCodeInputs, SecurityKeyDeleteInputs, RememberMeInputs } from "./input";
|
|
1
|
+
import { ContinueWithLoginIdentifierInputs, EmailCreateInputs, EmailDeleteInputs, EmailSetPrimaryInputs, EmailVerifyInputs, ExchangeTokenInputs, PasskeyCredentialDeleteInputs, PasskeyCredentialRenameInputs, PasswordRecoveryInputs, PasswordInputs, PatchMetadataInputs, RegisterClientCapabilitiesInputs, RegisterLoginIdentifierInputs, RegisterPasswordInputs, ThirdpartyOauthInputs, UsernameSetInputs, VerifyPasscodeInputs, WebauthnVerifyAssertionResponseInputs, WebauthnVerifyAttestationResponseInputs, SessionDeleteInputs, OTPCodeInputs, SecurityKeyDeleteInputs, RememberMeInputs } from "./input";
|
|
2
2
|
export interface Action<TInputs> {
|
|
3
|
-
|
|
3
|
+
action: string;
|
|
4
4
|
href: string;
|
|
5
5
|
inputs: TInputs;
|
|
6
6
|
description: string;
|
|
@@ -26,6 +26,7 @@ export interface ProfileInitActions {
|
|
|
26
26
|
readonly password_create?: Action<PasswordInputs>;
|
|
27
27
|
readonly password_update?: Action<PasswordInputs>;
|
|
28
28
|
readonly password_delete?: Action<null>;
|
|
29
|
+
readonly patch_metadata: Action<PatchMetadataInputs>;
|
|
29
30
|
readonly security_key_create?: Action<null>;
|
|
30
31
|
readonly security_key_delete?: Action<SecurityKeyDeleteInputs>;
|
|
31
32
|
readonly username_create?: Action<UsernameSetInputs>;
|
|
@@ -123,4 +124,5 @@ export interface DeviceTrustActions {
|
|
|
123
124
|
}
|
|
124
125
|
export interface ThirdPartyActions {
|
|
125
126
|
readonly exchange_token: Action<ExchangeTokenInputs>;
|
|
127
|
+
readonly back?: Action<null>;
|
|
126
128
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { StateName, Actions, Payloads } from "./state";
|
|
2
|
+
import { FlowError } from "./flowError";
|
|
3
|
+
import { State } from "../State";
|
|
4
|
+
type PickStates<TState extends StateName> = TState;
|
|
5
|
+
export type FlowName = "login" | "registration" | "profile" | "token_exchange";
|
|
6
|
+
export type AnyState = {
|
|
7
|
+
[TState in StateName]: State<TState>;
|
|
8
|
+
}[StateName];
|
|
9
|
+
export type AutoStep<TState extends StateName> = (state: State<TState>) => Promise<AnyState>;
|
|
10
|
+
export type AutoSteps = {
|
|
11
|
+
[TState in PickStates<"preflight" | "login_passkey" | "onboarding_verify_passkey_attestation" | "webauthn_credential_verification" | "thirdparty" | "success" | "account_deleted">]: AutoStep<TState>;
|
|
12
|
+
};
|
|
13
|
+
export type PasskeyAutofillActivationHandler<TState extends StateName> = (state: State<TState>) => Promise<void>;
|
|
14
|
+
export type PasskeyAutofillActivationHandlers = {
|
|
15
|
+
[TState in PickStates<"login_init">]: PasskeyAutofillActivationHandler<TState>;
|
|
16
|
+
};
|
|
17
|
+
export interface FlowResponse<TState extends StateName> {
|
|
18
|
+
name: TState;
|
|
19
|
+
status: number;
|
|
20
|
+
payload?: Payloads[TState];
|
|
21
|
+
actions?: Actions[TState];
|
|
22
|
+
csrf_token: string;
|
|
23
|
+
error?: FlowError;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FlowError } from "./flowError";
|
|
2
2
|
import { PublicKeyCredentialWithAssertionJSON, PublicKeyCredentialWithAttestationJSON } from "@github/webauthn-json";
|
|
3
3
|
export interface Input<TValue> {
|
|
4
4
|
readonly name: string;
|
|
5
5
|
readonly type: string;
|
|
6
|
-
value?: TValue;
|
|
6
|
+
readonly value?: TValue;
|
|
7
7
|
readonly min_length?: number;
|
|
8
8
|
readonly max_length?: number;
|
|
9
9
|
readonly required?: boolean;
|
|
10
10
|
readonly hidden?: boolean;
|
|
11
|
-
readonly error?:
|
|
11
|
+
readonly error?: FlowError;
|
|
12
12
|
readonly allowed_values?: AllowedInputValues[];
|
|
13
13
|
}
|
|
14
14
|
export interface AllowedInputValues {
|
|
@@ -35,7 +35,6 @@ export interface RegisterClientCapabilitiesInputs {
|
|
|
35
35
|
readonly webauthn_available: Input<boolean>;
|
|
36
36
|
readonly webauthn_conditional_mediation_available: Input<boolean>;
|
|
37
37
|
readonly webauthn_platform_authenticator_available: Input<boolean>;
|
|
38
|
-
readonly trusted_device: Input<boolean>;
|
|
39
38
|
}
|
|
40
39
|
export interface ContinueWithLoginIdentifierInputs {
|
|
41
40
|
readonly identifier?: Input<string>;
|
|
@@ -60,6 +59,9 @@ export interface EmailVerifyInputs {
|
|
|
60
59
|
export interface PasswordInputs {
|
|
61
60
|
readonly password: Input<string>;
|
|
62
61
|
}
|
|
62
|
+
export interface PatchMetadataInputs {
|
|
63
|
+
readonly patch_metadata: Input<Record<string, any>>;
|
|
64
|
+
}
|
|
63
65
|
export interface UsernameSetInputs {
|
|
64
66
|
readonly username: Input<string>;
|
|
65
67
|
}
|
|
@@ -51,6 +51,10 @@ export interface MFAConfig {
|
|
|
51
51
|
readonly totp_enabled: boolean;
|
|
52
52
|
readonly security_keys_enabled: boolean;
|
|
53
53
|
}
|
|
54
|
+
export type UserMetadata<PublicMetadata extends Record<string, any> = {}, UnsafeMetadata extends Record<string, any> = {}> = {
|
|
55
|
+
public_metadata?: PublicMetadata;
|
|
56
|
+
unsafe_metadata?: UnsafeMetadata;
|
|
57
|
+
};
|
|
54
58
|
export interface User {
|
|
55
59
|
readonly user_id: string;
|
|
56
60
|
readonly passkeys?: WebauthnCredential[];
|
|
@@ -58,6 +62,7 @@ export interface User {
|
|
|
58
62
|
readonly mfa_config?: MFAConfig;
|
|
59
63
|
readonly emails?: Email[];
|
|
60
64
|
readonly username?: Username;
|
|
65
|
+
readonly metadata?: UserMetadata;
|
|
61
66
|
readonly created_at: string;
|
|
62
67
|
readonly updated_at: string;
|
|
63
68
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { State } from "../State";
|
|
2
1
|
import { CredentialOnboardingChooserActions, DeviceTrustActions, LoginInitActions, LoginMethodChooserActions, LoginOTPActions, LoginPasskeyActions, LoginPasswordActions, LoginPasswordRecoveryActions, LoginSecurityKeyActions, MFAAOTPSecretCreationActions, MFAMethodChooserActions, MFASecurityKeyCreationActions, OnboardingCreatePasskeyActions, OnboardingEmailActions, OnboardingUsernameActions, OnboardingVerifyPasskeyAttestationActions, PasscodeConfirmationActions, PasswordCreationActions, PreflightActions, ProfileInitActions, RegistrationInitActions, ThirdPartyActions } from "./action";
|
|
3
2
|
import { LoginInitPayload, LoginPasskeyPayload, MFAOTPSecretCreationPayload, OnboardingVerifyPasskeyAttestationPayload, PasscodeConfirmationPayload, ProfilePayload, SuccessPayload, ThirdPartyPayload } from "./payload";
|
|
4
3
|
export type StateName = "account_deleted" | "credential_onboarding_chooser" | "device_trust" | "error" | "login_init" | "login_method_chooser" | "login_otp" | "login_passkey" | "login_password" | "login_password_recovery" | "login_security_key" | "mfa_method_chooser" | "mfa_otp_secret_creation" | "mfa_security_key_creation" | "onboarding_create_passkey" | "onboarding_email" | "onboarding_username" | "onboarding_verify_passkey_attestation" | "passcode_confirmation" | "password_creation" | "preflight" | "profile_init" | "registration_init" | "success" | "thirdparty" | "webauthn_credential_verification";
|
|
@@ -58,9 +57,3 @@ export interface Payloads {
|
|
|
58
57
|
readonly thirdparty: ThirdPartyPayload;
|
|
59
58
|
readonly webauthn_credential_verification: OnboardingVerifyPasskeyAttestationPayload;
|
|
60
59
|
}
|
|
61
|
-
export type FlowPath = "/login" | "/registration" | "/profile" | "/token_exchange";
|
|
62
|
-
export type FetchNextState = (href: string, body?: any) => Promise<State<any>>;
|
|
63
|
-
export type HandlerFunction<TStateName extends StateName> = (state: State<TStateName>) => any;
|
|
64
|
-
export type Handlers = {
|
|
65
|
-
[TStateName in StateName]: HandlerFunction<TStateName>;
|
|
66
|
-
};
|