@griddo/ax 12.16.0 → 12.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/README.md +1 -0
  2. package/config/griddo-config/index.js +3 -2
  3. package/package.json +7 -4
  4. package/public/img/logos/logoGriddoDxp.svg +22 -0
  5. package/public/img/logos/logoGriddoG.svg +10 -0
  6. package/src/GlobalStore.tsx +32 -25
  7. package/src/__tests__/GlobalStore.session.test.tsx +98 -0
  8. package/src/__tests__/api/global.test.ts +64 -0
  9. package/src/__tests__/api/session.test.ts +311 -0
  10. package/src/__tests__/api/sessionRenewal.test.ts +705 -0
  11. package/src/__tests__/api/utils.test.ts +373 -0
  12. package/src/__tests__/components/Fields/FileField/FileField.test.tsx +33 -6
  13. package/src/__tests__/components/FieldsBehavior/FieldsBehavior.test.tsx +5 -3
  14. package/src/__tests__/components/Login/BrandPalette.test.tsx +145 -0
  15. package/src/__tests__/components/Login/Login.test.tsx +2 -33
  16. package/src/__tests__/components/Login/LoginCollapsible.test.tsx +271 -0
  17. package/src/__tests__/components/Login/LoginDropdownCard.test.tsx +311 -0
  18. package/src/__tests__/components/Login/LoginFooter.test.tsx +128 -0
  19. package/src/__tests__/components/Login/LoginGriddoId.test.tsx +213 -0
  20. package/src/__tests__/components/Login/LoginInlineError.test.tsx +116 -0
  21. package/src/__tests__/components/Login/RecoveryModal/RecoveryModal.test.tsx +3 -4
  22. package/src/__tests__/components/SsoDenied/SsoDenied.test.tsx +86 -0
  23. package/src/__tests__/config/webpackAliases.test.ts +18 -0
  24. package/src/__tests__/containers/App/reducer.griddoId.test.ts +18 -0
  25. package/src/__tests__/containers/App/session.test.ts +397 -0
  26. package/src/__tests__/containers/App/signInOut.test.ts +159 -0
  27. package/src/__tests__/helpers/griddoId.test.ts +56 -0
  28. package/src/__tests__/hooks/useShouldBeSaved.test.tsx +78 -0
  29. package/src/__tests__/locales/loginLocale.test.ts +37 -0
  30. package/src/__tests__/modules/App/Routing/NavMenu.test.tsx +54 -0
  31. package/src/__tests__/modules/App/Routing/PrivateRoute.test.tsx +64 -0
  32. package/src/__tests__/modules/App/Routing/Routing.startup.test.tsx +79 -0
  33. package/src/__tests__/modules/Login/Login.test.tsx +169 -0
  34. package/src/__tests__/modules/Login/loginError.uc.test.tsx +294 -0
  35. package/src/__tests__/modules/Login/signInOut.test.tsx +125 -0
  36. package/src/__tests__/modules/Redirects/RedirectPanel/RedirectPanel.test.tsx +9 -0
  37. package/src/__tests__/modules/Redirects/Redirects/Redirects.create.test.tsx +19 -0
  38. package/src/__tests__/modules/Redirects/Redirects/Redirects.edit.test.tsx +19 -0
  39. package/src/__tests__/modules/Redirects/Redirects/Redirects.filter.test.tsx +19 -0
  40. package/src/__tests__/modules/SsoDenied/SsoDenied.test.tsx +30 -0
  41. package/src/__tests__/routes/publicRoutes.test.ts +36 -0
  42. package/src/api/global.tsx +24 -1
  43. package/src/api/session.tsx +197 -0
  44. package/src/api/sessionRenewal.tsx +114 -0
  45. package/src/api/utils.tsx +22 -12
  46. package/src/{helpers/categoryColumns.tsx → components/CategoryCell/buildCategoryColumns.tsx} +3 -2
  47. package/src/components/Circle/index.tsx +1 -1
  48. package/src/components/Circle/style.tsx +4 -2
  49. package/src/components/ErrorPage/index.tsx +1 -1
  50. package/src/components/ErrorPage/style.tsx +11 -9
  51. package/src/components/ErrorToast/index.tsx +2 -0
  52. package/src/{helpers/fields.tsx → components/FieldsBehavior/getFieldByPath.tsx} +1 -1
  53. package/src/components/FieldsBehavior/index.tsx +3 -1
  54. package/src/components/Login/LoginFooter/index.tsx +16 -0
  55. package/src/components/Login/LoginFooter/style.tsx +17 -0
  56. package/src/components/Login/LoginForm/index.tsx +147 -79
  57. package/src/components/Login/LoginForm/style.tsx +147 -24
  58. package/src/components/Login/LoginGriddoId/index.tsx +56 -0
  59. package/src/components/Login/LoginGriddoId/style.tsx +35 -0
  60. package/src/components/Login/LoginSSO/index.tsx +4 -7
  61. package/src/components/Login/LoginSSO/style.tsx +10 -26
  62. package/src/components/Login/LoginSlider/style.tsx +5 -5
  63. package/src/components/Login/index.tsx +35 -6
  64. package/src/components/Login/style.tsx +40 -24
  65. package/src/components/Notification/index.tsx +3 -1
  66. package/src/components/SsoDenied/index.tsx +46 -0
  67. package/src/components/SsoDenied/style.tsx +37 -0
  68. package/src/components/index.tsx +11 -7
  69. package/src/containers/App/actions.tsx +114 -6
  70. package/src/containers/App/interfaces.tsx +2 -2
  71. package/src/containers/App/reducer.tsx +9 -0
  72. package/src/containers/Users/actions.tsx +28 -24
  73. package/src/helpers/griddoId.ts +28 -0
  74. package/src/helpers/index.tsx +4 -5
  75. package/src/hooks/forms.tsx +8 -5
  76. package/src/locales/en-US.ts +13 -0
  77. package/src/locales/es-ES.ts +13 -0
  78. package/src/locales/index.ts +9 -1
  79. package/src/modules/App/Routing/NavMenu/index.tsx +4 -4
  80. package/src/modules/Content/PageItem/index.tsx +6 -8
  81. package/src/modules/Login/index.tsx +33 -14
  82. package/src/modules/SsoDenied/index.tsx +9 -0
  83. package/src/modules/StructuredData/StructuredDataList/GlobalPageItem/index.tsx +6 -8
  84. package/src/modules/StructuredData/StructuredDataList/StructuredDataItem/index.tsx +9 -11
  85. package/src/modules/Users/UserEdit/index.tsx +9 -2
  86. package/src/routes/publicRoutes.tsx +3 -0
  87. package/src/themes/brandPalette.ts +16 -0
  88. package/public/img/logos/logoSQY.svg +0 -3
