@q2devel/q2-core 1.0.4 → 1.0.6
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/dist/api/cart/Cart.service.js +2 -2
- package/dist/api/pages/branch/branch.service.d.ts +9 -0
- package/dist/api/pages/branch/branch.service.d.ts.map +1 -0
- package/dist/api/pages/branch/branch.service.js +39 -0
- package/dist/api/pages/branch/branchService.types.d.ts +16 -0
- package/dist/api/pages/branch/branchService.types.d.ts.map +1 -0
- package/dist/api/pages/faq/faq.service.d.ts +9 -0
- package/dist/api/pages/faq/faq.service.d.ts.map +1 -0
- package/dist/api/pages/faq/faq.service.js +33 -0
- package/dist/api/pages/faq/faqService.types.d.ts +11 -0
- package/dist/api/pages/faq/faqService.types.d.ts.map +1 -0
- package/dist/api/pages/page/page.service.d.ts +10 -0
- package/dist/api/pages/page/page.service.d.ts.map +1 -0
- package/dist/api/pages/page/page.service.js +33 -0
- package/dist/api/pages/page/pageService.types.d.ts +8 -0
- package/dist/api/pages/page/pageService.types.d.ts.map +1 -0
- package/dist/api/pages/page/pageService.types.js +1 -0
- package/dist/api/products/getProducts.d.ts.map +1 -1
- package/dist/api/products/getProducts.js +2 -2
- package/dist/api/user/getUser/user.service.d.ts +8 -0
- package/dist/api/user/getUser/user.service.d.ts.map +1 -0
- package/dist/api/user/getUser/user.service.js +25 -0
- package/dist/api/user/getUser/userService.types.d.ts +42 -0
- package/dist/api/user/getUser/userService.types.d.ts.map +1 -0
- package/dist/api/user/getUser/userService.types.js +1 -0
- package/dist/api/user/register/Register.service.d.ts +8 -0
- package/dist/api/user/register/Register.service.d.ts.map +1 -0
- package/dist/api/user/register/Register.service.js +24 -0
- package/dist/api/user/register/RegisterService.types.d.ts +13 -0
- package/dist/api/user/register/RegisterService.types.d.ts.map +1 -0
- package/dist/api/user/register/RegisterService.types.js +1 -0
- package/dist/api/user/resetPassword/resetPassword.service.d.ts +8 -0
- package/dist/api/user/resetPassword/resetPassword.service.d.ts.map +1 -0
- package/dist/api/user/resetPassword/resetPassword.service.js +4 -0
- package/dist/{types/content/ResetPassword.d.ts → api/user/resetPassword/resetPasswordSevice.types.d.ts} +2 -2
- package/dist/api/user/resetPassword/resetPasswordSevice.types.d.ts.map +1 -0
- package/dist/api/user/resetPassword/resetPasswordSevice.types.js +1 -0
- package/dist/api/wishlist/Wishlist.service.js +1 -1
- package/dist/auth/auth/auth.config.d.ts +14 -0
- package/dist/auth/auth/auth.config.d.ts.map +1 -0
- package/dist/auth/auth/auth.config.js +1 -0
- package/dist/auth/auth/auth.d.ts +36 -0
- package/dist/auth/auth/auth.d.ts.map +1 -0
- package/dist/auth/auth/auth.js +111 -0
- package/dist/auth/auth/auth.types.d.ts +38 -0
- package/dist/auth/auth/auth.types.d.ts.map +1 -0
- package/dist/auth/auth/auth.types.js +1 -0
- package/dist/auth/context/AuthContext.d.ts +4 -0
- package/dist/auth/context/AuthContext.d.ts.map +1 -0
- package/dist/auth/context/AuthContext.js +158 -0
- package/dist/auth/hooks/useCurrentUser.d.ts +11 -0
- package/dist/auth/hooks/useCurrentUser.d.ts.map +1 -0
- package/dist/auth/hooks/useCurrentUser.js +15 -0
- package/dist/auth/hooks/useSignIn.d.ts +7 -0
- package/dist/auth/hooks/useSignIn.d.ts.map +1 -0
- package/dist/auth/hooks/useSignIn.js +33 -0
- package/dist/auth/hooks/useSignOut.d.ts +5 -0
- package/dist/auth/hooks/useSignOut.d.ts.map +1 -0
- package/dist/auth/hooks/useSignOut.js +27 -0
- package/dist/auth/services/user.service.d.ts +11 -0
- package/dist/auth/services/user.service.d.ts.map +1 -0
- package/dist/auth/services/user.service.js +24 -0
- package/dist/auth/services/userService.types.d.ts +42 -0
- package/dist/auth/services/userService.types.d.ts.map +1 -0
- package/dist/auth/services/userService.types.js +1 -0
- package/dist/hooks/user/useGetUser.d.ts +3 -0
- package/dist/hooks/user/useGetUser.d.ts.map +1 -0
- package/dist/hooks/user/useGetUser.js +11 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -1
- package/dist/types/products/Product.d.ts +2 -0
- package/dist/types/products/Product.d.ts.map +1 -1
- package/dist/utils/mapProducts.d.ts +3 -2
- package/dist/utils/mapProducts.d.ts.map +1 -1
- package/dist/utils/mapProducts.js +22 -10
- package/package.json +5 -1
- package/dist/api/user/getUserCart.d.ts +0 -1
- package/dist/api/user/getUserCart.d.ts.map +0 -1
- package/dist/api/user/getUserCart.js +0 -1
- package/dist/types/ResetPassword.d.ts +0 -8
- package/dist/types/ResetPassword.d.ts.map +0 -1
- package/dist/types/content/ResetPassword.d.ts.map +0 -1
- /package/dist/{types/ResetPassword.js → api/pages/branch/branchService.types.js} +0 -0
- /package/dist/{types/content/ResetPassword.js → api/pages/faq/faqService.types.js} +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { UserAddress } from '../services/userService.types';
|
|
3
|
+
import { AuthConfig } from './auth.config';
|
|
4
|
+
export type AccessToken = string;
|
|
5
|
+
export type User = {
|
|
6
|
+
id: string;
|
|
7
|
+
name?: string | null;
|
|
8
|
+
email?: string | null;
|
|
9
|
+
username?: string | null;
|
|
10
|
+
address?: UserAddress;
|
|
11
|
+
};
|
|
12
|
+
export type MakeUserWithAccessToken<U> = U & {
|
|
13
|
+
token: AccessToken;
|
|
14
|
+
refreshToken: string;
|
|
15
|
+
expiresAt: number;
|
|
16
|
+
};
|
|
17
|
+
export interface AuthProviderProps {
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
config: AuthConfig;
|
|
20
|
+
initialAccessToken?: AccessToken;
|
|
21
|
+
initialCurrentUser?: User;
|
|
22
|
+
}
|
|
23
|
+
export interface AuthContextValue {
|
|
24
|
+
isLogged: boolean;
|
|
25
|
+
isReady: boolean;
|
|
26
|
+
user: User | undefined;
|
|
27
|
+
accessToken: AccessToken | undefined;
|
|
28
|
+
refreshToken: string | undefined;
|
|
29
|
+
expiresAt: number | undefined;
|
|
30
|
+
config: AuthConfig;
|
|
31
|
+
setUser: (value?: User) => void;
|
|
32
|
+
setAccessToken: (value?: AccessToken) => void;
|
|
33
|
+
setRefreshToken: (value?: string) => void;
|
|
34
|
+
setExpiresAt: (value?: number) => void;
|
|
35
|
+
refetchCurrentUser: () => Promise<User | undefined>;
|
|
36
|
+
isLoading: boolean;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=auth.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.types.d.ts","sourceRoot":"","sources":["../../../auth/auth/auth.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE1C,MAAM,MAAM,WAAW,GAAG,MAAM,CAAA;AAEhC,MAAM,MAAM,IAAI,GAAG;IACf,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,OAAO,CAAC,EAAE,WAAW,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,uBAAuB,CAAC,CAAC,IAAI,CAAC,GAAG;IACzC,KAAK,EAAE,WAAW,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,MAAM,WAAW,iBAAiB;IAC9B,QAAQ,EAAE,SAAS,CAAA;IACnB,MAAM,EAAE,UAAU,CAAA;IAClB,kBAAkB,CAAC,EAAE,WAAW,CAAA;IAChC,kBAAkB,CAAC,EAAE,IAAI,CAAA;CAC5B;AAED,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,EAAE,OAAO,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,IAAI,GAAG,SAAS,CAAA;IACtB,WAAW,EAAE,WAAW,GAAG,SAAS,CAAA;IACpC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,MAAM,EAAE,UAAU,CAAA;IAClB,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,KAAK,IAAI,CAAA;IAC/B,cAAc,EAAE,CAAC,KAAK,CAAC,EAAE,WAAW,KAAK,IAAI,CAAA;IAC7C,eAAe,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IACzC,YAAY,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IACtC,kBAAkB,EAAE,MAAM,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAAA;IACnD,SAAS,EAAE,OAAO,CAAA;CACrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AuthContextValue, AuthProviderProps } from '../auth/auth.types';
|
|
2
|
+
export declare const AuthContextProvider: ({ children, config, initialAccessToken, initialCurrentUser, }: AuthProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare const useAuth: () => AuthContextValue;
|
|
4
|
+
//# sourceMappingURL=AuthContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthContext.d.ts","sourceRoot":"","sources":["../../../auth/context/AuthContext.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAe,gBAAgB,EAAE,iBAAiB,EAAQ,MAAM,oBAAoB,CAAA;AAK3F,eAAO,MAAM,mBAAmB,GAAI,+DAKjC,iBAAiB,4CA+JnB,CAAA;AAED,eAAO,MAAM,OAAO,QAAO,gBAM1B,CAAA"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import Cookies from 'js-cookie';
|
|
4
|
+
import { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { fetchUserInfo, refreshTokenService } from '../auth/auth';
|
|
6
|
+
const AuthContext = createContext(undefined);
|
|
7
|
+
export const AuthContextProvider = ({ children, config, initialAccessToken, initialCurrentUser, }) => {
|
|
8
|
+
const [user, setUser] = useState(initialCurrentUser);
|
|
9
|
+
const [accessToken, setAccessToken] = useState(initialAccessToken);
|
|
10
|
+
const [refreshToken, setRefreshToken] = useState();
|
|
11
|
+
const [expiresAt, setExpiresAt] = useState();
|
|
12
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
13
|
+
const [isReady, setIsReady] = useState(false);
|
|
14
|
+
const refreshingRef = useRef(false);
|
|
15
|
+
const COOKIE_OPTIONS = {
|
|
16
|
+
secure: config.cookieOptions?.secure ?? false,
|
|
17
|
+
sameSite: config.cookieOptions?.sameSite ?? 'strict',
|
|
18
|
+
expires: config.cookieOptions?.expires ?? 7,
|
|
19
|
+
};
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const savedToken = Cookies.get('accessToken');
|
|
22
|
+
const savedRefreshToken = Cookies.get('refreshToken');
|
|
23
|
+
const savedExpiresAt = Cookies.get('expiresAt');
|
|
24
|
+
const savedUser = Cookies.get('user');
|
|
25
|
+
if (savedToken) {
|
|
26
|
+
setAccessToken(savedToken);
|
|
27
|
+
}
|
|
28
|
+
if (savedRefreshToken) {
|
|
29
|
+
setRefreshToken(savedRefreshToken);
|
|
30
|
+
}
|
|
31
|
+
if (savedExpiresAt) {
|
|
32
|
+
setExpiresAt(parseInt(savedExpiresAt));
|
|
33
|
+
}
|
|
34
|
+
if (savedUser) {
|
|
35
|
+
try {
|
|
36
|
+
setUser(JSON.parse(savedUser));
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
console.error('Failed to parse user from cookie');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
setIsReady(true);
|
|
43
|
+
}, []);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (accessToken && user) {
|
|
46
|
+
Cookies.set('accessToken', accessToken, COOKIE_OPTIONS);
|
|
47
|
+
if (refreshToken) {
|
|
48
|
+
Cookies.set('refreshToken', refreshToken, COOKIE_OPTIONS);
|
|
49
|
+
}
|
|
50
|
+
if (expiresAt) {
|
|
51
|
+
Cookies.set('expiresAt', expiresAt.toString(), COOKIE_OPTIONS);
|
|
52
|
+
}
|
|
53
|
+
Cookies.set('user', JSON.stringify(user), COOKIE_OPTIONS);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// Pokud nemáme token nebo uživatele, vymažeme cookies
|
|
57
|
+
Cookies.remove('accessToken');
|
|
58
|
+
Cookies.remove('refreshToken');
|
|
59
|
+
Cookies.remove('expiresAt');
|
|
60
|
+
Cookies.remove('user');
|
|
61
|
+
}
|
|
62
|
+
}, [accessToken, refreshToken, expiresAt, user, COOKIE_OPTIONS]);
|
|
63
|
+
const refreshTokenIfNeeded = useCallback(async () => {
|
|
64
|
+
if (refreshingRef.current || !refreshToken)
|
|
65
|
+
return;
|
|
66
|
+
if (expiresAt && Date.now() < expiresAt - 10000)
|
|
67
|
+
return;
|
|
68
|
+
try {
|
|
69
|
+
refreshingRef.current = true;
|
|
70
|
+
setIsLoading(true);
|
|
71
|
+
const refreshed = await refreshTokenService(refreshToken, config);
|
|
72
|
+
setAccessToken(refreshed.token);
|
|
73
|
+
setRefreshToken(refreshed.refreshToken);
|
|
74
|
+
setExpiresAt(refreshed.expiresAt);
|
|
75
|
+
setUser({
|
|
76
|
+
id: refreshed.id,
|
|
77
|
+
name: refreshed.name,
|
|
78
|
+
email: refreshed.email,
|
|
79
|
+
username: refreshed.username,
|
|
80
|
+
address: refreshed.address,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.error('Failed to refresh token:', error);
|
|
85
|
+
// Pokud refresh token selhal, můžeme vymazat autentifikační data
|
|
86
|
+
if (error instanceof Error && error.message === 'Failed to refresh token') {
|
|
87
|
+
// Odstranění cookies
|
|
88
|
+
Cookies.remove('accessToken');
|
|
89
|
+
Cookies.remove('refreshToken');
|
|
90
|
+
Cookies.remove('expiresAt');
|
|
91
|
+
Cookies.remove('user');
|
|
92
|
+
setAccessToken(undefined);
|
|
93
|
+
setRefreshToken(undefined);
|
|
94
|
+
setExpiresAt(undefined);
|
|
95
|
+
setUser(undefined);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
setIsLoading(false);
|
|
100
|
+
refreshingRef.current = false;
|
|
101
|
+
}
|
|
102
|
+
}, [refreshToken, expiresAt, config]);
|
|
103
|
+
// Pravidelný refresh tokenu
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (!refreshToken || !expiresAt)
|
|
106
|
+
return;
|
|
107
|
+
// Pokud token vyprší za méně než 30 sekund, spustíme refresh hned
|
|
108
|
+
if (Date.now() > expiresAt - 30000) {
|
|
109
|
+
refreshTokenIfNeeded();
|
|
110
|
+
}
|
|
111
|
+
// Nastavíme interval pro pravidelnou kontrolu
|
|
112
|
+
const interval = setInterval(() => {
|
|
113
|
+
refreshTokenIfNeeded();
|
|
114
|
+
}, 20000); // Kontrolujeme každých 20 sekund
|
|
115
|
+
return () => clearInterval(interval);
|
|
116
|
+
}, [refreshToken, expiresAt, refreshTokenIfNeeded]);
|
|
117
|
+
// Funkce pro získání aktuálních dat o uživateli z API
|
|
118
|
+
const refetchCurrentUser = useCallback(async () => {
|
|
119
|
+
if (!accessToken)
|
|
120
|
+
return undefined;
|
|
121
|
+
try {
|
|
122
|
+
setIsLoading(true);
|
|
123
|
+
const userData = await fetchUserInfo(accessToken, config);
|
|
124
|
+
setUser(userData);
|
|
125
|
+
return userData;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.error('Failed to fetch user data:', error);
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
setIsLoading(false);
|
|
133
|
+
}
|
|
134
|
+
}, [accessToken, config]);
|
|
135
|
+
const value = {
|
|
136
|
+
isLogged: !!accessToken && !!user,
|
|
137
|
+
isReady,
|
|
138
|
+
user,
|
|
139
|
+
accessToken,
|
|
140
|
+
refreshToken,
|
|
141
|
+
expiresAt,
|
|
142
|
+
config,
|
|
143
|
+
setUser,
|
|
144
|
+
setAccessToken,
|
|
145
|
+
setRefreshToken,
|
|
146
|
+
setExpiresAt,
|
|
147
|
+
refetchCurrentUser,
|
|
148
|
+
isLoading,
|
|
149
|
+
};
|
|
150
|
+
return _jsx(AuthContext.Provider, { value: value, children: children });
|
|
151
|
+
};
|
|
152
|
+
export const useAuth = () => {
|
|
153
|
+
const context = useContext(AuthContext);
|
|
154
|
+
if (context === undefined) {
|
|
155
|
+
throw new Error('useAuth must be used within an AuthContextProvider');
|
|
156
|
+
}
|
|
157
|
+
return context;
|
|
158
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const useCurrentUser: () => {
|
|
2
|
+
user: import("../..").User | undefined;
|
|
3
|
+
isLogged: boolean;
|
|
4
|
+
isReady: boolean;
|
|
5
|
+
refetchCurrentUser: () => Promise<import("../..").User | undefined>;
|
|
6
|
+
setUser: (value?: import("../..").User) => void;
|
|
7
|
+
setAccessToken: (value?: import("../..").AccessToken) => void;
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
accessToken: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=useCurrentUser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCurrentUser.d.ts","sourceRoot":"","sources":["../../../auth/hooks/useCurrentUser.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc;;;;;;;;;CAa1B,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useAuth } from "../context/AuthContext";
|
|
3
|
+
export const useCurrentUser = () => {
|
|
4
|
+
const { user, isLogged, isReady, accessToken, refetchCurrentUser, setUser, setAccessToken, isLoading } = useAuth();
|
|
5
|
+
return {
|
|
6
|
+
user,
|
|
7
|
+
isLogged,
|
|
8
|
+
isReady,
|
|
9
|
+
refetchCurrentUser,
|
|
10
|
+
setUser,
|
|
11
|
+
setAccessToken,
|
|
12
|
+
isLoading,
|
|
13
|
+
accessToken,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DefaultSignInRequestData } from '../auth/auth';
|
|
2
|
+
import { MakeUserWithAccessToken, User } from '../auth/auth.types';
|
|
3
|
+
export declare const useSignIn: <SignInRequestData = DefaultSignInRequestData>() => {
|
|
4
|
+
signIn: (data: SignInRequestData) => Promise<MakeUserWithAccessToken<User> | undefined>;
|
|
5
|
+
isLoading: boolean;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=useSignIn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSignIn.d.ts","sourceRoot":"","sources":["../../../auth/hooks/useSignIn.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAiB,MAAM,cAAc,CAAA;AACtE,OAAO,EAAE,uBAAuB,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AAIlE,eAAO,MAAM,SAAS,GAAI,iBAAiB,GAAG,wBAAwB;mBAKjD,iBAAiB;;CAiCrC,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { signInService } from '../auth/auth';
|
|
3
|
+
import { useAuth } from '../context/AuthContext';
|
|
4
|
+
import { useCallback, useState } from 'react';
|
|
5
|
+
export const useSignIn = () => {
|
|
6
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
7
|
+
const { setAccessToken, setRefreshToken, setExpiresAt, setUser, config } = useAuth();
|
|
8
|
+
const signIn = useCallback(async (data) => {
|
|
9
|
+
try {
|
|
10
|
+
setIsLoading(true);
|
|
11
|
+
const result = await signInService(data, config);
|
|
12
|
+
setAccessToken(result.token);
|
|
13
|
+
setRefreshToken(result.refreshToken);
|
|
14
|
+
setExpiresAt(result.expiresAt);
|
|
15
|
+
const userData = {
|
|
16
|
+
id: result.id,
|
|
17
|
+
name: result.name,
|
|
18
|
+
email: result.email,
|
|
19
|
+
username: result.username,
|
|
20
|
+
};
|
|
21
|
+
setUser(userData);
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.error('Sign in failed:', error);
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
setIsLoading(false);
|
|
30
|
+
}
|
|
31
|
+
}, [setAccessToken, setRefreshToken, setExpiresAt, setUser, config]);
|
|
32
|
+
return { signIn, isLoading };
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSignOut.d.ts","sourceRoot":"","sources":["../../../auth/hooks/useSignOut.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,UAAU;;;CAwBtB,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useAuth } from '../context/AuthContext';
|
|
3
|
+
import { signOutService } from '../auth/auth';
|
|
4
|
+
import { useCallback, useState } from 'react';
|
|
5
|
+
export const useSignOut = () => {
|
|
6
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
7
|
+
const { setAccessToken, setRefreshToken, setExpiresAt, setUser } = useAuth();
|
|
8
|
+
const signOut = useCallback(async () => {
|
|
9
|
+
try {
|
|
10
|
+
setIsLoading(true);
|
|
11
|
+
await signOutService();
|
|
12
|
+
setAccessToken(undefined);
|
|
13
|
+
setRefreshToken(undefined);
|
|
14
|
+
setExpiresAt(undefined);
|
|
15
|
+
setUser(undefined);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
console.error('Sign out failed:', error);
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
setIsLoading(false);
|
|
24
|
+
}
|
|
25
|
+
}, [setAccessToken, setRefreshToken, setExpiresAt, setUser]);
|
|
26
|
+
return { signOut, isLoading };
|
|
27
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { User } from './userService.types';
|
|
3
|
+
type GetUserParams = {
|
|
4
|
+
axiosInstance: AxiosInstance;
|
|
5
|
+
config?: AxiosRequestConfig;
|
|
6
|
+
userId?: string;
|
|
7
|
+
token?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const getUser: ({ axiosInstance, config, userId, token, }: GetUserParams) => Promise<User>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=user.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.service.d.ts","sourceRoot":"","sources":["../../../auth/services/user.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAEzD,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAE1C,KAAK,aAAa,GAAG;IACjB,aAAa,EAAE,aAAa,CAAA;IAC5B,MAAM,CAAC,EAAE,kBAAkB,CAAA;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,OAAO,GAAU,2CAK3B,aAAa,KAAG,OAAO,CAAC,IAAI,CAiC9B,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
|
|
2
|
+
export const getUser = async ({ axiosInstance, config = {}, userId, token, }) => {
|
|
3
|
+
const params = new DrupalJsonApiParams();
|
|
4
|
+
userId && params.addFilter('drupal_internal__uid', userId, 'IN');
|
|
5
|
+
const queryString = params.getQueryString();
|
|
6
|
+
const headers = token ? { ...config.headers, Authorization: `Bearer ${token}` } : config.headers;
|
|
7
|
+
const { data } = await axiosInstance.get(`/jsonapi/user/user?${queryString}`, {
|
|
8
|
+
...config,
|
|
9
|
+
headers,
|
|
10
|
+
});
|
|
11
|
+
const firstItem = data.data?.[0];
|
|
12
|
+
const customerId = firstItem?.relationships?.customer_profiles?.data?.[0]?.id;
|
|
13
|
+
let mappedUser = {
|
|
14
|
+
name: firstItem?.attributes?.name ?? '',
|
|
15
|
+
email: firstItem?.attributes?.mail ?? '',
|
|
16
|
+
};
|
|
17
|
+
if (customerId) {
|
|
18
|
+
const { data: customerData } = await axiosInstance.get(`/jsonapi/profile/customer/${customerId}`, {
|
|
19
|
+
...config,
|
|
20
|
+
});
|
|
21
|
+
mappedUser.address = customerData.data.attributes.address;
|
|
22
|
+
}
|
|
23
|
+
return mappedUser;
|
|
24
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type JsonApiResponse<T> = {
|
|
2
|
+
[x: string]: any;
|
|
3
|
+
jsonapi: {
|
|
4
|
+
version: string;
|
|
5
|
+
meta: {
|
|
6
|
+
links: {
|
|
7
|
+
self: {
|
|
8
|
+
href: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
data: T[];
|
|
14
|
+
included: any;
|
|
15
|
+
links: {
|
|
16
|
+
self: {
|
|
17
|
+
href: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export type UserAddress = {
|
|
22
|
+
additional_name: string | null;
|
|
23
|
+
address_line1: string;
|
|
24
|
+
address_line2: string;
|
|
25
|
+
administrative_area: string | null;
|
|
26
|
+
country_code: string;
|
|
27
|
+
dependent_locality: string | null;
|
|
28
|
+
family_name: string;
|
|
29
|
+
given_name: string;
|
|
30
|
+
langcode: string;
|
|
31
|
+
locality: string;
|
|
32
|
+
organization: string;
|
|
33
|
+
postal_code: string;
|
|
34
|
+
sorting_code: string | null;
|
|
35
|
+
};
|
|
36
|
+
export type User = {
|
|
37
|
+
name: string;
|
|
38
|
+
email: string;
|
|
39
|
+
field_name?: string;
|
|
40
|
+
address?: UserAddress;
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=userService.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userService.types.d.ts","sourceRoot":"","sources":["../../../auth/services/userService.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI;IAC7B,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;IAChB,OAAO,EAAE;QACL,OAAO,EAAE,MAAM,CAAA;QACf,IAAI,EAAE;YACF,KAAK,EAAE;gBACH,IAAI,EAAE;oBACF,IAAI,EAAE,MAAM,CAAA;iBACf,CAAA;aACJ,CAAA;SACJ,CAAA;KACJ,CAAA;IACD,IAAI,EAAE,CAAC,EAAE,CAAA;IACT,QAAQ,EAAE,GAAG,CAAA;IACb,KAAK,EAAE;QACH,IAAI,EAAE;YACF,IAAI,EAAE,MAAM,CAAA;SACf,CAAA;KACJ,CAAA;CACJ,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACtB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAA;IAClC,YAAY,EAAE,MAAM,CAAA;IACpB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,IAAI,GAAG;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,EAAE,WAAW,CAAA;CACxB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGetUser.d.ts","sourceRoot":"","sources":["../../../hooks/user/useGetUser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,eAAO,MAAM,UAAU,GAAI,KAAK,WAAW,0HAQ1C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { getUser } from '../../api/user/getUser/user.service';
|
|
3
|
+
export const useGetUser = (ctx) => {
|
|
4
|
+
return useQuery({
|
|
5
|
+
queryKey: ['user', ctx.userId],
|
|
6
|
+
queryFn: async ({ signal }) => {
|
|
7
|
+
return getUser(ctx, { mapFn: (user) => user });
|
|
8
|
+
},
|
|
9
|
+
enabled: !!ctx.userId,
|
|
10
|
+
});
|
|
11
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -6,13 +6,29 @@ export * from './api/getTerms';
|
|
|
6
6
|
export * from './types/Term';
|
|
7
7
|
export * from './api/products/getProducts';
|
|
8
8
|
export * from './types/products/Product';
|
|
9
|
+
export * from './api/pages/page/page.service';
|
|
10
|
+
export * from './api/pages/page/pageService.types';
|
|
11
|
+
export * from './api/pages/faq/faq.service';
|
|
12
|
+
export * from './api/pages/faq/faqService.types';
|
|
13
|
+
export * from './api/pages/branch/branch.service';
|
|
14
|
+
export * from './api/pages/branch/branchService.types';
|
|
15
|
+
export * from './api/user/register/Register.service';
|
|
16
|
+
export * from './api/user/resetPassword/resetPassword.service';
|
|
17
|
+
export * from './hooks/user/useGetUser';
|
|
18
|
+
export * from './auth/auth/auth';
|
|
19
|
+
export * from './auth/auth/auth.config';
|
|
20
|
+
export * from './auth/auth/auth.types';
|
|
21
|
+
export * from './auth/context/AuthContext';
|
|
22
|
+
export * from './auth/hooks/useCurrentUser';
|
|
23
|
+
export * from './auth/hooks/useSignIn';
|
|
24
|
+
export * from './auth/hooks/useSignOut';
|
|
9
25
|
export * from './api/checkout/Checkout.service';
|
|
10
26
|
export * from './api/checkout/CheckoutService.types';
|
|
11
27
|
export * from './hooks/cart/api/useGetOrderHistory';
|
|
12
28
|
export * from './hooks/wishlist/useWishlist';
|
|
13
29
|
export * from './context';
|
|
14
30
|
export * from './context/cart/BasketContext';
|
|
15
|
-
export * from './api/cart/CartService.types';
|
|
16
31
|
export * from './api/cart/Cart.service';
|
|
32
|
+
export * from './api/cart/CartService.types';
|
|
17
33
|
export * from './utils/mapProducts';
|
|
18
34
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA,cAAc,0BAA0B,CAAA;AACxC,cAAc,uBAAuB,CAAA;AAErC,cAAc,yBAAyB,CAAA;AACvC,cAAc,sBAAsB,CAAA;AAGpC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAG5B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,0BAA0B,CAAA;AAGxC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,oCAAoC,CAAA;AAElD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,kCAAkC,CAAA;AAEhD,cAAc,mCAAmC,CAAA;AACjD,cAAc,wCAAwC,CAAA;AAGtD,cAAc,sCAAsC,CAAA;AACpD,cAAc,gDAAgD,CAAA;AAC9D,cAAc,yBAAyB,CAAA;AAGvC,cAAc,kBAAkB,CAAA;AAChC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AAEvC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,sCAAsC,CAAA;AAEpD,cAAc,qCAAqC,CAAA;AACnD,cAAc,8BAA8B,CAAA;AAE5C,cAAc,WAAW,CAAA;AACzB,cAAc,8BAA8B,CAAA;AAE5C,cAAc,yBAAyB,CAAA;AACvC,cAAc,8BAA8B,CAAA;AAE5C,cAAc,qBAAqB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,39 @@
|
|
|
1
|
+
//content
|
|
1
2
|
export * from './api/content/getBanners';
|
|
2
3
|
export * from './api/content/getBlog';
|
|
3
4
|
export * from './types/content/Banners';
|
|
4
5
|
export * from './types/content/Blog';
|
|
6
|
+
//terms
|
|
5
7
|
export * from './api/getTerms';
|
|
6
8
|
export * from './types/Term';
|
|
9
|
+
//products
|
|
7
10
|
export * from './api/products/getProducts';
|
|
8
11
|
export * from './types/products/Product';
|
|
12
|
+
// pages
|
|
13
|
+
export * from './api/pages/page/page.service';
|
|
14
|
+
export * from './api/pages/page/pageService.types';
|
|
15
|
+
export * from './api/pages/faq/faq.service';
|
|
16
|
+
export * from './api/pages/faq/faqService.types';
|
|
17
|
+
export * from './api/pages/branch/branch.service';
|
|
18
|
+
export * from './api/pages/branch/branchService.types';
|
|
19
|
+
//user api (len register a reset password)
|
|
20
|
+
export * from './api/user/register/Register.service';
|
|
21
|
+
export * from './api/user/resetPassword/resetPassword.service';
|
|
22
|
+
export * from './hooks/user/useGetUser';
|
|
23
|
+
// auth - hlavné auth funkcionality
|
|
24
|
+
export * from './auth/auth/auth';
|
|
25
|
+
export * from './auth/auth/auth.config';
|
|
26
|
+
export * from './auth/auth/auth.types';
|
|
27
|
+
export * from './auth/context/AuthContext';
|
|
28
|
+
export * from './auth/hooks/useCurrentUser';
|
|
29
|
+
export * from './auth/hooks/useSignIn';
|
|
30
|
+
export * from './auth/hooks/useSignOut';
|
|
9
31
|
export * from './api/checkout/Checkout.service';
|
|
10
32
|
export * from './api/checkout/CheckoutService.types';
|
|
11
33
|
export * from './hooks/cart/api/useGetOrderHistory';
|
|
12
34
|
export * from './hooks/wishlist/useWishlist';
|
|
13
35
|
export * from './context';
|
|
14
36
|
export * from './context/cart/BasketContext';
|
|
15
|
-
export * from './api/cart/CartService.types';
|
|
16
37
|
export * from './api/cart/Cart.service';
|
|
38
|
+
export * from './api/cart/CartService.types';
|
|
17
39
|
export * from './utils/mapProducts';
|
|
@@ -4,6 +4,7 @@ export type Product = {
|
|
|
4
4
|
type: string;
|
|
5
5
|
variation_name: string;
|
|
6
6
|
sku: string;
|
|
7
|
+
ean: number;
|
|
7
8
|
description: string;
|
|
8
9
|
price: number;
|
|
9
10
|
discountPercent: number | null;
|
|
@@ -24,6 +25,7 @@ export type Product = {
|
|
|
24
25
|
text: string;
|
|
25
26
|
color: string;
|
|
26
27
|
}>;
|
|
28
|
+
related_products?: Product[];
|
|
27
29
|
field_news?: boolean;
|
|
28
30
|
field_aftersale?: boolean;
|
|
29
31
|
field_care?: any[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Product.d.ts","sourceRoot":"","sources":["../../../types/products/Product.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,EAAE,G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,EAAE,MAAM,CAAC;IACd,wBAAwB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;KACb,EAAE,CAAC;IACJ,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function mapProduct(defaultProduct: any, variationProduct: any,
|
|
1
|
+
import { Product } from '../types/products/Product';
|
|
2
|
+
export declare function mapProduct(defaultProduct: any, variationProduct: any, ctx: any): Product;
|
|
3
|
+
export declare function mapProductLite(defaultProduct: any, variationProduct: any, ctx: any): any;
|
|
3
4
|
//# sourceMappingURL=mapProducts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapProducts.d.ts","sourceRoot":"","sources":["../../utils/mapProducts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mapProducts.d.ts","sourceRoot":"","sources":["../../utils/mapProducts.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,OAAO,EAAE,MAAM,2BAA2B,CAAC;AA0EzE,wBAAgB,UAAU,CAAC,cAAc,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAaxF;AAED,wBAAgB,cAAc,CAAC,cAAc,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,CAMxF"}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { getDiscountPercent } from '../utils/generalHelper';
|
|
2
2
|
function mapImages(images, ctx) {
|
|
3
|
-
const imagesArray = Array.isArray(images)
|
|
4
|
-
? images
|
|
5
|
-
: images
|
|
6
|
-
? [images]
|
|
7
|
-
: [];
|
|
3
|
+
const imagesArray = Array.isArray(images) ? images : images ? [images] : [];
|
|
8
4
|
if (imagesArray.length === 0) {
|
|
9
5
|
return [{ href: '/ks_logo.png', alt: 'Q2' }];
|
|
10
6
|
}
|
|
@@ -13,7 +9,6 @@ function mapImages(images, ctx) {
|
|
|
13
9
|
alt: img.name ?? 'Image',
|
|
14
10
|
}));
|
|
15
11
|
}
|
|
16
|
-
// Pomocná funkce na mapování variant
|
|
17
12
|
function mapVariations(variations = []) {
|
|
18
13
|
return variations.map((v) => {
|
|
19
14
|
const discountPercentVariation = getDiscountPercent(v.price, v.list_price);
|
|
@@ -26,12 +21,11 @@ function mapVariations(variations = []) {
|
|
|
26
21
|
discountPercentVariation,
|
|
27
22
|
ean: v.field_ean,
|
|
28
23
|
stock: v?.field_stock_level?.available_stock ?? 0,
|
|
29
|
-
href: ''
|
|
24
|
+
href: '',
|
|
30
25
|
};
|
|
31
26
|
});
|
|
32
27
|
}
|
|
33
|
-
|
|
34
|
-
export function mapProduct(defaultProduct, variationProduct, allVariations, ctx) {
|
|
28
|
+
function mapProductBase(defaultProduct, variationProduct, ctx) {
|
|
35
29
|
const defaultImages = defaultProduct.field_image;
|
|
36
30
|
const variationImages = variationProduct.field_image;
|
|
37
31
|
const discountPercent = getDiscountPercent(variationProduct.price, variationProduct.list_price);
|
|
@@ -44,7 +38,8 @@ export function mapProduct(defaultProduct, variationProduct, allVariations, ctx)
|
|
|
44
38
|
variation_uuid: variationProduct.id,
|
|
45
39
|
type: variationProduct.type,
|
|
46
40
|
variation_name: variationProduct.title,
|
|
47
|
-
sku: variationProduct.
|
|
41
|
+
sku: variationProduct.sku,
|
|
42
|
+
ean: variationProduct.field_ean,
|
|
48
43
|
description: defaultProduct.field_description?.processed ?? '',
|
|
49
44
|
price: variationProduct?.list_price?.number ? variationProduct.list_price.number : variationProduct.price?.number ?? 0,
|
|
50
45
|
discountPercent,
|
|
@@ -64,3 +59,20 @@ export function mapProduct(defaultProduct, variationProduct, allVariations, ctx)
|
|
|
64
59
|
field_shipping: defaultProduct.field_shipping ?? [],
|
|
65
60
|
};
|
|
66
61
|
}
|
|
62
|
+
export function mapProduct(defaultProduct, variationProduct, ctx) {
|
|
63
|
+
const base = mapProductBase(defaultProduct, variationProduct, ctx);
|
|
64
|
+
const relatedProducts = Array.isArray(defaultProduct.field_related_products) && defaultProduct.field_related_products[0]?.default_variation
|
|
65
|
+
? defaultProduct.field_related_products.map((related) => mapProductLite(related, related.default_variation, ctx))
|
|
66
|
+
: [];
|
|
67
|
+
return {
|
|
68
|
+
...base,
|
|
69
|
+
related_products: relatedProducts,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export function mapProductLite(defaultProduct, variationProduct, ctx) {
|
|
73
|
+
// console.log('Mapping product lite', defaultProduct, variationProduct);
|
|
74
|
+
return {
|
|
75
|
+
...mapProductBase(defaultProduct, variationProduct, ctx),
|
|
76
|
+
related_products: [],
|
|
77
|
+
};
|
|
78
|
+
}
|