@leancodepl/kratos 8.5.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.
Files changed (78) hide show
  1. package/index.cjs.default.js +1 -0
  2. package/index.cjs.js +4681 -0
  3. package/index.cjs.mjs +2 -0
  4. package/index.d.ts +1 -0
  5. package/index.esm.js +4653 -0
  6. package/package.json +1 -6
  7. package/src/index.d.ts +12 -0
  8. package/src/lib/cards/index.d.ts +2 -0
  9. package/src/lib/cards/userAuthCard.d.ts +62 -0
  10. package/src/lib/cards/userSettingsCard.d.ts +36 -0
  11. package/src/lib/createKratosClient.d.ts +19 -0
  12. package/src/lib/defaultComponents/DefaultButtonComponent/index.d.ts +2 -0
  13. package/src/lib/defaultComponents/DefaultCheckboxComponent/index.d.ts +2 -0
  14. package/src/lib/defaultComponents/DefaultImageComponent/index.d.ts +2 -0
  15. package/src/lib/defaultComponents/DefaultInputComponent/index.d.ts +2 -0
  16. package/src/lib/defaultComponents/DefaultLinkComponent/index.d.ts +2 -0
  17. package/src/lib/defaultComponents/DefaultMessageComponent/index.d.ts +2 -0
  18. package/src/lib/defaultComponents/DefaultMessageFormatComponent/index.d.ts +2 -0
  19. package/src/lib/defaultComponents/DefaultTextComponent/index.d.ts +2 -0
  20. package/src/lib/defaultComponents/DefaultUiMessagesComponent/index.d.ts +2 -0
  21. package/src/lib/defaultComponents.d.ts +2 -0
  22. package/src/lib/flows/index.d.ts +7 -0
  23. package/src/lib/flows/useLoginFlow.d.ts +50 -0
  24. package/src/lib/flows/useLogoutFlow.d.ts +33 -0
  25. package/src/lib/flows/useReauthenticationFlow.d.ts +31 -0
  26. package/src/lib/flows/useRecoveryFlow.d.ts +47 -0
  27. package/src/lib/flows/useRegistrationFlow.d.ts +47 -0
  28. package/src/lib/flows/useSettingsFlow.d.ts +47 -0
  29. package/src/lib/flows/useVerificationFlow.d.ts +47 -0
  30. package/src/lib/helpers/errorMessages.d.ts +7 -0
  31. package/src/lib/helpers/filterFlowNodes.d.ts +7 -0
  32. package/src/lib/helpers/formattedMessage.d.ts +4 -0
  33. package/src/lib/helpers/getNodeLabel.d.ts +2 -0
  34. package/src/lib/helpers/node.d.ts +7 -0
  35. package/src/lib/helpers/useScriptNodes.d.ts +5 -0
  36. package/src/lib/helpers/userAuthForm.d.ts +31 -0
  37. package/src/lib/kratosContext.d.ts +29 -0
  38. package/src/lib/kratosContextProvider.d.ts +34 -0
  39. package/src/lib/sections/authCodeSection.d.ts +14 -0
  40. package/src/lib/sections/identifierFirstLoginSection.d.ts +8 -0
  41. package/src/lib/sections/linkSection.d.ts +14 -0
  42. package/src/lib/sections/loginSection.d.ts +8 -0
  43. package/src/lib/sections/lookupSecretSettingsSection.d.ts +8 -0
  44. package/src/lib/sections/oidcSection.d.ts +8 -0
  45. package/src/lib/sections/oidcSettingsSection.d.ts +8 -0
  46. package/src/lib/sections/passkeySettingsSection.d.ts +8 -0
  47. package/src/lib/sections/passwordSettingsSection.d.ts +8 -0
  48. package/src/lib/sections/passwordlessSection.d.ts +8 -0
  49. package/src/lib/sections/profileLoginSection.d.ts +8 -0
  50. package/src/lib/sections/profileRegistrationSection.d.ts +8 -0
  51. package/src/lib/sections/profileSettingsSection.d.ts +8 -0
  52. package/src/lib/sections/registrationSection.d.ts +8 -0
  53. package/src/lib/sections/totpSettingsSection.d.ts +8 -0
  54. package/src/lib/sessionManager/baseSessionManager.d.ts +35 -0
  55. package/src/lib/types/components.d.ts +78 -0
  56. package/src/lib/types/enums/errorId.d.ts +16 -0
  57. package/src/lib/types/enums/errorValidation.d.ts +30 -0
  58. package/src/lib/types/enums/errorValidationLogin.d.ts +9 -0
  59. package/src/lib/types/enums/errorValidationRecovery.d.ts +9 -0
  60. package/src/lib/types/enums/errorValidationRegistration.d.ts +4 -0
  61. package/src/lib/types/enums/errorValidationSettings.d.ts +4 -0
  62. package/src/lib/types/enums/errorValidationVerification.d.ts +9 -0
  63. package/src/lib/types/enums/index.d.ts +14 -0
  64. package/src/lib/types/enums/infoNodeLabel.d.ts +14 -0
  65. package/src/lib/types/enums/infoSelfServiceLogin.d.ts +16 -0
  66. package/src/lib/types/enums/infoSelfServiceRecovery.d.ts +6 -0
  67. package/src/lib/types/enums/infoSelfServiceRegistration.d.ts +7 -0
  68. package/src/lib/types/enums/infoSelfServiceSettings.d.ts +21 -0
  69. package/src/lib/types/enums/infoSelfServiceVerification.d.ts +6 -0
  70. package/src/lib/types/enums/misc.d.ts +10 -0
  71. package/src/lib/types/responseError.d.ts +2 -0
  72. package/src/lib/types/useHandleFlowError.d.ts +13 -0
  73. package/src/lib/utils/filterNodesByGroups.d.ts +22 -0
  74. package/src/lib/utils/getNodeInputType.d.ts +1 -0
  75. package/src/lib/utils/handleCancelError.d.ts +2 -0
  76. package/src/lib/utils/helpers.d.ts +11 -0
  77. package/src/lib/utils/typeGuards.d.ts +24 -0
  78. package/src/lib/utils/variables.d.ts +4 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leancodepl/kratos",