@@ -1,8 +1,10 @@
1
1
  import { useEffect, useRef, useState } from "react";
2
2
 
3
- import type { IGlobalSettings } from "@ax/containers/App/reducer";
4
3
  import { Circle } from "@ax/components";
5
- import LoginForm from "./LoginForm";
4
+ import type { IGlobalSettings } from "@ax/containers/App/reducer";
5
+
6
+ import LoginForm, { type ILoginSubmitContext } from "./LoginForm";
7
+ import LoginGriddoId from "./LoginGriddoId";
6
8
  import LoginSSO from "./LoginSSO";
7
9
 
8
10
  import * as S from "./style";
@@ -21,6 +23,7 @@ const Login = (props: ILoginProps): JSX.Element => {
21
23
  isLoginSuccess,
22
24
  handleLoginSuccess,
23
25
  handleSSO,
26
+ handleGriddoId,
24
27
  errorSSO,
25
28
  } = props;
26
29
 
@@ -42,13 +45,25 @@ const Login = (props: ILoginProps): JSX.Element => {
42
45
  };
43
46
  }, []);
44
47
 
48
+ // El logo «griddo dxp» solo acompaña al login con Griddo ID: el de siempre ya lleva su «Welcome to» con
49
+ // logo y el SSO de Comillas el suyo.
50
+ const showBrand = Boolean(settings.GriddoIdEnabled) && !settings.SSOActivated;
51
+
45
52
  const _handleAnimationEnd = () => handleLoginSuccess();
46
53
 
