@leancodepl/kratos 8.4.0 → 8.5.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.
- package/README.md +368 -4
- package/index.cjs.js +335 -16
- package/index.esm.js +335 -16
- package/package.json +36 -3
- package/src/lib/cards/userAuthCard.d.ts +42 -0
- package/src/lib/cards/userSettingsCard.d.ts +26 -0
- package/src/lib/createKratosClient.d.ts +17 -0
- package/src/lib/flows/useLoginFlow.d.ts +29 -0
- package/src/lib/flows/useLogoutFlow.d.ts +25 -0
- package/src/lib/flows/useReauthenticationFlow.d.ts +23 -0
- package/src/lib/flows/useRecoveryFlow.d.ts +27 -0
- package/src/lib/flows/useRegistrationFlow.d.ts +27 -0
- package/src/lib/flows/useSettingsFlow.d.ts +27 -0
- package/src/lib/flows/useVerificationFlow.d.ts +27 -0
- package/src/lib/kratosContext.d.ts +18 -0
- package/src/lib/kratosContextProvider.d.ts +24 -0
- package/src/lib/sessionManager/baseSessionManager.d.ts +22 -0
- package/index.esm.d.ts +0 -1
- /package/{index.cjs.d.ts → index.d.ts} +0 -0
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
import { FrontendApi, LoginFlow, Session, UpdateLoginFlowBody } from "@ory/client";
|
|
2
|
+
/**
|
|
3
|
+
* Manages Kratos reauthentication flow for elevated security operations.
|
|
4
|
+
*
|
|
5
|
+
* Handles reauthentication flow creation and submission for operations requiring
|
|
6
|
+
* fresh authentication, such as changing passwords or accessing sensitive data.
|
|
7
|
+
*
|
|
8
|
+
* @param kratosClient - Configured Kratos FrontendApi client
|
|
9
|
+
* @param onReauthenticated - Callback executed with session after successful reauthentication
|
|
10
|
+
* @returns Object with current flow and submit function
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { useReauthenticationFlow } from '@leancodepl/kratos';
|
|
14
|
+
*
|
|
15
|
+
* function ReauthForm() {
|
|
16
|
+
* const { flow, submit } = useReauthenticationFlow({
|
|
17
|
+
* kratosClient,
|
|
18
|
+
* onReauthenticated: (session) => navigate('/secure-area')
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* return <form onSubmit={submit}>...</form>;
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
2
25
|
export declare function useReauthenticationFlow({ kratosClient, onReauthenticated, }: {
|
|
3
26
|
kratosClient: FrontendApi;
|
|
4
27
|
onReauthenticated: (session: Session) => void;
|
|
@@ -4,6 +4,33 @@ type RecoveryFlowSearchParams = {
|
|
|
4
4
|
[flowIdParameterName]?: string;
|
|
5
5
|
[returnToParameterName]?: string;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* Manages Kratos account recovery flow state and form submission.
|
|
9
|
+
*
|
|
10
|
+
* Handles recovery flow creation, retrieval, and submission with automatic error handling,
|
|
11
|
+
* URL parameter management, and continue-with callbacks for post-recovery actions.
|
|
12
|
+
*
|
|
13
|
+
* @param kratosClient - Configured Kratos FrontendApi client
|
|
14
|
+
* @param onSessionAlreadyAvailable - Callback when session already exists
|
|
15
|
+
* @param onContinueWith - Optional callback for post-recovery actions
|
|
16
|
+
* @param searchParams - URL search parameters for flow state
|
|
17
|
+
* @param updateSearchParams - Function to update URL search parameters
|
|
18
|
+
* @returns Object with current flow, submit function, and recovery status
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { useRecoveryFlow } from '@leancodepl/kratos';
|
|
22
|
+
*
|
|
23
|
+
* function RecoveryForm() {
|
|
24
|
+
* const { flow, submit, isRecovering } = useRecoveryFlow({
|
|
25
|
+
* kratosClient,
|
|
26
|
+
* onSessionAlreadyAvailable: () => navigate('/dashboard'),
|
|
27
|
+
* updateSearchParams: (params) => setSearchParams(params)
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* return <form onSubmit={submit}>...</form>;
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
7
34
|
export declare function useRecoveryFlow({ kratosClient, onSessionAlreadyAvailable, onContinueWith, searchParams, updateSearchParams, }: {
|
|
8
35
|
kratosClient: FrontendApi;
|
|
9
36
|
onSessionAlreadyAvailable: () => void;
|
|
@@ -4,6 +4,33 @@ type RegistrationFlowSearchParams = {
|
|
|
4
4
|
[flowIdParameterName]?: string;
|
|
5
5
|
[returnToParameterName]?: string;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* Manages Kratos registration flow state and form submission.
|
|
9
|
+
*
|
|
10
|
+
* Handles registration flow creation, retrieval, and submission with automatic error handling,
|
|
11
|
+
* URL parameter management, and continue-with callbacks for post-registration actions.
|
|
12
|
+
*
|
|
13
|
+
* @param kratosClient - Configured Kratos FrontendApi client
|
|
14
|
+
* @param onSessionAlreadyAvailable - Callback when session already exists
|
|
15
|
+
* @param onContinueWith - Optional callback for post-registration actions
|
|
16
|
+
* @param searchParams - URL search parameters for flow state
|
|
17
|
+
* @param updateSearchParams - Function to update URL search parameters
|
|
18
|
+
* @returns Object with current flow, submit function, and registration status
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { useRegisterFlow } from '@leancodepl/kratos';
|
|
22
|
+
*
|
|
23
|
+
* function RegisterForm() {
|
|
24
|
+
* const { flow, submit, isRegistered } = useRegisterFlow({
|
|
25
|
+
* kratosClient,
|
|
26
|
+
* onSessionAlreadyAvailable: () => navigate('/dashboard'),
|
|
27
|
+
* updateSearchParams: (params) => setSearchParams(params)
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* return <form onSubmit={submit}>...</form>;
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
7
34
|
export declare function useRegisterFlow({ kratosClient, onSessionAlreadyAvailable, onContinueWith, searchParams, updateSearchParams, }: {
|
|
8
35
|
kratosClient: FrontendApi;
|
|
9
36
|
onSessionAlreadyAvailable: () => void;
|
|
@@ -5,6 +5,33 @@ type SettingsFlowSearchParams = {
|
|
|
5
5
|
[flowIdParameterName]?: string;
|
|
6
6
|
[returnToParameterName]?: string;
|
|
7
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* Manages Kratos user settings flow state and form submission.
|
|
10
|
+
*
|
|
11
|
+
* Handles settings flow creation, retrieval, and submission for profile updates,
|
|
12
|
+
* password changes, and security settings management.
|
|
13
|
+
*
|
|
14
|
+
* @param kratosClient - Configured Kratos FrontendApi client
|
|
15
|
+
* @param params - Optional Axios request parameters
|
|
16
|
+
* @param onContinueWith - Optional callback for post-settings actions
|
|
17
|
+
* @param searchParams - URL search parameters for flow state
|
|
18
|
+
* @param updateSearchParams - Function to update URL search parameters
|
|
19
|
+
* @returns Object with current flow and submit function
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { useSettingsFlow } from '@leancodepl/kratos';
|
|
23
|
+
*
|
|
24
|
+
* function UserSettingsForm() {
|
|
25
|
+
* const { flow, submit } = useSettingsFlow({
|
|
26
|
+
* kratosClient,
|
|
27
|
+
* onContinueWith: (actions) => console.log('Settings updated'),
|
|
28
|
+
* updateSearchParams: (params) => setSearchParams(params)
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* return <form onSubmit={submit}>...</form>;
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
8
35
|
export declare function useSettingsFlow({ kratosClient, params, onContinueWith, searchParams, updateSearchParams, }: {
|
|
9
36
|
kratosClient: FrontendApi;
|
|
10
37
|
params?: AxiosRequestConfig["params"];
|
|
@@ -4,6 +4,33 @@ type RecoveryFlowSearchParams = {
|
|
|
4
4
|
[flowIdParameterName]?: string;
|
|
5
5
|
[returnToParameterName]?: string;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* Manages Kratos email/phone verification flow state and form submission.
|
|
9
|
+
*
|
|
10
|
+
* Handles verification flow creation, retrieval, and submission with automatic error handling,
|
|
11
|
+
* URL parameter management, and verification status tracking.
|
|
12
|
+
*
|
|
13
|
+
* @param initialFlowId - Optional initial flow ID to start with
|
|
14
|
+
* @param kratosClient - Configured Kratos FrontendApi client
|
|
15
|
+
* @param onVerified - Callback executed when verification is successful
|
|
16
|
+
* @param searchParams - URL search parameters for flow state
|
|
17
|
+
* @param updateSearchParams - Function to update URL search parameters
|
|
18
|
+
* @returns Object with current flow, submit function, and reset function
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { useVerificationFlow } from '@leancodepl/kratos';
|
|
22
|
+
*
|
|
23
|
+
* function VerifyEmailForm() {
|
|
24
|
+
* const { flow, submit, reset } = useVerificationFlow({
|
|
25
|
+
* kratosClient,
|
|
26
|
+
* onVerified: () => navigate('/dashboard'),
|
|
27
|
+
* updateSearchParams: (params) => setSearchParams(params)
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* return <form onSubmit={submit}>...</form>;
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
7
34
|
export declare function useVerificationFlow({ initialFlowId, kratosClient, onVerified, searchParams, updateSearchParams, }: {
|
|
8
35
|
initialFlowId?: string;
|
|
9
36
|
kratosClient: FrontendApi;
|
|
@@ -6,6 +6,24 @@ export type KratosContextData = {
|
|
|
6
6
|
excludeScripts: boolean;
|
|
7
7
|
};
|
|
8
8
|
export declare const kratosContext: import("react").Context<KratosContextData>;
|
|
9
|
+
/**
|
|
10
|
+
* Access Kratos context data with components and error handling.
|
|
11
|
+
*
|
|
12
|
+
* Retrieves the current Kratos context including UI components, error handlers,
|
|
13
|
+
* and configuration. Throws error if components are not initialized.
|
|
14
|
+
*
|
|
15
|
+
* @returns Kratos context data with initialized components
|
|
16
|
+
* @throws Error when Kratos context components are not initialized
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { useKratosContext } from '@leancodepl/kratos';
|
|
20
|
+
*
|
|
21
|
+
* function LoginComponent() {
|
|
22
|
+
* const { components, useHandleFlowError } = useKratosContext();
|
|
23
|
+
* // Use components and error handling...
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
9
27
|
export declare function useKratosContext(): KratosContextData & {
|
|
10
28
|
components: KratosComponents;
|
|
11
29
|
};
|
|
@@ -7,4 +7,28 @@ export type KratosContextProviderProps = {
|
|
|
7
7
|
excludeScripts?: boolean;
|
|
8
8
|
children?: ReactNode;
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Provides Kratos context to child components with customizable configuration.
|
|
12
|
+
*
|
|
13
|
+
* Sets up the React context for Kratos integration, allowing customization of
|
|
14
|
+
* UI components, error handling, and script loading behavior.
|
|
15
|
+
*
|
|
16
|
+
* @param components - Partial override of default Kratos UI components
|
|
17
|
+
* @param useHandleFlowError - Custom error handler for authentication flows
|
|
18
|
+
* @param excludeScripts - Whether to exclude script node execution
|
|
19
|
+
* @param children - Child React components
|
|
20
|
+
* @returns JSX element providing Kratos context
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { KratosContextProvider } from '@leancodepl/kratos';
|
|
24
|
+
*
|
|
25
|
+
* function App() {
|
|
26
|
+
* return (
|
|
27
|
+
* <KratosContextProvider>
|
|
28
|
+
* <LoginPage />
|
|
29
|
+
* </KratosContextProvider>
|
|
30
|
+
* );
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
10
34
|
export declare function KratosContextProvider({ components, useHandleFlowError, excludeScripts, children, }: KratosContextProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
import { Session } from "@ory/client";
|
|
2
2
|
import { Subject } from "rxjs";
|
|
3
|
+
/**
|
|
4
|
+
* Manages Kratos session state with RxJS observables for authentication status.
|
|
5
|
+
*
|
|
6
|
+
* Provides reactive session management with automatic status checking, user identity
|
|
7
|
+
* tracking, and AAL (Authenticator Assurance Level) handling for multi-factor authentication.
|
|
8
|
+
*
|
|
9
|
+
* @param authUrl - Base URL for Kratos authentication endpoints
|
|
10
|
+
* @param loginRoute - Application route for login page
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { BaseSessionManager } from '@leancodepl/kratos';
|
|
14
|
+
*
|
|
15
|
+
* const sessionManager = new BaseSessionManager(
|
|
16
|
+
* 'https://auth.example.com',
|
|
17
|
+
* '/login'
|
|
18
|
+
* );
|
|
19
|
+
*
|
|
20
|
+
* sessionManager.isLoggedIn.subscribe(loggedIn => {
|
|
21
|
+
* console.log('User logged in:', loggedIn);
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
3
25
|
export declare class BaseSessionManager {
|
|
4
26
|
authUrl: string;
|
|
5
27
|
loginRoute: string;
|
package/index.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
|
File without changes
|