@q2devel/q2-storybook 1.0.26 → 1.0.28

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 (83) hide show
  1. package/dist/auth/Auth.types.d.ts +32 -0
  2. package/dist/auth/Auth.types.js +1 -0
  3. package/dist/auth/components/AuthenticatedFactory.d.ts +7 -0
  4. package/dist/auth/components/AuthenticatedFactory.js +21 -0
  5. package/dist/auth/components/AuthenticatedFactory.types.d.ts +4 -0
  6. package/dist/auth/components/AuthenticatedFactory.types.js +1 -0
  7. package/dist/auth/config/Config.d.ts +3 -0
  8. package/dist/auth/config/Config.js +19 -0
  9. package/dist/auth/config/config.types.d.ts +27 -0
  10. package/dist/auth/config/config.types.js +1 -0
  11. package/dist/auth/context/AuthContextFactory.d.ts +3 -0
  12. package/dist/auth/context/AuthContextFactory.js +19 -0
  13. package/dist/auth/hooks/useCurrentUserHookFactory.d.ts +11 -0
  14. package/dist/auth/hooks/useCurrentUserHookFactory.js +17 -0
  15. package/dist/auth/hooks/useCurrentUserUpdateHookFactory.d.ts +9 -0
  16. package/dist/auth/hooks/useCurrentUserUpdateHookFactory.js +28 -0
  17. package/dist/auth/hooks/useCurrentUserUpdatePasswordHookFactory.d.ts +7 -0
  18. package/dist/auth/hooks/useCurrentUserUpdatePasswordHookFactory.js +31 -0
  19. package/dist/auth/hooks/useForgotPasswordHookFactory.d.ts +7 -0
  20. package/dist/auth/hooks/useForgotPasswordHookFactory.js +26 -0
  21. package/dist/auth/hooks/useResetPasswordHookFactory.d.ts +7 -0
  22. package/dist/auth/hooks/useResetPasswordHookFactory.js +29 -0
  23. package/dist/auth/hooks/useSignInHookFactory.d.ts +7 -0
  24. package/dist/auth/hooks/useSignInHookFactory.js +30 -0
  25. package/dist/auth/hooks/useSignOutHookFactory.d.ts +6 -0
  26. package/dist/auth/hooks/useSignOutHookFactory.js +30 -0
  27. package/dist/auth/hooks/useSignUpHookFactory.d.ts +7 -0
  28. package/dist/auth/hooks/useSignUpHookFactory.js +30 -0
  29. package/dist/auth/index.d.ts +53 -0
  30. package/dist/auth/index.js +30 -0
  31. package/dist/auth/provider/AuthContextProviderFactory.d.ts +6 -0
  32. package/dist/auth/provider/AuthContextProviderFactory.js +46 -0
  33. package/dist/auth/service/AuthService.d.ts +15 -0
  34. package/dist/auth/service/AuthService.js +103 -0
  35. package/dist/auth/service/AuthService.types.d.ts +33 -0
  36. package/dist/auth/service/AuthService.types.js +1 -0
  37. package/dist/auth/service/index.d.ts +2 -0
  38. package/dist/auth/service/index.js +3 -0
  39. package/dist/auth/types/index.d.ts +14 -0
  40. package/dist/auth/types/index.js +1 -0
  41. package/dist/auth/utils/Helper.d.ts +1 -0
  42. package/dist/auth/utils/Helper.js +10 -0
  43. package/dist/auth/utils/Storage.d.ts +6 -0
  44. package/dist/auth/utils/Storage.js +57 -0
  45. package/dist/components/badge/Badge.d.ts +1 -2
  46. package/dist/components/badge/Badge.js +3 -7
  47. package/dist/components/banner/Banner.d.ts +48 -0
  48. package/dist/components/banner/Banner.js +121 -0
  49. package/dist/components/basket-dialog/BasketDialog.d.ts +55 -0
  50. package/dist/components/basket-dialog/BasketDialog.js +101 -0
  51. package/dist/components/button/Button.js +3 -5
  52. package/dist/components/icon/CloseIcon.d.ts +2 -0
  53. package/dist/components/icon/CloseIcon.js +2 -0
  54. package/dist/components/icon/InfoIcon.d.ts +2 -0
  55. package/dist/components/icon/InfoIcon.js +2 -0
  56. package/dist/components/label/Label.d.ts +11 -0
  57. package/dist/components/label/Label.js +7 -0
  58. package/dist/components/nav-bar/NavBar.d.ts +19 -0
  59. package/dist/components/nav-bar/NavBar.js +17 -0
  60. package/dist/components/product-card/ProductCard.d.ts +61 -0
  61. package/dist/components/product-card/ProductCard.js +110 -0
  62. package/dist/components/select-field/SelectField.d.ts +27 -0
  63. package/dist/components/select-field/SelectField.js +122 -0
  64. package/dist/components/select-field/SelectFieldOption.d.ts +4 -0
  65. package/dist/components/select-field/SelectFieldOption.js +7 -0
  66. package/dist/components/text-field/TextField.d.ts +21 -0
  67. package/dist/components/text-field/TextField.js +57 -0
  68. package/dist/components/text-field/TextField.types.d.ts +22 -0
  69. package/dist/components/text-field/TextField.types.js +1 -0
  70. package/dist/components/text-with-image/ImageWithText.js +3 -11
  71. package/dist/components/tooltip/Tooltip.d.ts +18 -0
  72. package/dist/components/tooltip/Tooltip.js +18 -0
  73. package/dist/index.d.ts +11 -2
  74. package/dist/index.js +14 -3
  75. package/dist/index.mjs +10571 -0
  76. package/dist/style.css +1 -0
  77. package/dist/utils/Helper.d.ts +0 -0
  78. package/dist/utils/Helper.js +1 -0
  79. package/dist/utils/StyleHelper.d.ts +4 -0
  80. package/dist/utils/StyleHelper.js +8 -0
  81. package/package.json +73 -55
  82. package/dist/components/head/Heading1.d.ts +0 -9
  83. package/dist/components/head/Heading1.js +0 -14