47
54
  return (
48
55
  <S.Wrapper data-testid="login-wrapper">
49
- <S.LeftWrapper className={isLoginSuccess ? "animate" : ""} onAnimationEnd={_handleAnimationEnd} ref={wrapperRef}>
56
+ <S.LeftWrapper
57
+ data-testid="login-left"
58
+ className={isLoginSuccess ? "animate" : ""}
59
+ onAnimationEnd={_handleAnimationEnd}
60
+ ref={wrapperRef}
61
+ >
62
+ <S.Halo data-testid="login-halo" />
50
63
  <S.LoginWrapper className={isLoginSuccess ? "animate" : ""} width={wrapperWidth}>
51
64
  {settings.SSOActivated ? (
65
+ // SSO de Comillas: la pantalla de siempre, sin formulario y sin «Entrar con Griddo» (ese botón
66
+ // solo existe junto al login normal), con o sin `GriddoIdEnabled`.
52
67
  <LoginSSO handleSSO={handleSSO} errorSSO={errorSSO} settings={settings} />
53
68
  ) : (
54
69
  <LoginForm
@@ -61,13 +76,25 @@ const Login = (props: ILoginProps): JSX.Element => {
61
76
  settings={settings}
62
77
  rememberMe={rememberMe}
63
78
  handleRememberMe={handleRememberMe}
79
+ brand={
80
+ showBrand && (
81
+ <S.Brand data-testid="login-brand">
82
+ <img src="/img/logos/logoGriddoDxp.svg" alt="Griddo DXP" />
83
+ </S.Brand>
84
+ )
85
+ }
86
+ alternative={
87
+ settings.GriddoIdEnabled && (
88
+ <LoginGriddoId handleGriddoId={handleGriddoId ?? (() => undefined)} errorSSO={errorSSO} />
89
+ )
90
+ }
64
91
  />
65
92
  )}
66
93
  </S.LoginWrapper>
67
94
  </S.LeftWrapper>
68
95
  <S.RightWrapper>
69
- <Circle animation={1} />
70
- <Circle animation={2} />
96
+ <Circle animation={1} size={365} />
97
+ <Circle animation={2} size={419} />
71
98
  <S.AnimatedLoginSlider className={isLoginSuccess ? "animate" : ""} />
72
99
  </S.RightWrapper>
73
100
  </S.Wrapper>
@@ -75,7 +102,7 @@ const Login = (props: ILoginProps): JSX.Element => {
75
102
  };
76
103
 
77
104
  export interface ILoginProps {
78
- handleSubmit: (e: React.FormEvent<HTMLFormElement>) => void;
105
+ handleSubmit: (e: React.FormEvent<HTMLFormElement>, context?: ILoginSubmitContext) => void;
79
106
  email: string;
80
107
  handleEmail: (email: string) => void;
81
108
  password: string;
@@ -87,6 +114,8 @@ export interface ILoginProps {
87
114
  isLoginSuccess: boolean;
88
115
  handleLoginSuccess: () => void;
89
116
  handleSSO: () => void;
117
+ /** Navega a `/sso/start` de la API (login con auth.griddo.io). */
118
+ handleGriddoId?: () => void;
90
119
  errorSSO: string | null;
91
120
  }
92
121
 
@@ -1,11 +1,14 @@
1
+ import { BRAND_PALETTE } from "@ax/themes/brandPalette";
2
+
1
3
  import styled, { keyframes } from "styled-components";
4
+
2
5
  import LoginSlider from "./LoginSlider";
3
6
 
4
7
  const Wrapper = styled.section`
5
8
  position: relative;
6
9
  display: flex;
7
10
  height: 100vh;
8
- background: ${(p) => p.theme.color.uiBackground04};
11
+ background: ${BRAND_PALETTE.navy};
9
12
  flex-direction: row;
10
13
  `;
11
14
 
@@ -24,8 +27,9 @@ const OpacityAnimation = keyframes`
24
27
  const LeftWrapper = styled.div`
25
28
  position: relative;
26
29
  display: flex;
27
- width: 45%;
28
- background: ${(p) => p.theme.color.uiBackground04};
30
+ width: 44.6875%; // Figma: columna de 572px sobre 1280
31
+ overflow: hidden;
32
+ background: ${BRAND_PALETTE.navy};
29
33
 
30
34
  &.animate {
31
35
  position: absolute;
@@ -38,7 +42,24 @@ const LeftWrapper = styled.div`
38
42
  }
39
43
  `;
40
44
 
45
+ // Halo de marca (Figma `blur-mono`, 419px en x45/y470 de un frame 1280x800): detrás del contenido y sin clics.
46
+ const Halo = styled.div`
47
+ position: absolute;
48
+ left: 7.87%;
49
+ top: 59%;
50
+ z-index: 0;
51
+ width: 419px;
52
+ height: 419px;
53
+ border-radius: 50%;
54
+ background-color: ${BRAND_PALETTE.turquoise};
55
+ filter: blur(50px);
56
+ opacity: 0.5;
57
+ pointer-events: none;
58
+ `;
59
+
41
60
  const LoginWrapper = styled.div<{ width: number }>`
61
+ position: relative;
62
+ z-index: 1;
42
63
  width: ${(p) => (p.width > 0 ? `${p.width}px` : "100%")};
43
64
  display: flex;
44
65
  align-items: center;
@@ -52,10 +73,23 @@ const LoginWrapper = styled.div<{ width: number }>`
52
73
  }
53
74
  `;
54
75
 
76
+ // Logo del bloque anclado: en el flujo, 96px sobre «Welcome» (logo y=64; «Welcome» a y=196, centrado con la línea
77
+ // «content at any time» del slider).
78
+ const Brand = styled.div`
79
+ margin-bottom: 96px;
80
+
81
+ img {
82
+ display: block;
83
+ height: 36px;
84
+ width: auto;
85
+ }
86
+ `;
87
+
88
+ // Figma: la mitad derecha va sobre `#022958` (más clara que la izquierda), de ahí el corte entre columnas.
55
89
  const RightWrapper = styled.div`
56
- background-color: #001b3c;
90
+ background-color: ${BRAND_PALETTE.navyControl};
57
91
  position: relative;
58
- width: 55%;
92
+ width: 55.3125%;
59
93
  height: 100%;
60
94
  color: ${(p) => p.theme.color.textHighEmphasisInverse};
61
95
  margin-left: auto;
@@ -71,22 +105,4 @@ const AnimatedLoginSlider = styled(LoginSlider)`
71
105
  }
72
106
  `;
73
107
 
74
- const Secuoyas = styled.div<{ width: number }>`
75
- ${(p) => p.theme.textStyle.uiXS};
76
- position: absolute;
77
- display: flex;
78
- color: ${(p) => p.theme.color.textMediumEmphasisInverse};
79
- width: ${(p) => (p.width > 0 ? `${p.width}px` : "100%")};
80
- justify-content: center;
81
- align-items: center;
82
- left: 0;
83
- bottom: ${(p) => p.theme.spacing.m};
84
- padding-bottom: ${(p) => p.theme.spacing.xs};
85
- img {
86
- width: 20px;
87
- height: 20px;
88
- margin-left: ${(p) => p.theme.spacing.xs};
89
- }
90
- `;
91
-
92
- export { Wrapper, LeftWrapper, RightWrapper, LoginWrapper, AnimatedLoginSlider, Secuoyas };
108
+ export { AnimatedLoginSlider, Brand, Halo, LeftWrapper, LoginWrapper, RightWrapper, Wrapper };
@@ -1,5 +1,7 @@
1
1
  import { useState } from "react";
2
+
2
3
  import { Icon } from "@ax/components";
4
+
3
5
  import SubNotification from "./SubNotification";
4
6
 
5
7
  import * as S from "./style";
@@ -42,7 +44,7 @@ const Notification = (props: INotificationProps): JSX.Element => {
42
44
 
43
45
  const { handleErrorClick } = window as any;
44
46
 
45
- const handleClick = () => (onClick ? onClick() : handleErrorClick());
47
+ const handleClick = () => (onClick ? onClick() : handleErrorClick?.());
46
48
 
47
49
  const handleClose = () => {
48
50
  resetError?.();
@@ -0,0 +1,46 @@
1
+ import { useEffect, useRef } from "react";
2
+
3
+ import { Circle } from "@ax/components";
4
+ import { getLoginLocale } from "@ax/locales";
5
+
6
+ import * as S from "./style";
7
+
8
+ /**
9
+ * S6: acceso denegado tras el login con `auth.griddo.io`. Texto fijo: no lee parámetros de la URL ni distingue
10
+ * la causa (la API redirige aquí igual para todas). «Entrar con otra cuenta» cierra la sesión central y empieza
11
+ * un login nuevo.
12
+ */
13
+ const SsoDenied = (props: ISsoDeniedProps): JSX.Element => {
14
+ const { switchAccountUrl } = props;
15
+
16
+ const text = getLoginLocale();
17
+ const titleRef = useRef<HTMLHeadingElement>(null);
18
+
19
+ useEffect(() => {
20
+ titleRef.current?.focus();
21
+ }, []);
22
+
23
+ return (
24
+ <S.Wrapper data-testid="sso-denied-wrapper">
25
+ <S.LeftWrapper>
26
+ <S.Content>
27
+ <S.Title ref={titleRef} tabIndex={-1}>
28
+ {text.deniedTitle}
29
+ </S.Title>
30
+ <S.SwitchAccount href={switchAccountUrl}>{text.switchAccount}</S.SwitchAccount>
31
+ </S.Content>
32
+ </S.LeftWrapper>
33
+ <S.RightWrapper>
34
+ <Circle animation={1} />
35
+ <Circle animation={2} />
36
+ </S.RightWrapper>
37
+ </S.Wrapper>
38
+ );
39
+ };
40
+
41
+ export interface ISsoDeniedProps {
42
+ /** URL absoluta de `GET /sso/switch-account` de la API. */
43
+ switchAccountUrl: string;
44
+ }
45
+
46
+ export default SsoDenied;
@@ -0,0 +1,37 @@
1
+ import styled from "styled-components";
2
+
3
+ import * as Login from "../Login/style";
4
+
5
+ const Title = styled.h1`
6
+ ${(p) => p.theme.textStyle.headingL};
7
+ color: ${(p) => p.theme.color.textHighEmphasisInverse};
8
+ margin-bottom: ${(p) => p.theme.spacing.m};
9
+ max-width: 416px;
10
+
11
+ &:focus {
12
+ outline: none;
13
+ }
14
+ `;
15
+
16
+ const SwitchAccount = styled.a`
17
+ ${(p) => p.theme.textStyle.uiM};
18
+ color: ${(p) => p.theme.color.textMediumEmphasisInverse};
19
+ text-decoration: underline;
20
+
21
+ &:hover,
22
+ &:focus-visible {
23
+ color: ${(p) => p.theme.color.textHighEmphasisInverse};
24
+ }
25
+ `;
26
+
27
+ const Content = styled.div`
28
+ display: flex;
29
+ flex-direction: column;
30
+ justify-content: center;
31
+ align-items: flex-start;
32
+ width: 100%;
33
+ padding: 0 ${(p) => p.theme.spacing.l};
34
+ `;
35
+
36
+ export const { Wrapper, LeftWrapper, RightWrapper } = Login;
37
+ export { Content, SwitchAccount, Title };
@@ -7,9 +7,10 @@ import BrowserContent from "./BrowserContent";
7
7
  import BulkSelectionOptions from "./BulkSelectionOptions";
8
8
  import Button from "./Button";
9
9
  import CategoryCell from "./CategoryCell";
10
+ import { buildCategoryColumns } from "./CategoryCell/buildCategoryColumns";
10
11
  import Circle from "./Circle";
11
- import ContentItem from "./ContentItem";
12
12
  import ConfigPanel from "./ConfigPanel";
13
+ import ContentItem from "./ContentItem";
13
14
  import ContextMenu from "./ContextMenu";
14
15
  import DragAndDrop from "./DragAndDrop";
15
16
  import ElementsTooltip from "./ElementsTooltip";
@@ -104,6 +105,7 @@ import SearchTagsBar from "./SearchTagsBar";
104
105
  import SelectionComponent from "./SelectionComponent";
105
106
  import SharePageModal from "./SharePageModal";
106
107
  import SideModal from "./SideModal";
108
+ import SsoDenied from "./SsoDenied";
107
109
  import StatusTile from "./StatusTile";
108
110
  import SubNav from "./SubNav";
109
111
  import TableCounter from "./TableCounter";
@@ -146,6 +148,7 @@ export {
146
148
  BrowserContent,
147
149
  BulkSelectionOptions,
148
150
  Button,
151
+ buildCategoryColumns,
149
152
  CancelScheduleModal,
150
153
  CategoryCell,
151
154
  CategoryFilter,
@@ -155,9 +158,9 @@ export {
155
158
  Circle,
156
159
  ComponentArray,
157
160
  ComponentContainer,
158
- ContentItem,
159
161
  ConditionalField,
160
162
  ConfigPanel,
163
+ ContentItem,
161
164
  ContextMenu,
162
165
  CustomizeFilters,
163
166
  DateField,
@@ -186,8 +189,8 @@ export {
186
189
  FormFieldArray,
187
190
  Gallery,
188
191
  GuardModal,
189
- HeadingsPreviewModal,
190
192
  HeadingField,
193
+ HeadingsPreviewModal,
191
194
  HiddenField,
192
195
  Icon,
193
196
  IconAction,
@@ -195,8 +198,8 @@ export {
195
198
  ImageDragAndDrop,
196
199
  ImageField,
197
200
  InformativeMenu,
198
- KeywordsPreviewModal,
199
201
  IntegrationsField,
202
+ KeywordsPreviewModal,
200
203
  LanguageMenu,
201
204
  LastAccessFilter,
202
205
  LinkField,
@@ -218,8 +221,8 @@ export {
218
221
  OcassionalToast,
219
222
  PageFinder,
220
223
  Pagination,
221
- ProfileImage,
222
224
  PermissionsFilter,
225
+ ProfileImage,
223
226
  ProgressBar,
224
227
  RadioField,
225
228
  RadioGroup,
@@ -231,14 +234,15 @@ export {
231
234
  RichText,
232
235
  RoleFilter,
233
236
  ScheduleModal,
237
+ SEOPreview,
234
238
  SearchField,
235
239
  SearchTagsBar,
236
240
  Select,
237
241
  SelectionComponent,
238
- SEOPreview,
239
242
  SharePageModal,
240
243
  SideModal,
241
244
  SiteFilter,
245
+ SsoDenied,
242
246
  StateFilter,
243
247
  StatusFilter,
244
248
  StatusTile,
@@ -260,8 +264,8 @@ export {
260
264
  TypeFilter,
261
265
  UniqueCheck,
262
266
  UrlField,
263
- UsersFilter,
264
267
  UserRolesAndSites,
268
+ UsersFilter,
265
269
  VisualOption,
266
270
  VisualUniqueSelection,
267
271
  Wysiwyg,
@@ -7,6 +7,7 @@ import type { AxiosResponse } from "axios";
7
7
  import differenceInSeconds from "date-fns/differenceInSeconds";
8
8
  import type { Dispatch } from "redux";
9
9
 
10
+ import { clearSession, getSession, type ISession, markSessionEnded, setSession } from "../../api/session";
10
11
  import history from "../../routes/history";
11
12
  import {
12
13
  IS_LOGGING_IN,
@@ -82,15 +83,116 @@ function setToken(token: string): ISetTokenAction {
82
83
  return { type: SET_TOKEN, payload: { token } };
83
84
  }
84
85
 
85
- function logout(): ILogoutAction {
86
+ /** Acción que refleja en el store un par de sesión ya guardado (renovación o login). */
87
+ function setSessionTokens(session: ISession): ISetTokenAction {
88
+ return {
89
+ type: SET_TOKEN,
90
+ payload: { token: session.token, refreshToken: session.refreshToken ?? "", sessionUpdatedAt: session.updatedAt },
91
+ };
92
+ }
93
+
94
+ /**
95
+ * Guarda un par de sesión nuevo (login, SSO, creación o cambio de contraseña) en memoria y disco, y lo
96
+ * refleja en el store. `refreshToken` ausente = API antigua: el 401 cerrará sesión sin renovar.
97
+ */
98
+ function applySession(token: string, refreshToken?: string | null): (dispatch: Dispatch) => void {
99
+ return (dispatch) => {
100
+ dispatch(setSessionTokens(setSession(token, refreshToken ?? null)));
101
+ };
102
+ }
103
+
104
+ /** Limpia el estado local de la sesión (almacenamiento y memoria) y devuelve la acción que vacía el store. */
105
+ function clearLocalSession(): ILogoutAction {
86
106
  const listConfig = localStorage.getItem("sitesConfig") || "";
87
107
  localStorage.clear();
88
108
  localStorage.setItem("sitesConfig", listConfig);
89
- return { type: LOGOUT, payload: { token: "" } };
109
+ clearSession();
110
+ return { type: LOGOUT, payload: { token: "", refreshToken: "", sessionUpdatedAt: 0 } };
111
+ }
112
+
113
+ /**
114
+ * Limpia la sesión local y avisa a la API en segundo plano (revoca la familia de refresh). El cierre local
115
+ * no espera ni depende de la respuesta; un 401 del logout no dispara renovación ni otro cierre.
116
+ */
117
+ function logout(): ILogoutAction {
118
+ const session = getSession();
119
+ if (session) {
120
+ Promise.resolve(global.logout({ token: session.token, refreshToken: session.refreshToken })).catch(() => undefined);
121
+ }
122
+ return clearLocalSession();
123
+ }
124
+
125
+ /** Espera máxima de `POST /logout` en el cierre manual: más allá, AX cierra solo en local. */
126
+ const END_SESSION_TIMEOUT_MS = 5000;
127
+
128
+ /** `endSessionUrl` de la respuesta de `POST /logout` si es una URL http(s); `null` si no hay o no vale. */
129
+ function readEndSessionUrl(
130
+ response: { status?: number; data?: { endSessionUrl?: unknown } } | undefined,
131
+ ): string | null {
132
+ const url = response?.status === 200 ? response.data?.endSessionUrl : undefined;
133
+
134
+ if (typeof url !== "string" || !URL.canParse(url)) return null;
135
+
136
+ return ["https:", "http:"].includes(new URL(url).protocol) ? url : null;
137
+ }
138
+
139
+ /**
140
+ * «Logout» del menú. Avisa a la API esperando la respuesta (máximo 5 s) para saber si la sesión nació de
141
+ * `auth.griddo.io`: en ese caso limpia lo local y navega a la URL de cierre de la sesión central (la persona acaba en
142
+ * «Sesión cerrada» de auth.griddo.io; Hydra avisa a las demás instancias). En cualquier otro caso (sesión con
143
+ * contraseña, error, timeout, URL no válida) se comporta como `logoutAndNavigate`. Solo con `GriddoIdEnabled`: sin él
144
+ * (SSO de Comillas o contraseña) es exactamente `logoutAndNavigate`. La expiración por 401 y el logout por broadcast
145
+ * siguen siendo solo locales.
146
+ */
147
+ function logoutAndEndCentralSession(): (dispatch: Dispatch, getState: () => IRootState) => Promise<void> {
148
+ return async (dispatch, getState) => {
149
+ // Sin Griddo ID (SSO de Comillas o contraseña) el logout es el de siempre: local, sin esperar a la API.
150
+ if (!getState().app.globalSettings.GriddoIdEnabled) {
151
+ await logoutAndNavigate()(dispatch);
152
+
153
+ return;
154
+ }
155
+
156
+ markSessionEnded();
157
+
158
+ const session = getSession();
159
+ let endSessionUrl: string | null = null;
160
+
161
+ if (session) {
162
+ let timer: ReturnType<typeof setTimeout> | undefined;
163
+
164
+ try {
165
+ const response = await Promise.race([
166
+ Promise.resolve(global.logout({ token: session.token, refreshToken: session.refreshToken })),
167
+ new Promise<undefined>((resolve) => {
168
+ timer = setTimeout(() => resolve(undefined), END_SESSION_TIMEOUT_MS);
169
+ }),
170
+ ]);
171
+
172
+ endSessionUrl = readEndSessionUrl(response as Parameters<typeof readEndSessionUrl>[0]);
173
+ } catch {
174
+ endSessionUrl = null;
175
+ } finally {
176
+ clearTimeout(timer);
177
+ }
178
+ }
179
+
180
+ dispatch(clearLocalSession());
181
+
182
+ if (endSessionUrl) {
183
+ window.location.assign(endSessionUrl);
184
+
185
+ return;
186
+ }
187
+
188
+ await setHistoryPush("/logout")(dispatch);
189
+ };
90
190
  }
91
191
 
92
192
  function logoutAndNavigate(): (dispatch: Dispatch) => Promise<void> {
93
193
  return async (dispatch) => {
194
+ // Cierre manual, por 401 o recibido por broadcast: un 401 en vuelo no debe despachar otro.
195
+ markSessionEnded();
94
196
  await setHistoryPush("/logout")(dispatch);
95
197
  };
96
198
  }
@@ -164,11 +266,13 @@ function login(loginData: {
164
266
  password?: string;
165
267
  rememberMe?: boolean;
166
268
  petitionId?: string;
269
+ /** Acción del botón «Lost your password?» del aviso del 403 (no depende de `window`). */
270
+ onLostPassword?: () => void;
167
271
  }): (dispatch: Dispatch, setState: () => IRootState) => Promise<boolean> {
168
272
  return async (dispatch, setState) => {
169
273
  dispatch(setIsLogging(true));
170
- const { email, password, rememberMe, petitionId } = loginData;
171
- const loginResponse: AxiosResponse<{ id: number; token: string }> = await global.login({
274
+ const { email, password, rememberMe, petitionId, onLostPassword } = loginData;
275
+ const loginResponse: AxiosResponse<{ id: number; token: string; refreshToken?: string }> = await global.login({
172
276
  username: email,
173
277
  password,
174
278
  petitionId,
@@ -177,11 +281,11 @@ function login(loginData: {
177
281
  switch (loginResponse?.status) {
178
282
  case 200: {
179
283
  const {
180
- data: { id, token },
284
+ data: { id, token, refreshToken },
181
285
  } = loginResponse;
182
286
  const langResponse = await languages.getLanguages(token);
183
287
  isReqOk(langResponse.status) && dispatch(setGlobalLanguages(langResponse.data.items));
184
- dispatch(setToken(loginResponse.data.token));
288
+ applySession(token, refreshToken)(dispatch);
185
289
  await usersActions.getUser(id, token, false)(dispatch, setState);
186
290
  dispatch(setSessionStartedAt(new Date()));
187
291
  dispatch(setHasAnimation(true));
@@ -195,6 +299,7 @@ function login(loginData: {
195
299
  const error = {
196
300
  ...loginResponse,
197
301
  btnText: "Lost your password?",
302
+ btnAction: onLostPassword,
198
303
  actionsBelow: true,
199
304
  };
200
305
  handleError(error)(dispatch);
@@ -267,12 +372,14 @@ function checkUserSession(): (dispatch: Dispatch, getState: () => IRootState) =>
267
372
  }
268
373
 
269
374
  export {
375
+ applySession,
270
376
  checkUserSession,
271
377
  getGlobalSettings,
272
378
  handleError,
273
379
  login,
274
380
  loginSSO,
275
381
  logout,
382
+ logoutAndEndCentralSession,
276
383
  logoutAndNavigate,
277
384
  resetError,
278
385
  setError,
@@ -284,6 +391,7 @@ export {
284
391
  setIsLogging,
285
392
  setIsSaving,
286
393
  setLanguage,
394
+ setSessionTokens,
287
395
  setToken,
288
396
  setUser,
289
397
  };
@@ -17,12 +17,12 @@ import type { IUser } from "./reducer";
17
17
 
18
18
  export interface ISetTokenAction {
19
19
  type: typeof SET_TOKEN;
20
- payload: { token: string };
20
+ payload: { token: string; refreshToken?: string; sessionUpdatedAt?: number };
21
21
  }
22
22
 
23
23
  export interface ILogoutAction {
24
24
  type: typeof LOGOUT;
25
- payload: { token: string };
25
+ payload: { token: string; refreshToken: string; sessionUpdatedAt: number };
26
26
  }
27
27
 
28
28
  export interface IIsLoggingInAction {
@@ -26,6 +26,10 @@ export interface IAppState {
26
26
  error: IError;
27
27
  user: IUser;
28
28
  token: string;
29
+ /** Refresh token de la sesión ("" = sin refresh: API antigua o sesión previa al despliegue). */
30
+ refreshToken: string;
31
+ /** Versión del par token/refresh (ms); decide qué pestaña tiene el par más nuevo. */
32
+ sessionUpdatedAt: number;
29
33
  isLoggingIn: boolean;
30
34
  lang: { locale: string; id: number };
31
35
  globalLangs: ILanguage[];
@@ -60,6 +64,8 @@ export interface IGlobalSettings {
60
64
  autoSummary: boolean;
61
65
  autoTranslation: boolean;
62
66
  SSOActivated: boolean;
67
+ /** `GRIDDO_ID_ENABLED` de la API: muestra «Entrar con Griddo». Apagado por defecto (también si `GET /settings` falla). */
68
+ GriddoIdEnabled: boolean;
63
69
  SSOWelcomeText: string;
64
70
  useForms: boolean;
65
71
  }
@@ -77,6 +83,8 @@ export const initialState = {
77
83
  email: "",
78
84
  },
79
85
  token: "",
86
+ refreshToken: "",
87
+ sessionUpdatedAt: 0,
80
88
  isLoggingIn: false,
81
89
  lang: {
82
90
  locale: "en-GB",
@@ -94,6 +102,7 @@ export const initialState = {
94
102
  autoSummary: false,
95
103
  autoTranslation: false,
96
104
  SSOActivated: false,
105
+ GriddoIdEnabled: false,
97
106
  SSOWelcomeText: "",
98
107
  useForms: false,
99
108
  },