3
- "version": "8.5.0",
3
+ "version": "8.5.1",
4
4
  "license": "Apache-2.0",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -45,11 +45,6 @@
45
45
  "name": "LeanCode",
46
46
  "url": "https://leancode.co"
47
47
  },
48
- "files": [
49
- "dist",
50
- "README.md",
51
- "CHANGELOG.md"
52
- ],
53
48
  "sideEffects": false,
54
49
  "exports": {
55
50
  "./package.json": "./package.json",
package/src/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ export * from "./lib/createKratosClient";
2
+ export * from "./lib/kratosContext";
3
+ export * from "./lib/kratosContextProvider";
4
+ export * from "./lib/utils/variables";
5
+ export * from "./lib/types/responseError";
6
+ export * from "./lib/types/useHandleFlowError";
7
+ export * from "./lib/sessionManager/baseSessionManager";
8
+ export * from "./lib/types/enums";
9
+ export * from "./lib/types/components";
10
+ export * from "./lib/utils/typeGuards";
11
+ export * from "./lib/flows";
12
+ export * from "./lib/cards";
@@ -0,0 +1,2 @@
1
+ export * from "./userAuthCard";
2
+ export * from "./userSettingsCard";
@@ -0,0 +1,62 @@
1
+ import { LoginFlow, RecoveryFlow, RegistrationFlow, UpdateLoginFlowBody, UpdateRecoveryFlowBody, UpdateRegistrationFlowBody, UpdateVerificationFlowBody, VerificationFlow } from "@ory/client";
2
+ import { UserAuthFormAdditionalProps } from "../helpers/userAuthForm";
3
+ type UserAuthCardProps<TBody> = UserAuthFormAdditionalProps<TBody> & {
4
+ className?: string;
5
+ flow: LoginFlow | RecoveryFlow | RegistrationFlow | VerificationFlow;
6
+ flowType: "login" | "recovery" | "registration" | "verification";
7
+ };
8
+ /**
9
+ * Pre-built login card component for Kratos login flows.
10
+ *
11
+ * Renders a complete login form with support for password, passkey, OIDC,
12
+ * multi-factor authentication, and identifier-first flows.
13
+ *
14
+ * @param flow - Kratos login flow object
15
+ * @param onSubmit - Form submission handler
16
+ * @param className - Optional CSS class name
17
+ * @returns JSX element with login form
18
+ */
19
+ export declare const LoginCard: ({ ...props }: Omit<UserAuthCardProps<UpdateLoginFlowBody>, "flow" | "flowType"> & {
20
+ flow: LoginFlow;
21
+ }) => import("react/jsx-runtime").JSX.Element;
22
+ /**
23
+ * Pre-built verification card component for Kratos verification flows.
24
+ *
25
+ * Renders a complete verification form for email/phone verification processes.
26
+ *
27
+ * @param flow - Kratos verification flow object
28
+ * @param onSubmit - Form submission handler
29
+ * @param className - Optional CSS class name
30
+ * @returns JSX element with verification form
31
+ */
32
+ export declare const VerificationCard: ({ ...props }: Omit<UserAuthCardProps<UpdateVerificationFlowBody>, "flow" | "flowType"> & {
33
+ flow: VerificationFlow;
34
+ }) => import("react/jsx-runtime").JSX.Element;
35
+ /**
36
+ * Pre-built registration card component for Kratos registration flows.
37
+ *
38
+ * Renders a complete registration form with support for profile fields,
39
+ * password, passkey, and OIDC registration methods.
40
+ *
41
+ * @param flow - Kratos registration flow object
42
+ * @param onSubmit - Form submission handler
43
+ * @param className - Optional CSS class name
44
+ * @returns JSX element with registration form
45
+ */
46
+ export declare const RegistrationCard: ({ ...props }: Omit<UserAuthCardProps<UpdateRegistrationFlowBody>, "flow" | "flowType"> & {
47
+ flow: RegistrationFlow;
48
+ }) => import("react/jsx-runtime").JSX.Element;
49
+ /**
50
+ * Pre-built recovery card component for Kratos account recovery flows.
51
+ *
52
+ * Renders a complete recovery form for password reset and account recovery processes.
53
+ *
54
+ * @param flow - Kratos recovery flow object
55
+ * @param onSubmit - Form submission handler
56
+ * @param className - Optional CSS class name
57
+ * @returns JSX element with recovery form
58
+ */
59
+ export declare const RecoveryCard: ({ ...props }: Omit<UserAuthCardProps<UpdateRecoveryFlowBody>, "flow" | "flowType"> & {
60
+ flow: RecoveryFlow;
61
+ }) => import("react/jsx-runtime").JSX.Element;
62
+ export {};
@@ -0,0 +1,36 @@
1
+ import { JSX } from "react";
2
+ import { SettingsFlow, UiNodeGroupEnum, UpdateSettingsFlowBody } from "@ory/client";
3
+ import { UserAuthFormAdditionalProps } from "../helpers/userAuthForm";
4
+ export type UserSettingsFlowType = typeof UiNodeGroupEnum.LookupSecret | typeof UiNodeGroupEnum.Oidc | typeof UiNodeGroupEnum.Passkey | typeof UiNodeGroupEnum.Password | typeof UiNodeGroupEnum.Profile | typeof UiNodeGroupEnum.Totp;
5
+ export type UserSettingsCardProps = UserAuthFormAdditionalProps<UpdateSettingsFlowBody> & {
6
+ flow: SettingsFlow;
7
+ flowType: UserSettingsFlowType;
8
+ className?: string;
9
+ };
10
+ /**
11
+ * Pre-built settings card component for Kratos settings flows.
12
+ *
13
+ * Renders different settings sections based on flow type: profile, password,
14
+ * passkey, TOTP, lookup secrets, or OIDC settings management.
15
+ *
16
+ * @param flow - Kratos settings flow object
17
+ * @param flowType - Type of settings flow to render
18
+ * @param onSubmit - Form submission handler
19
+ * @param className - Optional CSS class name
20
+ * @returns JSX element with settings form or null if flow type unavailable
21
+ * @example
22
+ * ```typescript
23
+ * import { UserSettingsCard } from '@leancodepl/kratos';
24
+ *
25
+ * function ProfileSettings() {
26
+ * return (
27
+ * <UserSettingsCard
28
+ * flow={settingsFlow}
29
+ * flowType="profile"
30
+ * onSubmit={handleSubmit}
31
+ * />
32
+ * );
33
+ * }
34
+ * ```
35
+ */
36
+ export declare function UserSettingsCard({ flow, flowType, onSubmit, className }: UserSettingsCardProps): JSX.Element | null;
@@ -0,0 +1,19 @@
1
+ import { ConfigurationParameters, FrontendApi } from "@ory/client";
2
+ /**
3
+ * Creates Ory Kratos FrontendApi client with axios and credentials configuration.
4
+ *
5
+ * Initializes a Kratos client for browser-based applications with automatic
6
+ * cookie handling and CORS support for authentication flows.
7
+ *
8
+ * @param configuration - Kratos client configuration parameters
9
+ * @returns Configured FrontendApi instance for Kratos operations
10
+ * @example
11
+ * ```typescript
12
+ * import { createKratosClient } from '@leancodepl/kratos';
13
+ *
14
+ * const kratosClient = createKratosClient({
15
+ * basePath: 'https://auth.example.com'
16
+ * });
17
+ * ```
18
+ */
19
+ export declare function createKratosClient(configuration: ConfigurationParameters): FrontendApi;
@@ -0,0 +1,2 @@
1
+ import type { ButtonComponentProps } from "../../types/components";
2
+ export declare function DefaultButtonComponent({ header, ...props }: ButtonComponentProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import type { CheckboxComponentProps } from "../../types/components";
2
+ export declare function DefaultCheckboxComponent({ label, helperMessage, ...props }: CheckboxComponentProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import type { ImageComponentProps } from "../../types/components";
2
+ export declare function DefaultImageComponent({ header, ...props }: ImageComponentProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import type { InputComponentProps } from "../../types/components";
2
+ export declare function DefaultInputComponent({ helperMessage, header, ...props }: InputComponentProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import type { LinkComponentProps } from "../../types/components";
2
+ export declare function DefaultLinkComponent({ href: _href, ...props }: LinkComponentProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import type { MessageComponentProps } from "../../types/components";
2
+ export declare function DefaultMessageComponent({ children }: MessageComponentProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import type { MessageFormatComponentProps } from "../../types/components";
2
+ export declare function DefaultMessageFormatComponent({ text }: MessageFormatComponentProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import type { TextComponentProps } from "../../types/components";
2
+ export declare function DefaultTextComponent({ label, codes }: TextComponentProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import type { UiMessagesComponentProps } from "../../types/components";
2
+ export declare function DefaultUiMessagesComponent(props: UiMessagesComponentProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import type { KratosComponents } from "./types/components";
2
+ export declare const defaultComponents: KratosComponents;
@@ -0,0 +1,7 @@
1
+ export * from "./useReauthenticationFlow";
2
+ export * from "./useRecoveryFlow";
3
+ export * from "./useSettingsFlow";
4
+ export * from "./useLoginFlow";
5
+ export * from "./useRegistrationFlow";
6
+ export * from "./useVerificationFlow";
7
+ export * from "./useLogoutFlow";
@@ -0,0 +1,50 @@
1
+ import { FrontendApi, LoginFlow, Session, UpdateLoginFlowBody } from "@ory/client";
2
+ import { aalParameterName, flowIdParameterName, refreshParameterName, returnToParameterName } from "../utils/variables";
3
+ export type LoginSearchParams = {
4
+ [flowIdParameterName]?: string;
5
+ [returnToParameterName]?: string;
6
+ [refreshParameterName]?: string;
7
+ [aalParameterName]?: string;
8
+ };
9
+ /**
10
+ * Manages Kratos login flow state and form submission.
11
+ *
12
+ * Handles login flow creation, retrieval, and submission with automatic error handling,
13
+ * URL parameter management, and session callbacks. Supports multi-factor authentication
14
+ * and refresh flows.
15
+ *
16
+ * @param kratosClient - Configured Kratos FrontendApi client
17
+ * @param returnTo - URL to redirect after successful login
18
+ * @param onLoggedIn - Callback executed when user successfully logs in
19
+ * @param onSessionAlreadyAvailable - Callback when session already exists
20
+ * @param searchParams - URL search parameters for flow state
21
+ * @param updateSearchParams - Function to update URL search parameters
22
+ * @returns Object with current flow and submit function
23
+ * @example
24
+ * ```typescript
25
+ * import { useLoginFlow } from '@leancodepl/kratos';
26
+ *
27
+ * function LoginForm() {
28
+ * const { flow, submit } = useLoginFlow({
29
+ * kratosClient,
30
+ * onLoggedIn: (session) => navigate('/dashboard'),
31
+ * updateSearchParams: (params) => setSearchParams(params)
32
+ * });
33
+ *
34
+ * return <form onSubmit={submit}>...</form>;
35
+ * }
36
+ * ```
37
+ */
38
+ export declare function useLoginFlow({ kratosClient, returnTo, onLoggedIn, onSessionAlreadyAvailable, searchParams, updateSearchParams, }: {
39
+ kratosClient: FrontendApi;
40
+ returnTo?: string;
41
+ onLoggedIn?: (session: Session) => void;
42
+ onSessionAlreadyAvailable?: () => void;
43
+ updateSearchParams: (searchParams: LoginSearchParams) => void;
44
+ searchParams?: LoginSearchParams;
45
+ }): {
46
+ flow: LoginFlow | undefined;
47
+ submit: ({ body }: {
48
+ body: UpdateLoginFlowBody;
49
+ }) => void;
50
+ };
@@ -0,0 +1,33 @@
1
+ import { FrontendApi } from "@ory/client";
2
+ /**
3
+ * Manages Kratos user logout flow with callback support.
4
+ *
5
+ * Provides a logout function that creates and executes logout flow,
6
+ * handling token invalidation and redirect logic.
7
+ *
8
+ * @param kratosClient - Configured Kratos FrontendApi client
9
+ * @param returnTo - Optional URL to redirect after logout
10
+ * @param onLoggedOut - Optional callback executed after successful logout
11
+ * @returns Object with logout function
12
+ * @example
13
+ * ```typescript
14
+ * import { useLogoutFlow } from '@leancodepl/kratos';
15
+ *
16
+ * function LogoutButton() {
17
+ * const { logout } = useLogoutFlow({
18
+ * kratosClient,
19
+ * returnTo: '/login',
20
+ * onLoggedOut: () => console.log('User logged out')
21
+ * });
22
+ *
23
+ * return <button onClick={logout}>Logout</button>;
24
+ * }
25
+ * ```
26
+ */
27
+ export declare function useLogoutFlow({ kratosClient, returnTo, onLoggedOut, }: {
28
+ kratosClient: FrontendApi;
29
+ returnTo?: string;
30
+ onLoggedOut?: () => void;
31
+ }): {
32
+ logout: () => Promise<void>;
33
+ };
@@ -0,0 +1,31 @@
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
+ */
25
+ export declare function useReauthenticationFlow({ kratosClient, onReauthenticated, }: {
26
+ kratosClient: FrontendApi;
27
+ onReauthenticated: (session: Session) => void;
28
+ }): {
29
+ flow: LoginFlow | undefined;
30
+ submit: (values: UpdateLoginFlowBody) => Promise<unknown> | undefined;
31
+ };
@@ -0,0 +1,47 @@
1
+ import { ContinueWith, FrontendApi, RecoveryFlow, UpdateRecoveryFlowBody } from "@ory/client";
2
+ import { flowIdParameterName, returnToParameterName } from "../utils/variables";
3
+ type RecoveryFlowSearchParams = {
4
+ [flowIdParameterName]?: string;
5
+ [returnToParameterName]?: string;
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
+ */
34
+ export declare function useRecoveryFlow({ kratosClient, onSessionAlreadyAvailable, onContinueWith, searchParams, updateSearchParams, }: {
35
+ kratosClient: FrontendApi;
36
+ onSessionAlreadyAvailable: () => void;
37
+ onContinueWith?: (continueWith: ContinueWith[]) => void;
38
+ searchParams?: RecoveryFlowSearchParams;
39
+ updateSearchParams: (searchParams: RecoveryFlowSearchParams) => void;
40
+ }): {
41
+ flow: RecoveryFlow | undefined;
42
+ submit: ({ body }: {
43
+ body: UpdateRecoveryFlowBody;
44
+ }) => Promise<unknown> | undefined;
45
+ isRecovering: boolean;
46
+ };
47
+ export {};
@@ -0,0 +1,47 @@
1
+ import { ContinueWith, FrontendApi, RegistrationFlow, UpdateRegistrationFlowBody } from "@ory/client";
2
+ import { flowIdParameterName, returnToParameterName } from "../utils/variables";
3
+ type RegistrationFlowSearchParams = {
4
+ [flowIdParameterName]?: string;
5
+ [returnToParameterName]?: string;
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
+ */
34
+ export declare function useRegisterFlow({ kratosClient, onSessionAlreadyAvailable, onContinueWith, searchParams, updateSearchParams, }: {
35
+ kratosClient: FrontendApi;
36
+ onSessionAlreadyAvailable: () => void;
37
+ onContinueWith?: (continueWith: ContinueWith[]) => void;
38
+ searchParams?: RegistrationFlowSearchParams;
39
+ updateSearchParams: (searchParams: RegistrationFlowSearchParams) => void;
40
+ }): {
41
+ flow: RegistrationFlow | undefined;
42
+ submit: ({ body }: {
43
+ body: UpdateRegistrationFlowBody;
44
+ }) => Promise<unknown> | undefined;
45
+ isRegistered: boolean;
46
+ };
47
+ export {};
@@ -0,0 +1,47 @@
1
+ import { ContinueWith, FrontendApi, SettingsFlow, UpdateSettingsFlowBody } from "@ory/client";
2
+ import { AxiosRequestConfig } from "axios";
3
+ import { flowIdParameterName, returnToParameterName } from "../utils/variables";
4
+ type SettingsFlowSearchParams = {
5
+ [flowIdParameterName]?: string;
6
+ [returnToParameterName]?: string;
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
+ */
35
+ export declare function useSettingsFlow({ kratosClient, params, onContinueWith, searchParams, updateSearchParams, }: {
36
+ kratosClient: FrontendApi;
37
+ params?: AxiosRequestConfig["params"];
38
+ onContinueWith?: (continueWith: ContinueWith[]) => void;
39
+ searchParams?: SettingsFlowSearchParams;
40
+ updateSearchParams: (searchParams: SettingsFlowSearchParams) => void;
41
+ }): {
42
+ flow: SettingsFlow | undefined;
43
+ submit: ({ body }: {
44
+ body: UpdateSettingsFlowBody;
45
+ }) => Promise<unknown> | undefined;
46
+ };
47
+ export {};
@@ -0,0 +1,47 @@
1
+ import { FrontendApi, UpdateVerificationFlowBody, VerificationFlow } from "@ory/client";
2
+ import { flowIdParameterName, returnToParameterName } from "../utils/variables";
3
+ type RecoveryFlowSearchParams = {
4
+ [flowIdParameterName]?: string;
5
+ [returnToParameterName]?: string;
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
+ */
34
+ export declare function useVerificationFlow({ initialFlowId, kratosClient, onVerified, searchParams, updateSearchParams, }: {
35
+ initialFlowId?: string;
36
+ kratosClient: FrontendApi;
37
+ onVerified: () => void;
38
+ searchParams?: RecoveryFlowSearchParams;
39
+ updateSearchParams: (searchParams: RecoveryFlowSearchParams) => void;
40
+ }): {
41
+ flow: VerificationFlow | undefined;
42
+ submit: ({ body }: {
43
+ body: UpdateVerificationFlowBody;
44
+ }) => Promise<unknown> | undefined;
45
+ reset: () => void;
46
+ };
47
+ export {};
@@ -0,0 +1,7 @@
1
+ import { UiNode, UiText } from "@ory/client";
2
+ type NodeMessagesProps = {
3
+ nodes?: UiNode[];
4
+ uiMessages?: UiText[];
5
+ };
6
+ export declare function NodeMessages({ nodes, uiMessages }: NodeMessagesProps): import("react/jsx-runtime").JSX.Element | null;
7
+ export {};
@@ -0,0 +1,7 @@
1
+ import { FilterNodesByGroups } from "../utils/filterNodesByGroups";
2
+ type FilterFlowNodesProps = {
3
+ filter: FilterNodesByGroups;
4
+ includeCSRF?: boolean;
5
+ };
6
+ export declare function FilterFlowNodes({ filter, includeCSRF, ...overrides }: FilterFlowNodesProps): import("react/jsx-runtime").JSX.Element | null;
7
+ export {};
@@ -0,0 +1,4 @@
1
+ import { UiText } from "@ory/client";
2
+ export declare function FormattedMessage({ message }: {
3
+ message?: Omit<UiText, "type">;
4
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,2 @@
1
+ import { UiNode, UiText } from "@ory/client";
2
+ export declare const getNodeLabel: (node: UiNode) => UiText | undefined;
@@ -0,0 +1,7 @@
1
+ import { UiNode } from "@ory/client";
2
+ type NodeProps = {
3
+ node: UiNode;
4
+ className?: string;
5
+ };
6
+ export declare function Node({ node, className }: NodeProps): import("react/jsx-runtime").JSX.Element | null;
7
+ export {};
@@ -0,0 +1,5 @@
1
+ import { UiNode } from "@ory/client";
2
+ export declare function useScriptNodes({ nodes, excludeScripts }: {
3
+ nodes: UiNode[];
4
+ excludeScripts?: boolean;
5
+ }): void;
@@ -0,0 +1,31 @@
1
+ import { ReactNode } from "react";
2
+ import { LoginFlow, RecoveryFlow, RegistrationFlow, SettingsFlow, VerificationFlow } from "@ory/client";
3
+ import { FilterNodesByGroups } from "../utils/filterNodesByGroups";
4
+ export type SelfServiceFlow = LoginFlow | RecoveryFlow | RegistrationFlow | SettingsFlow | VerificationFlow;
5
+ /**
6
+ * Additional props that can be passed to the UserAuthForm component
7
+ * @see UserAuthForm
8
+ *
9
+ * @param onSubmit - function that is called when the form is submitted. It automatically maps the form data to the request body and prevents native form submits.
10
+ */
11
+ export type UserAuthFormAdditionalProps<TBody> = {
12
+ onSubmit?: ({ body, event }: {
13
+ body: TBody;
14
+ event?: React.FormEvent<HTMLFormElement>;
15
+ }) => void;
16
+ };
17
+ export type UserAuthFormProps<TBody> = Omit<React.FormHTMLAttributes<HTMLFormElement>, "onSubmit"> & UserAuthFormAdditionalProps<TBody> & {
18
+ flow: SelfServiceFlow;
19
+ children: ReactNode;
20
+ formFilterOverride?: FilterNodesByGroups;
21
+ submitOnEnter?: boolean;
22
+ className?: string;
23
+ };
24
+ /**
25
+ * UserAuthForm is a component that renders a form for a given Ory flow.
26
+ * It automatically adds the form action and method and adds csrf tokens to the form.
27
+ * When the `onSubmit` parameter is passed, it also automatically maps the form data to the request body and prevents native form submits.
28
+ * @see UserAuthFormProps
29
+ * @returns JSX.Element
30
+ */
31
+ export declare function UserAuthForm<TBody>({ flow, children, submitOnEnter, onSubmit, formFilterOverride, ...props }: UserAuthFormProps<TBody>): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,29 @@
1
+ import type { KratosComponents } from "./types/components";
2
+ import type { UseHandleFlowError } from "./types/useHandleFlowError";
3
+ export type KratosContextData = {
4
+ components: KratosComponents | undefined;
5
+ useHandleFlowError: UseHandleFlowError;
6
+ excludeScripts: boolean;
7
+ };
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
+ */
27
+ export declare function useKratosContext(): KratosContextData & {
28
+ components: KratosComponents;
29
+ };