@@ -0,0 +1,32 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { Context, PropsWithChildren } from 'react';
3
+ import { AccessToken, DeepNonRequired } from './types';
4
+ import { AuthenticationSettings } from './config/config.types';
5
+ export type AuthContextType<UserType> = Context<AuthContextState<UserType>>;
6
+ export type LoadingType = 'SIGN_IN' | 'SIGN_UP' | 'SIGN_OUT' | 'FORGOT_PASSWORD' | 'RESET_PASSWORD' | 'CURRENT_USER' | 'UPDATE_CURRENT_USER' | 'UPDATE_CURRENT_USER_PASSWORD';
7
+ export type TokenStorage = {
8
+ get: () => AccessToken | undefined;
9
+ set: (accessToken?: AccessToken) => void;
10
+ };
11
+ export type AuthContextState<UserType> = {
12
+ config: AuthenticationSettings;
13
+ axiosInstance: AxiosInstance;
14
+ tokenStorage?: TokenStorage;
15
+ accessToken?: AccessToken;
16
+ currentUser?: UserType;
17
+ loading: LoadingType[];
18
+ isLogged: boolean;
19
+ isReady: boolean;
20
+ setAccessToken: (value?: AccessToken) => void;
21
+ setCurrentUser: (value?: UserType) => void;
22
+ refetchCurrentUser: () => void;
23
+ addLoading: (value: LoadingType) => void;
24
+ removeLoading: (value: LoadingType) => void;
25
+ destroyAccessToken: () => void;
26
+ };
27
+ export type AuthProviderProps<UserType = unknown> = PropsWithChildren<{
28
+ config?: DeepNonRequired<AuthenticationSettings>;
29
+ axiosInstance: AxiosInstance;
30
+ initialAccessToken?: AccessToken;
31
+ initialCurrentUser?: UserType;
32
+ }>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { AuthContextType } from '../Auth.types';
2
+ import { AuthenticatedProps } from './AuthenticatedFactory.types';
3
+ declare const createAuthenticatedComponent: <UserType extends unknown>(AuthContext: AuthContextType<UserType>) => {
4
+ ({ children, middleware }: AuthenticatedProps): import("react/jsx-runtime").JSX.Element | null;
5
+ displayName: string;
6
+ };
7
+ export default createAuthenticatedComponent;
@@ -0,0 +1,21 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ // src/auth/components/AuthenticatedFactory.tsx
3
+ import { useContext } from 'react';
4
+ const createAuthenticatedComponent = (AuthContext) => {
5
+ const Authenticated = ({ children, middleware }) => {
6
+ const { isLogged, isReady } = useContext(AuthContext);
7
+ if (!isReady) {
8
+ return null;
9
+ }
10
+ if (middleware === 'only-logged' && !isLogged) {
11
+ return null;
12
+ }
13
+ if (middleware === 'only-guest' && isLogged) {
14
+ return null;
15
+ }
16
+ return _jsx(_Fragment, { children: children });
17
+ };
18
+ Authenticated.displayName = 'Authenticated';
19
+ return Authenticated;
20
+ };
21
+ export default createAuthenticatedComponent;
@@ -0,0 +1,4 @@
1
+ import { PropsWithChildren } from 'react';
2
+ export type AuthenticatedProps = PropsWithChildren<{
3
+ middleware?: 'only-logged' | 'only-guest';
4
+ }>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { AuthenticationSettings } from './config.types';
2
+ declare const config: AuthenticationSettings;
3
+ export default config;
@@ -0,0 +1,19 @@
1
+ // Defaultní konfigurace
2
+ const config = {
3
+ tokenStorageType: 'localStorage',
4
+ tokenStorageKey: 'auth-token',
5
+ logoutWhenFailedLoadUser: true,
6
+ getDataFromRequest: (data) => data.data,
7
+ getTokenFromRequest: (data) => data.token,
8
+ signInRoute: '/api/auth/login',
9
+ defaultRequestType: 'json',
10
+ signOutRoute: '/api/auth/logout',
11
+ signUpRoute: '/api/auth/register',
12
+ currentUserRoute: '/api/auth/user',
13
+ currentUserUpdateRoute: '/api/auth/user',
14
+ currentUserChangePasswordRoute: '/api/auth/user/password',
15
+ currentUserChangeAvatarRoute: '/api/auth/user/avatar',
16
+ forgotPasswordRoute: '/api/auth/forgot-password',
17
+ resetPasswordRoute: '/api/auth/reset-password',
18
+ };
19
+ export default config;
@@ -0,0 +1,27 @@
1
+ import { AccessToken, TokenStorageProvider } from '../types';
2
+ export type TokenStorageType = 'localStorage' | 'cookie' | 'memory';
3
+ export type RequestDataType = 'json' | 'form-data';
4
+ export type AuthenticationSettings = {
5
+ tokenStorageType: TokenStorageType | TokenStorageProvider;
6
+ tokenStorageKey: string;
7
+ logoutWhenFailedLoadUser: boolean;
8
+ getDataFromRequest: (data: any) => unknown;
9
+ getTokenFromRequest: (data: any) => AccessToken;
10
+ signInRoute: string;
11
+ defaultRequestType: RequestDataType;
12
+ signInRouteRequestType?: RequestDataType;
13
+ signOutRoute: string;
14
+ signOutRouteRequestType?: RequestDataType;
15
+ signUpRoute: string;
16
+ signUpRouteRequestType?: RequestDataType;
17
+ currentUserRoute: string;
18
+ currentUserUpdateRoute: string;
19
+ currentUserUpdateRouteRequestDataType?: RequestDataType;
20
+ currentUserChangePasswordRoute: string;
21
+ currentUserChangePasswordRouteRequestDataType?: RequestDataType;
22
+ currentUserChangeAvatarRoute: string;
23
+ forgotPasswordRoute: string;
24
+ forgotPasswordRouteRequestDataType?: RequestDataType;
25
+ resetPasswordRoute: string;
26
+ resetPasswordRouteRequestDataType?: RequestDataType;
27
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { AuthContextState } from '../Auth.types';
2
+ declare const createAuthContext: <UserType>() => import("react").Context<AuthContextState<UserType>>;
3
+ export default createAuthContext;
@@ -0,0 +1,19 @@
1
+ 'use client';
2
+ import { createContext } from 'react';
3
+ const createAuthContext = () => {
4
+ const defaultState = {
5
+ config: {},
6
+ axiosInstance: {},
7
+ loading: [],
8
+ isLogged: false,
9
+ isReady: false,
10
+ setAccessToken: () => { },
11
+ setCurrentUser: () => { },
12
+ refetchCurrentUser: () => { },
13
+ addLoading: () => { },
14
+ removeLoading: () => { },
15
+ destroyAccessToken: () => { },
16
+ };
17
+ return createContext(defaultState);
18
+ };
19
+ export default createAuthContext;
@@ -0,0 +1,11 @@
1
+ import { AuthContextType } from '../Auth.types';
2
+ declare const createUseCurrentUserHook: <UserType>(AuthContext: AuthContextType<UserType>) => () => {
3
+ isLogged: boolean;
4
+ isReady: boolean;
5
+ user: UserType | undefined;
6
+ setUser: (value?: UserType | undefined) => void;
7
+ refetchCurrentUser: () => void;
8
+ setAccessToken: (value?: import("..").AccessToken) => void;
9
+ isLoading: boolean;
10
+ };
11
+ export default createUseCurrentUserHook;
@@ -0,0 +1,17 @@
1
+ import { useContext } from 'react';
2
+ const createUseCurrentUserHook = (AuthContext) => {
3
+ return () => {
4
+ const { currentUser, setCurrentUser, refetchCurrentUser, setAccessToken, loading, isLogged, isReady, } = useContext(AuthContext);
5
+ const isLoading = loading.includes('CURRENT_USER');
6
+ return {
7
+ isLogged,
8
+ isReady,
9
+ user: currentUser,
10
+ setUser: setCurrentUser,
11
+ refetchCurrentUser,
12
+ setAccessToken,
13
+ isLoading,
14
+ };
15
+ };
16
+ };
17
+ export default createUseCurrentUserHook;
@@ -0,0 +1,9 @@
1
+ import { AuthContextType } from '../Auth.types';
2
+ import { DefaultUpdateCurrentUserRequestData } from '../service';
3
+ declare const createUseCurrentUserUpdateHook: <UserType>(AuthContext: AuthContextType<UserType>) => <UpdateCurrentUserRequestData = DefaultUpdateCurrentUserRequestData>() => {
4
+ updateCurrentUser: (data: UpdateCurrentUserRequestData) => Promise<(UserType & {
5
+ token: import("..").AccessToken;
6
+ }) | undefined>;
7
+ isLoading: boolean;
8
+ };
9
+ export default createUseCurrentUserUpdateHook;
@@ -0,0 +1,28 @@
1
+ import { useContext, useCallback } from 'react';
2
+ import { updateCurrentUser } from '../service/AuthService';
3
+ const createUseCurrentUserUpdateHook = (AuthContext) => {
4
+ return () => {
5
+ const { axiosInstance, config, addLoading, removeLoading, setCurrentUser } = useContext(AuthContext);
6
+ const loading = useContext(AuthContext).loading;
7
+ const isLoading = loading.includes('UPDATE_CURRENT_USER');
8
+ const updateCallback = useCallback(async (data) => {
9
+ try {
10
+ addLoading('UPDATE_CURRENT_USER');
11
+ const response = await updateCurrentUser(axiosInstance, config, data);
12
+ setCurrentUser(response);
13
+ return response;
14
+ }
15
+ catch (e) {
16
+ return undefined;
17
+ }
18
+ finally {
19
+ removeLoading('UPDATE_CURRENT_USER');
20
+ }
21
+ }, [axiosInstance, config, addLoading, removeLoading, setCurrentUser]);
22
+ return {
23
+ updateCurrentUser: updateCallback,
24
+ isLoading,
25
+ };
26
+ };
27
+ };
28
+ export default createUseCurrentUserUpdateHook;
@@ -0,0 +1,7 @@
1
+ import { AuthContextType } from '../Auth.types';
2
+ import { DefaultUpdateCurrentUserPasswordRequestData } from '../service';
3
+ declare const createUseCurrentUserUpdatePasswordHook: <UserType>(AuthContext: AuthContextType<UserType>) => <UpdateCurrentUserPasswordRequestData = DefaultUpdateCurrentUserPasswordRequestData>() => {
4
+ updateCurrentUserPassword: (data: UpdateCurrentUserPasswordRequestData) => Promise<import("..").MakeUserWithAccessToken<UserType> | undefined>;
5
+ isLoading: boolean;
6
+ };
7
+ export default createUseCurrentUserUpdatePasswordHook;
@@ -0,0 +1,31 @@
1
+ import { useContext, useCallback } from 'react';
2
+ import { updateCurrentUserPassword } from '../service/AuthService';
3
+ const createUseCurrentUserUpdatePasswordHook = (AuthContext) => {
4
+ return () => {
5
+ const { axiosInstance, config, addLoading, removeLoading, setAccessToken, setCurrentUser } = useContext(AuthContext);
6
+ const loading = useContext(AuthContext).loading;
7
+ const isLoading = loading.includes('UPDATE_CURRENT_USER_PASSWORD');
8
+ const updatePasswordCallback = useCallback(async (data) => {
9
+ try {
10
+ addLoading('UPDATE_CURRENT_USER_PASSWORD');
11
+ const response = await updateCurrentUserPassword(axiosInstance, config, data);
12
+ if (response.token) {
13
+ setAccessToken(response.token);
14
+ }
15
+ setCurrentUser(response);
16
+ return response;
17
+ }
18
+ catch (e) {
19
+ return undefined;
20
+ }
21
+ finally {
22
+ removeLoading('UPDATE_CURRENT_USER_PASSWORD');
23
+ }
24
+ }, [axiosInstance, config, addLoading, removeLoading, setAccessToken, setCurrentUser]);
25
+ return {
26
+ updateCurrentUserPassword: updatePasswordCallback,
27
+ isLoading,
28
+ };
29
+ };
30
+ };
31
+ export default createUseCurrentUserUpdatePasswordHook;
@@ -0,0 +1,7 @@
1
+ import { AuthContextType } from '../Auth.types';
2
+ import { DefaultForgotPasswordRequestData } from '../service';
3
+ declare const createUseForgotPasswordHook: <UserType>(AuthContext: AuthContextType<UserType>) => <ForgotPasswordRequestData = DefaultForgotPasswordRequestData>() => {
4
+ forgotPassword: (data: ForgotPasswordRequestData) => Promise<any>;
5
+ isLoading: boolean;
6
+ };
7
+ export default createUseForgotPasswordHook;
@@ -0,0 +1,26 @@
1
+ import { useContext, useCallback } from 'react';
2
+ import { forgotPassword } from '../service/AuthService';
3
+ const createUseForgotPasswordHook = (AuthContext) => {
4
+ return () => {
5
+ const { axiosInstance, config, addLoading, removeLoading } = useContext(AuthContext);
6
+ const loading = useContext(AuthContext).loading;
7
+ const isLoading = loading.includes('FORGOT_PASSWORD');
8
+ const forgotPasswordCallback = useCallback(async (data) => {
9
+ try {
10
+ addLoading('FORGOT_PASSWORD');
11
+ return await forgotPassword(axiosInstance, config, data);
12
+ }
13
+ catch (e) {
14
+ return undefined;
15
+ }
16
+ finally {
17
+ removeLoading('FORGOT_PASSWORD');
18
+ }
19
+ }, [axiosInstance, config, addLoading, removeLoading]);
20
+ return {
21
+ forgotPassword: forgotPasswordCallback,
22
+ isLoading,
23
+ };
24
+ };
25
+ };
26
+ export default createUseForgotPasswordHook;
@@ -0,0 +1,7 @@
1
+ import { AuthContextType } from '../Auth.types';
2
+ import { DefaultResetPasswordRequestData } from '../service';
3
+ declare const createUseResetPasswordHook: <UserType>(AuthContext: AuthContextType<UserType>) => <PasswordResetRequestData = DefaultResetPasswordRequestData>() => {
4
+ resetPassword: (data: PasswordResetRequestData) => Promise<import("..").MakeUserWithAccessToken<UserType> | undefined>;
5
+ isLoading: boolean;
6
+ };
7
+ export default createUseResetPasswordHook;
@@ -0,0 +1,29 @@
1
+ import { useContext, useCallback } from 'react';
2
+ import { resetPassword } from '../service/AuthService';
3
+ const createUseResetPasswordHook = (AuthContext) => {
4
+ return () => {
5
+ const { axiosInstance, config, setAccessToken, setCurrentUser, addLoading, removeLoading } = useContext(AuthContext);
6
+ const loading = useContext(AuthContext).loading;
7
+ const isLoading = loading.includes('RESET_PASSWORD');
8
+ const resetPasswordCallback = useCallback(async (data) => {
9
+ try {
10
+ addLoading('RESET_PASSWORD');
11
+ const response = await resetPassword(axiosInstance, config, data);
12
+ setAccessToken(response.token);
13
+ setCurrentUser(response);
14
+ return response;
15
+ }
16
+ catch (e) {
17
+ return undefined;
18
+ }
19
+ finally {
20
+ removeLoading('RESET_PASSWORD');
21
+ }
22
+ }, [axiosInstance, config, setAccessToken, setCurrentUser, addLoading, removeLoading]);
23
+ return {
24
+ resetPassword: resetPasswordCallback,
25
+ isLoading,
26
+ };
27
+ };
28
+ };
29
+ export default createUseResetPasswordHook;
@@ -0,0 +1,7 @@
1
+ import { AuthContextType } from '../Auth.types';
2
+ import { DefaultSignInRequestData } from '../service';
3
+ declare const createUseSignInHook: <UserType>(AuthContext: AuthContextType<UserType>) => <SignInRequestData = DefaultSignInRequestData>() => {
4
+ signIn: (data: SignInRequestData, customApiUrl?: string) => Promise<import("..").MakeUserWithAccessToken<UserType> | undefined>;
5
+ isLoading: boolean;
6
+ };
7
+ export default createUseSignInHook;
@@ -0,0 +1,30 @@
1
+ // src/auth/hooks/UseSignInHookFactory.tsx
2
+ import { useContext, useCallback } from 'react';
3
+ import { signIn } from '../service/AuthService';
4
+ const createUseSignInHook = (AuthContext) => {
5
+ return () => {
6
+ const { axiosInstance, config, setAccessToken, setCurrentUser, addLoading, removeLoading } = useContext(AuthContext);
7
+ const loading = useContext(AuthContext).loading;
8
+ const isLoading = loading.includes('SIGN_IN');
9
+ const signInCallback = useCallback(async (data, customApiUrl) => {
10
+ try {
11
+ addLoading('SIGN_IN');
12
+ const response = await signIn(axiosInstance, config, data);
13
+ setAccessToken(response.token);
14
+ setCurrentUser(response);
15
+ return response;
16
+ }
17
+ catch (e) {
18
+ return undefined;
19
+ }
20
+ finally {
21
+ removeLoading('SIGN_IN');
22
+ }
23
+ }, [axiosInstance, config, setAccessToken, setCurrentUser, addLoading, removeLoading]);
24
+ return {
25
+ signIn: signInCallback,
26
+ isLoading,
27
+ };
28
+ };
29
+ };
30
+ export default createUseSignInHook;
@@ -0,0 +1,6 @@
1
+ import { AuthContextType } from '../Auth.types';
2
+ declare const createUseSignOutHook: <UserType>(AuthContext: AuthContextType<UserType>) => () => {
3
+ signOut: () => Promise<any>;
4
+ isLoading: boolean;
5
+ };
6
+ export default createUseSignOutHook;
@@ -0,0 +1,30 @@
1
+ // src/auth/hooks/UseSignOutHookFactory.tsx
2
+ import { useContext, useCallback } from 'react';
3
+ import { signOut } from '../service/AuthService';
4
+ const createUseSignOutHook = (AuthContext) => {
5
+ return () => {
6
+ const { axiosInstance, config, destroyAccessToken, setCurrentUser, addLoading, removeLoading, } = useContext(AuthContext);
7
+ const loading = useContext(AuthContext).loading;
8
+ const isLoading = loading.includes('SIGN_OUT');
9
+ const signOutCallback = useCallback(async () => {
10
+ try {
11
+ addLoading('SIGN_OUT');
12
+ const response = await signOut(axiosInstance, config);
13
+ destroyAccessToken();
14
+ setCurrentUser(undefined);
15
+ return response;
16
+ }
17
+ catch (e) {
18
+ return undefined;
19
+ }
20
+ finally {
21
+ removeLoading('SIGN_OUT');
22
+ }
23
+ }, [axiosInstance, config, destroyAccessToken, setCurrentUser, addLoading, removeLoading]);
24
+ return {
25
+ signOut: signOutCallback,
26
+ isLoading,
27
+ };
28
+ };
29
+ };
30
+ export default createUseSignOutHook;
@@ -0,0 +1,7 @@
1
+ import { AuthContextType } from '../Auth.types';
2
+ import { DefaultSignUpRequestData } from '../service';
3
+ declare const createUseSignUpHook: <UserType>(AuthContext: AuthContextType<UserType>) => <SignUpRequestData = DefaultSignUpRequestData>() => {
4
+ signUp: (data: SignUpRequestData) => Promise<import("..").MakeUserWithAccessToken<UserType> | undefined>;
5
+ isLoading: boolean;
6
+ };
7
+ export default createUseSignUpHook;
@@ -0,0 +1,30 @@
1
+ // src/auth/hooks/UseSignUpHookFactory.tsx
2
+ import { useContext, useCallback } from 'react';
3
+ import { signUp } from '../service/AuthService';
4
+ const createUseSignUpHook = (AuthContext) => {
5
+ return () => {
6
+ const { axiosInstance, config, setAccessToken, setCurrentUser, addLoading, removeLoading } = useContext(AuthContext);
7
+ const loading = useContext(AuthContext).loading;
8
+ const isLoading = loading.includes('SIGN_UP');
9
+ const signUpCallback = useCallback(async (data) => {
10
+ try {
11
+ addLoading('SIGN_UP');
12
+ const response = await signUp(axiosInstance, config, data);
13
+ setAccessToken(response.token);
14
+ setCurrentUser(response);
15
+ return response;
16
+ }
17
+ catch (e) {
18
+ return undefined;
19
+ }
20
+ finally {
21
+ removeLoading('SIGN_UP');
22
+ }
23
+ }, [axiosInstance, config, setAccessToken, setCurrentUser, addLoading, removeLoading]);
24
+ return {
25
+ signUp: signUpCallback,
26
+ isLoading,
27
+ };
28
+ };
29
+ };
30
+ export default createUseSignUpHook;
@@ -0,0 +1,53 @@
1
+ declare const createAuthentication: <UserType extends unknown>() => {
2
+ AuthContextProvider: {
3
+ ({ children, config, axiosInstance, initialAccessToken, initialCurrentUser, }: import("./Auth.types").AuthProviderProps<UserType>): import("react/jsx-runtime").JSX.Element;
4
+ displayName: string;
5
+ };
6
+ useCurrentUser: () => {
7
+ isLogged: boolean;
8
+ isReady: boolean;
9
+ user: UserType | undefined;
10
+ setUser: (value?: UserType | undefined) => void;
11
+ refetchCurrentUser: () => void;
12
+ setAccessToken: (value?: import("./types").AccessToken) => void;
13
+ isLoading: boolean;
14
+ };
15
+ useCurrentUserUpdate: <UpdateCurrentUserRequestData = import("./service/AuthService.types").DefaultUpdateCurrentUserRequestData>() => {
16
+ updateCurrentUser: (data: UpdateCurrentUserRequestData) => Promise<(UserType & {
17
+ token: import("./types").AccessToken;
18
+ }) | undefined>;
19
+ isLoading: boolean;
20
+ };
21
+ useCurrentUserUpdatePassword: <UpdateCurrentUserPasswordRequestData = import("./service/AuthService.types").DefaultUpdateCurrentUserPasswordRequestData>() => {
22
+ updateCurrentUserPassword: (data: UpdateCurrentUserPasswordRequestData) => Promise<import("./types").MakeUserWithAccessToken<UserType> | undefined>;
23
+ isLoading: boolean;
24
+ };
25
+ useSignIn: <SignInRequestData = import("./service/AuthService.types").DefaultSignInRequestData>() => {
26
+ signIn: (data: SignInRequestData, customApiUrl?: string) => Promise<import("./types").MakeUserWithAccessToken<UserType> | undefined>;
27
+ isLoading: boolean;
28
+ };
29
+ useSignOut: () => {
30
+ signOut: () => Promise<any>;
31
+ isLoading: boolean;
32
+ };
33
+ useSignUp: <SignUpRequestData = import("./service/AuthService.types").DefaultSignUpRequestData>() => {
34
+ signUp: (data: SignUpRequestData) => Promise<import("./types").MakeUserWithAccessToken<UserType> | undefined>;
35
+ isLoading: boolean;
36
+ };
37
+ useForgotPassword: <ForgotPasswordRequestData = import("./service/AuthService.types").DefaultForgotPasswordRequestData>() => {
38
+ forgotPassword: (data: ForgotPasswordRequestData) => Promise<any>;
39
+ isLoading: boolean;
40
+ };
41
+ useResetPassword: <PasswordResetRequestData = import("./service/AuthService.types").DefaultResetPasswordRequestData>() => {
42
+ resetPassword: (data: PasswordResetRequestData) => Promise<import("./types").MakeUserWithAccessToken<UserType> | undefined>;
43
+ isLoading: boolean;
44
+ };
45
+ Authenticated: {
46
+ ({ children, middleware }: import("./components/AuthenticatedFactory.types").AuthenticatedProps): import("react/jsx-runtime").JSX.Element | null;
47
+ displayName: string;
48
+ };
49
+ };
50
+ export default createAuthentication;
51
+ export * from './service/AuthService.types';
52
+ export * from './config/config.types';
53
+ export * from './types';
@@ -0,0 +1,30 @@
1
+ import createAuthContext from './context/AuthContextFactory';
2
+ import createAuthContextProvider from './provider/AuthContextProviderFactory';
3
+ import createUseCurrentUserHook from './hooks/useCurrentUserHookFactory';
4
+ import createUseCurrentUserUpdateHook from './hooks/useCurrentUserUpdateHookFactory';
5
+ import createUseCurrentUserUpdatePasswordHook from './hooks/useCurrentUserUpdatePasswordHookFactory';
6
+ import createUseSignInHook from './hooks/useSignInHookFactory';
7
+ import createUseSignOutHook from './hooks/useSignOutHookFactory';
8
+ import createUseSignUpHook from './hooks/useSignUpHookFactory';
9
+ import createUseForgotPasswordHook from './hooks/useForgotPasswordHookFactory';
10
+ import createUseResetPasswordHook from './hooks/useResetPasswordHookFactory';
11
+ import createAuthenticatedComponent from './components/AuthenticatedFactory';
12
+ const createAuthentication = () => {
13
+ const AuthContext = createAuthContext();
14
+ return {
15
+ AuthContextProvider: createAuthContextProvider(AuthContext),
16
+ useCurrentUser: createUseCurrentUserHook(AuthContext),
17
+ useCurrentUserUpdate: createUseCurrentUserUpdateHook(AuthContext),
18
+ useCurrentUserUpdatePassword: createUseCurrentUserUpdatePasswordHook(AuthContext),
19
+ useSignIn: createUseSignInHook(AuthContext),
20
+ useSignOut: createUseSignOutHook(AuthContext),
21
+ useSignUp: createUseSignUpHook(AuthContext),
22
+ useForgotPassword: createUseForgotPasswordHook(AuthContext),
23
+ useResetPassword: createUseResetPasswordHook(AuthContext),
24
+ Authenticated: createAuthenticatedComponent(AuthContext),
25
+ };
26
+ };
27
+ export default createAuthentication;
28
+ export * from './service/AuthService.types';
29
+ export * from './config/config.types';
30
+ export * from './types';
@@ -0,0 +1,6 @@
1
+ import { AuthContextType, AuthProviderProps } from '../Auth.types';
2
+ declare const createAuthContextProvider: <UserType extends unknown>(AuthContext: AuthContextType<UserType>) => {
3
+ ({ children, config, axiosInstance, initialAccessToken, initialCurrentUser, }: AuthProviderProps<UserType>): import("react/jsx-runtime").JSX.Element;
4
+ displayName: string;
5
+ };
6
+ export default createAuthContextProvider;
@@ -0,0 +1,46 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useEffect, useMemo, useState } from 'react';
4
+ const createAuthContextProvider = (AuthContext) => {
5
+ const Provider = ({ children, config, axiosInstance, initialAccessToken, initialCurrentUser, }) => {
6
+ const [accessToken, setAccessToken] = useState(initialAccessToken);
7
+ const [currentUser, setCurrentUser] = useState(initialCurrentUser);
8
+ const [loading, setLoading] = useState([]);
9
+ const [isReady, setIsReady] = useState(false);
10
+ const addLoading = (value) => {
11
+ setLoading((prev) => [...prev, value]);
12
+ };
13
+ const removeLoading = (value) => {
14
+ setLoading((prev) => prev.filter((item) => item !== value));
15
+ };
16
+ const destroyAccessToken = () => {
17
+ setAccessToken(undefined);
18
+ };
19
+ const refetchCurrentUser = () => {
20
+ // Implementace by zde volala getCurrentUser
21
+ };
22
+ const isLogged = useMemo(() => !!accessToken && !!currentUser, [accessToken, currentUser]);
23
+ const authContextValue = useMemo(() => ({
24
+ config: config,
25
+ axiosInstance,
26
+ accessToken,
27
+ currentUser,
28
+ loading,
29
+ isLogged,
30
+ isReady,
31
+ setAccessToken,
32
+ setCurrentUser,
33
+ refetchCurrentUser,
34
+ addLoading,
35
+ removeLoading,
36
+ destroyAccessToken,
37
+ }), [accessToken, currentUser, loading, isLogged, isReady, axiosInstance]);
38
+ useEffect(() => {
39
+ setIsReady(true);
40
+ }, []);
41
+ return _jsx(AuthContext.Provider, { value: authContextValue, children: children });
42
+ };
43
+ Provider.displayName = 'AuthContextProvider';
44
+ return Provider;
45
+ };
46
+ export default createAuthContextProvider;
@@ -0,0 +1,15 @@
1
+ import { AuthenticationSettings } from '../config/config.types';
2
+ import { AxiosInstance } from 'axios';
3
+ import { DefaultForgotPasswordRequestData, DefaultResetPasswordRequestData, DefaultSignInRequestData, DefaultSignUpRequestData, DefaultUpdateCurrentUserPasswordRequestData, DefaultUpdateCurrentUserRequestData } from './AuthService.types';
4
+ import { MakeUserWithAccessToken } from '../types';
5
+ export declare const signIn: <UserType, SignInRequest = DefaultSignInRequestData>(axios: AxiosInstance, config: AuthenticationSettings, requestData: SignInRequest) => Promise<MakeUserWithAccessToken<UserType>>;
6
+ export declare const signOut: (axios: AxiosInstance, config: AuthenticationSettings) => Promise<any>;
7
+ export declare const signUp: <UserType, SignUpRequest = DefaultSignUpRequestData>(axios: AxiosInstance, config: AuthenticationSettings, requestData: SignUpRequest) => Promise<MakeUserWithAccessToken<UserType>>;
8
+ export declare const forgotPassword: <ForgotPasswordRequest = DefaultForgotPasswordRequestData>(axios: AxiosInstance, config: AuthenticationSettings, requestData: ForgotPasswordRequest) => Promise<any>;
9
+ export declare const resetPassword: <UserType, ResetPasswordRequest = DefaultResetPasswordRequestData>(axios: AxiosInstance, config: AuthenticationSettings, requestData: ResetPasswordRequest) => Promise<MakeUserWithAccessToken<UserType>>;
10
+ export declare const getCurrentUser: <UserType>(axios: AxiosInstance, config: AuthenticationSettings) => Promise<UserType>;
11
+ export declare const updateCurrentUser: <UserType, UpdateCurrentUserRequest = DefaultUpdateCurrentUserRequestData>(axios: AxiosInstance, config: AuthenticationSettings, requestData: UpdateCurrentUserRequest) => Promise<UserType & {
12
+ token: import("../types").AccessToken;
13
+ }>;
14
+ export declare const updateCurrentUserPassword: <UpdateCurrentUserPasswordRequest = DefaultUpdateCurrentUserPasswordRequestData, User = {}>(axios: AxiosInstance, config: AuthenticationSettings, requestData: UpdateCurrentUserPasswordRequest) => Promise<MakeUserWithAccessToken<User>>;
15
+ export declare const updateCurrentUserAvatar: <UserType>(axios: AxiosInstance, config: AuthenticationSettings, requestFile?: File) => Promise<UserType>;