@uxland/primary-shell 8.3.3 → 8.3.5

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 (154) hide show
  1. package/README.md +18 -1
  2. package/dist/{component-BYXgNvke.js → component-Dv2Cw4dX.js} +2 -2
  3. package/dist/{component-BYXgNvke.js.map → component-Dv2Cw4dX.js.map} +1 -1
  4. package/dist/{index-CDpyZ5Yt.js → index-CCC4rQo1.js} +2629 -2628
  5. package/dist/{index-CDpyZ5Yt.js.map → index-CCC4rQo1.js.map} +1 -1
  6. package/dist/index.js +21 -22
  7. package/dist/index.js.map +1 -1
  8. package/dist/{plugin-CMgpCPh9.js → plugin-D3sg1ev9.js} +5 -6
  9. package/dist/{plugin-CMgpCPh9.js.map → plugin-D3sg1ev9.js.map} +1 -1
  10. package/package.json +7 -15
  11. package/src/UI/bootstrapper.ts +0 -14
  12. package/src/UI/components/bootstrapper.ts +0 -25
  13. package/src/UI/components/clinical-pathways-action-menu/clinical-pathways-action-menu.ts +0 -13
  14. package/src/UI/components/communication-action-menu/communication-action-menu.ts +0 -13
  15. package/src/UI/components/error-view/component.ts +0 -17
  16. package/src/UI/components/error-view/styles.css +0 -27
  17. package/src/UI/components/error-view/template.ts +0 -12
  18. package/src/UI/components/nav-divider/nav-divider.ts +0 -41
  19. package/src/UI/components/nav-divider/styles.css +0 -21
  20. package/src/UI/components/nav-divider/template.ts +0 -8
  21. package/src/UI/components/petitioner-action-menu/petitioner-action-menu.ts +0 -13
  22. package/src/UI/components/primaria-accordion/primaria-accordion.ts +0 -45
  23. package/src/UI/components/primaria-shell/constants.ts +0 -4
  24. package/src/UI/components/primaria-shell/primaria-shell.ts +0 -105
  25. package/src/UI/components/primaria-shell/shell-header/header-divider/header-divider.ts +0 -13
  26. package/src/UI/components/primaria-shell/shell-header/header-divider/styles.css +0 -5
  27. package/src/UI/components/primaria-shell/shell-header/header-divider/template.ts +0 -8
  28. package/src/UI/components/primaria-shell/shell-header/shell-header.ts +0 -71
  29. package/src/UI/components/primaria-shell/shell-header/styles.css +0 -45
  30. package/src/UI/components/primaria-shell/shell-header/template.ts +0 -37
  31. package/src/UI/components/primaria-shell/styles.css +0 -185
  32. package/src/UI/components/primaria-shell/template.ts +0 -72
  33. package/src/UI/components/sidenav-action-menu/sidenav-action-menu.ts +0 -62
  34. package/src/UI/components/sidenav-action-menu/styles.css +0 -25
  35. package/src/UI/components/sidenav-action-menu/template.ts +0 -24
  36. package/src/UI/fonts/fonts.css +0 -48
  37. package/src/UI/fonts/open-sans-v40-latin-300.woff2 +0 -0
  38. package/src/UI/fonts/open-sans-v40-latin-500.woff2 +0 -0
  39. package/src/UI/fonts/open-sans-v40-latin-600.woff2 +0 -0
  40. package/src/UI/fonts/open-sans-v40-latin-700.woff2 +0 -0
  41. package/src/UI/fonts/open-sans-v40-latin-800.woff2 +0 -0
  42. package/src/UI/fonts/open-sans-v40-latin-regular.woff2 +0 -0
  43. package/src/UI/images/Gencat_Logotip.svg +0 -70
  44. package/src/UI/images/Salut_Logotip.svg +0 -8
  45. package/src/UI/index.ts +0 -1
  46. package/src/UI/internal-views/administrative-nav-menu.ts +0 -302
  47. package/src/UI/internal-views/common-nav-menu.ts +0 -94
  48. package/src/UI/internal-views/doctor-nav-menu.ts +0 -297
  49. package/src/UI/internal-views/doctor-quick-action-menu.ts +0 -16
  50. package/src/UI/internal-views/handle-views.ts +0 -24
  51. package/src/UI/shared-components/bootstrapper.ts +0 -18
  52. package/src/UI/shared-components/index.ts +0 -1
  53. package/src/UI/shared-components/primaria-character-limit-badge/primaria-character-limit-badge.ts +0 -27
  54. package/src/UI/shared-components/primaria-character-limit-badge/styles.css +0 -8
  55. package/src/UI/shared-components/primaria-content-switcher/primaria-content-switcher.ts +0 -78
  56. package/src/UI/shared-components/primaria-nav-item/primaria-nav-item.ts +0 -71
  57. package/src/UI/shared-components/primaria-nav-item/styles.css +0 -25
  58. package/src/UI/shared-components/primaria-nav-item/template.ts +0 -27
  59. package/src/UI/shared-components/primaria-nav-tree-menu/primaria-nav-tree-menu.ts +0 -41
  60. package/src/UI/shared-components/primaria-nav-tree-menu/styles.css +0 -11
  61. package/src/UI/shared-components/primaria-nav-tree-menu/template.ts +0 -46
  62. package/src/UI/shared-components/primaria-region/index.ts +0 -1
  63. package/src/UI/shared-components/primaria-region/primaria-region.ts +0 -199
  64. package/src/UI/shared-components/primaria-text-editor/primaria-rich-text-editor.ts +0 -261
  65. package/src/UI/shared-components/primaria-text-editor/styles.css +0 -966
  66. package/src/UI/shared-components/primaria-text-editor/template.ts +0 -8
  67. package/src/UI/shared-components/primaria-text-editor/utils.ts +0 -39
  68. package/src/UI/shared-components/quick-action-item/quick-action-item.ts +0 -21
  69. package/src/UI/shared-components/quick-action-item/template.ts +0 -8
  70. package/src/UI/shared-components/typings.ts +0 -19
  71. package/src/api/activity-monitor/activity-monitor.test.ts +0 -67
  72. package/src/api/activity-monitor/activity-monitor.ts +0 -26
  73. package/src/api/api.test.ts +0 -37
  74. package/src/api/api.ts +0 -119
  75. package/src/api/broker/broker-events.ts +0 -39
  76. package/src/api/broker/broker-requests.ts +0 -20
  77. package/src/api/broker/factory.test.ts +0 -378
  78. package/src/api/broker/factory.ts +0 -151
  79. package/src/api/broker/primaria-broker.ts +0 -20
  80. package/src/api/context-manager/context-manager.test.ts +0 -86
  81. package/src/api/context-manager/context-manager.ts +0 -42
  82. package/src/api/ecap-event-manager/ecap-event-manager.test.ts +0 -100
  83. package/src/api/ecap-event-manager/ecap-event-manager.ts +0 -58
  84. package/src/api/ecap-event-manager/typings.ts +0 -6
  85. package/src/api/exit-guard-manager/exit-guard-manager.test.ts +0 -75
  86. package/src/api/exit-guard-manager/exit-guard-manager.ts +0 -31
  87. package/src/api/global-state/global-state.test.ts +0 -45
  88. package/src/api/global-state/global-state.ts +0 -38
  89. package/src/api/http-client/http-client.test.ts +0 -196
  90. package/src/api/http-client/http-client.ts +0 -97
  91. package/src/api/import-data-manager/component/component.ts +0 -29
  92. package/src/api/import-data-manager/component/styles.css +0 -79
  93. package/src/api/import-data-manager/component/template.ts +0 -49
  94. package/src/api/import-data-manager/import-data-manager-impl.test.ts +0 -364
  95. package/src/api/import-data-manager/import-data-manager-impl.ts +0 -121
  96. package/src/api/import-data-manager/import-data-manager.ts +0 -42
  97. package/src/api/import-data-manager/index.ts +0 -2
  98. package/src/api/interaction-service/confirmation-message.tsx +0 -5
  99. package/src/api/interaction-service/index.ts +0 -1
  100. package/src/api/interaction-service/interaction-service-impl.tsx +0 -260
  101. package/src/api/interaction-service/interaction-service.ts +0 -52
  102. package/src/api/interaction-service/modal-styles.css +0 -97
  103. package/src/api/localization/localization.test.ts +0 -61
  104. package/src/api/localization/localization.ts +0 -58
  105. package/src/api/notification-service/notification-service-impl.test.ts +0 -84
  106. package/src/api/notification-service/notification-service.ts +0 -6
  107. package/src/api/notification-service/notification.service-impl.ts +0 -67
  108. package/src/api/pdf-viewer-manager/constants.ts +0 -1
  109. package/src/api/pdf-viewer-manager/events.ts +0 -5
  110. package/src/api/pdf-viewer-manager/handle-views.ts +0 -32
  111. package/src/api/pdf-viewer-manager/pdf-viewer-manager.test.ts +0 -126
  112. package/src/api/pdf-viewer-manager/pdf-viewer-manager.ts +0 -96
  113. package/src/api/pdf-viewer-manager/pdf-visor/pdf-selector/pdf-selector.ts +0 -39
  114. package/src/api/pdf-viewer-manager/pdf-visor/pdf-selector/styles.css +0 -45
  115. package/src/api/pdf-viewer-manager/pdf-visor/pdf-selector/template.ts +0 -32
  116. package/src/api/pdf-viewer-manager/pdf-visor/pdf-visor.ts +0 -122
  117. package/src/api/pdf-viewer-manager/pdf-visor/styles.css +0 -29
  118. package/src/api/pdf-viewer-manager/pdf-visor/utils.ts +0 -16
  119. package/src/api/quick-action-busy-manager/quick-action-busy-manager.test.ts +0 -61
  120. package/src/api/quick-action-busy-manager/quick-action-busy-manager.ts +0 -45
  121. package/src/api/region-manager/region-manager.test.ts +0 -239
  122. package/src/api/region-manager/region-manager.ts +0 -263
  123. package/src/api/region-manager/regions.ts +0 -30
  124. package/src/api/region-manager/remove-view-idempotency.test.ts +0 -98
  125. package/src/api/session-refresh-timer/session-refresh-timer.test.ts +0 -102
  126. package/src/api/session-refresh-timer/session-refresh-timer.ts +0 -75
  127. package/src/api/token-manager/token-manager.test.ts +0 -146
  128. package/src/api/token-manager/token-manager.ts +0 -70
  129. package/src/api/user-manager/user-manager.ts +0 -79
  130. package/src/bootstrapper.ts +0 -41
  131. package/src/constants.ts +0 -1
  132. package/src/disposer.ts +0 -19
  133. package/src/features/bootstrapper.ts +0 -21
  134. package/src/features/exit/bootstrapper.ts +0 -17
  135. package/src/features/exit/handler.test.ts +0 -187
  136. package/src/features/exit/handler.ts +0 -58
  137. package/src/features/exit/request.ts +0 -10
  138. package/src/features/get-patient-cip/action.ts +0 -5
  139. package/src/features/get-user-info/backend-adapter.ts +0 -48
  140. package/src/features/get-user-info/bootstrapper.ts +0 -20
  141. package/src/features/get-user-info/handler.test.ts +0 -66
  142. package/src/features/get-user-info/handler.ts +0 -23
  143. package/src/features/get-user-info/model.ts +0 -10
  144. package/src/features/get-user-info/pds-token.ts +0 -28
  145. package/src/features/get-user-info/request.ts +0 -4
  146. package/src/features/get-visi-id/action.ts +0 -11
  147. package/src/features/navigate-to-ecap/navigate-to-ecap.ts +0 -21
  148. package/src/features/utils.ts +0 -27
  149. package/src/handle-plugins.ts +0 -82
  150. package/src/index.ts +0 -101
  151. package/src/infrastructure/ioc/container.ts +0 -14
  152. package/src/infrastructure/ioc/types.ts +0 -5
  153. package/src/locales.ts +0 -70
  154. package/src/types/custom.d.ts +0 -30
@@ -1,102 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
- import { SessionRefreshTimerImpl } from "./session-refresh-timer";
3
-
4
- const createJwt = (exp: number): string => {
5
- const payload = btoa(JSON.stringify({ exp }))
6
- .replace(/=/g, "")
7
- .replace(/\+/g, "-")
8
- .replace(/\//g, "_");
9
- return `header.${payload}.sig`;
10
- };
11
-
12
- const createMockTokenManager = (overrides: Record<string, any> = {}) => ({
13
- getToken: vi.fn().mockReturnValue(createJwt(Math.floor(Date.now() / 1000) + 3600)),
14
- setInitialTokens: vi.fn(),
15
- refreshToken: vi.fn().mockResolvedValue("new_token"),
16
- ...overrides,
17
- });
18
-
19
- const createMockActivityMonitor = (lastActivity = Date.now()) => ({
20
- start: vi.fn(),
21
- stop: vi.fn(),
22
- getLastActivityTimestamp: vi.fn().mockReturnValue(lastActivity),
23
- });
24
-
25
- describe("SessionRefreshTimer", () => {
26
- beforeEach(() => {
27
- vi.useFakeTimers();
28
- });
29
-
30
- afterEach(() => {
31
- vi.useRealTimers();
32
- vi.clearAllMocks();
33
- });
34
-
35
- it("should skip tick when there is no recent activity", async () => {
36
- const tokenManager = createMockTokenManager({
37
- getToken: vi.fn().mockReturnValue(createJwt(Math.floor(Date.now() / 1000) + 60)),
38
- });
39
- const timer = new SessionRefreshTimerImpl(tokenManager, createMockActivityMonitor(0));
40
-
41
- timer.start();
42
- await vi.advanceTimersByTimeAsync(30_000);
43
-
44
- expect(tokenManager.refreshToken).not.toHaveBeenCalled();
45
- });
46
-
47
- it("should skip tick when token is not near expiry", async () => {
48
- const tokenManager = createMockTokenManager({
49
- getToken: vi.fn().mockReturnValue(createJwt(Math.floor(Date.now() / 1000) + 3600)),
50
- });
51
- const timer = new SessionRefreshTimerImpl(tokenManager, createMockActivityMonitor());
52
-
53
- timer.start();
54
- await vi.advanceTimersByTimeAsync(30_000);
55
-
56
- expect(tokenManager.refreshToken).not.toHaveBeenCalled();
57
- });
58
-
59
- it("should refresh when token is near expiry and user is active", async () => {
60
- const tokenManager = createMockTokenManager({
61
- getToken: vi.fn().mockReturnValue(createJwt(Math.floor(Date.now() / 1000) + 60)),
62
- });
63
- const timer = new SessionRefreshTimerImpl(tokenManager, createMockActivityMonitor());
64
-
65
- timer.start();
66
- await vi.advanceTimersByTimeAsync(30_000);
67
-
68
- expect(tokenManager.refreshToken).toHaveBeenCalledTimes(1);
69
- });
70
-
71
- it("should refresh when token is already expired and user is active", async () => {
72
- const tokenManager = createMockTokenManager({
73
- getToken: vi.fn().mockReturnValue(createJwt(Math.floor(Date.now() / 1000) - 60)),
74
- });
75
- const timer = new SessionRefreshTimerImpl(tokenManager, createMockActivityMonitor());
76
-
77
- timer.start();
78
- await vi.advanceTimersByTimeAsync(30_000);
79
-
80
- expect(tokenManager.refreshToken).toHaveBeenCalledTimes(1);
81
- });
82
-
83
- it("should not trigger concurrent refreshes", async () => {
84
- let resolveRefresh!: () => void;
85
- const tokenManager = createMockTokenManager({
86
- getToken: vi.fn().mockReturnValue(createJwt(Math.floor(Date.now() / 1000) + 60)),
87
- refreshToken: vi.fn().mockImplementation(
88
- () => new Promise((resolve) => { resolveRefresh = () => resolve("new_token"); }),
89
- ),
90
- });
91
- const timer = new SessionRefreshTimerImpl(tokenManager, createMockActivityMonitor());
92
-
93
- timer.start();
94
- await vi.advanceTimersByTimeAsync(30_000);
95
- await vi.advanceTimersByTimeAsync(30_000);
96
-
97
- resolveRefresh();
98
- await Promise.resolve();
99
-
100
- expect(tokenManager.refreshToken).toHaveBeenCalledTimes(1);
101
- });
102
- });
@@ -1,75 +0,0 @@
1
- import { jwtDecode } from "jwt-decode";
2
- import { ActivityMonitor } from "../activity-monitor/activity-monitor";
3
- import { TokenManager } from "../token-manager/token-manager";
4
-
5
- const CHECK_INTERVAL_MS = 30_000;
6
- const REFRESH_THRESHOLD_S = 120;
7
- const ACTIVITY_WINDOW_MS = 15 * 60 * 1000;
8
-
9
- export interface SessionRefreshTimer {
10
- start: () => void;
11
- stop: () => void;
12
- }
13
-
14
- export class SessionRefreshTimerImpl implements SessionRefreshTimer {
15
- private intervalId: ReturnType<typeof setInterval> | null = null;
16
- private isRefreshing = false;
17
-
18
- constructor(
19
- private readonly tokenManager: TokenManager,
20
- private readonly activityMonitor: ActivityMonitor,
21
- ) {}
22
-
23
- start = () => {
24
- this.intervalId = setInterval(this.checkAndRefresh, CHECK_INTERVAL_MS);
25
- };
26
-
27
- stop = () => {
28
- if (this.intervalId !== null) {
29
- clearInterval(this.intervalId);
30
- this.intervalId = null;
31
- }
32
- };
33
-
34
- private getTokenExpiry = (): number => {
35
- try {
36
- const { exp } = jwtDecode(this.tokenManager.getToken()) as { exp?: number };
37
- return exp ?? 0;
38
- } catch {
39
- return 0;
40
- }
41
- };
42
-
43
- private checkAndRefresh = async () => {
44
- const now = Date.now();
45
-
46
- // Skip if the user hasn't interacted in the last ACTIVITY_WINDOW_MS.
47
- // Avoids keeping sessions alive for unattended tabs.
48
- if (now - this.activityMonitor.getLastActivityTimestamp() > ACTIVITY_WINDOW_MS) return;
49
-
50
- // Skip if a refresh is already in flight (this interval can fire again before the previous awaits).
51
- if (this.isRefreshing) return;
52
-
53
- const exp = this.getTokenExpiry();
54
-
55
- // Skip if the token can't be decoded (e.g. not yet initialized).
56
- if (exp === 0) return;
57
-
58
- // exp is in seconds, now is in milliseconds — compare in the same unit.
59
- if (exp - now / 1000 <= REFRESH_THRESHOLD_S) {
60
- this.isRefreshing = true;
61
- try {
62
- await this.tokenManager.refreshToken();
63
- } catch {
64
- // tokenManager.refreshToken() publishes refreshTokenFailed via broker on failure
65
- } finally {
66
- this.isRefreshing = false;
67
- }
68
- }
69
- };
70
- }
71
-
72
- export const createSessionRefreshTimer = (
73
- tokenManager: TokenManager,
74
- activityMonitor: ActivityMonitor,
75
- ): SessionRefreshTimer => new SessionRefreshTimerImpl(tokenManager, activityMonitor);
@@ -1,146 +0,0 @@
1
- // @vitest-environment happy-dom
2
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
- import axios from "axios";
4
- import { BROKER_EVENTS } from "../broker/broker-events";
5
-
6
- vi.mock("axios");
7
-
8
- const access_token = "test_access_token";
9
- const refresh_token = "test_refresh_token";
10
- const new_access_token = "new_access_token";
11
- const new_refresh_token = "new_refresh_token";
12
-
13
- const createMockBroker = () => ({
14
- publish: vi.fn().mockResolvedValue(undefined),
15
- subscribe: vi.fn(),
16
- send: vi.fn(),
17
- registerRequest: vi.fn(),
18
- events: BROKER_EVENTS,
19
- });
20
-
21
- describe("TokenManager", () => {
22
- let mockLocation: Partial<Location>;
23
- let TokenManagerImpl: any;
24
- let createTokenManager: any;
25
- let mockBroker: ReturnType<typeof createMockBroker>;
26
-
27
- beforeEach(async () => {
28
- vi.resetModules();
29
- mockLocation = {
30
- search: `?access_token=${access_token}&refresh_token=${refresh_token}`,
31
- };
32
- vi.spyOn(window, "location", "get").mockReturnValue(mockLocation as Location);
33
- mockBroker = createMockBroker();
34
-
35
- const module = await import("./token-manager");
36
- TokenManagerImpl = module.TokenManagerImpl;
37
- createTokenManager = module.createTokenManager;
38
- });
39
-
40
- afterEach(() => {
41
- vi.clearAllMocks();
42
- });
43
-
44
- describe("getToken", () => {
45
- it("should initialize token from URL params on first call", () => {
46
- const tokenManager = new TokenManagerImpl(mockBroker);
47
- expect(tokenManager.getToken()).toBe(access_token);
48
- });
49
-
50
- it("should return empty string if URL params are missing", () => {
51
- mockLocation.search = "";
52
- const tokenManager = new TokenManagerImpl(mockBroker);
53
- expect(tokenManager.getToken()).toBe("");
54
- });
55
-
56
- it("should return the same token on subsequent calls", () => {
57
- const tokenManager = new TokenManagerImpl(mockBroker);
58
- expect(tokenManager.getToken()).toBe(tokenManager.getToken());
59
- });
60
- });
61
-
62
- describe("setInitialTokens", () => {
63
- it("should set tokens manually", () => {
64
- const tokenManager = new TokenManagerImpl(mockBroker);
65
- tokenManager.setInitialTokens("manual_access", "manual_refresh");
66
- expect(tokenManager.getToken()).toBe("manual_access");
67
- });
68
-
69
- it("should throw error if tokens are already initialized", () => {
70
- const tokenManager = new TokenManagerImpl(mockBroker);
71
- tokenManager.setInitialTokens("manual_access", "manual_refresh");
72
- expect(() => tokenManager.setInitialTokens("another_access", "another_refresh")).toThrow("Token already initialized");
73
- });
74
-
75
- it("should throw error if tokens were already initialized from URL", () => {
76
- const tokenManager = new TokenManagerImpl(mockBroker);
77
- tokenManager.getToken();
78
- expect(() => tokenManager.setInitialTokens("manual_access", "manual_refresh")).toThrow("Token already initialized");
79
- });
80
- });
81
-
82
- describe("refreshToken", () => {
83
- it("should refresh token successfully", async () => {
84
- vi.mocked(axios.post).mockResolvedValue({
85
- data: { access_token: new_access_token, refresh_token: new_refresh_token },
86
- });
87
-
88
- const tokenManager = new TokenManagerImpl(mockBroker);
89
- tokenManager.setInitialTokens(access_token, refresh_token);
90
-
91
- const refreshed = await tokenManager.refreshToken();
92
-
93
- expect(axios.post).toHaveBeenCalledWith("/api/token/refresh", { token: refresh_token });
94
- expect(refreshed).toBe(new_access_token);
95
- expect(tokenManager.getToken()).toBe(new_access_token);
96
- });
97
-
98
- it("should initialize tokens from URL before refreshing if not initialized", async () => {
99
- vi.mocked(axios.post).mockResolvedValue({
100
- data: { access_token: new_access_token, refresh_token: new_refresh_token },
101
- });
102
-
103
- const tokenManager = new TokenManagerImpl(mockBroker);
104
- await tokenManager.refreshToken();
105
-
106
- expect(axios.post).toHaveBeenCalledWith("/api/token/refresh", { token: refresh_token });
107
- });
108
-
109
- it("should throw error if refresh response doesn't contain access_token", async () => {
110
- vi.mocked(axios.post).mockResolvedValue({ data: {} });
111
-
112
- const tokenManager = new TokenManagerImpl(mockBroker);
113
- tokenManager.setInitialTokens(access_token, refresh_token);
114
-
115
- await expect(tokenManager.refreshToken()).rejects.toThrow("Invalid refresh token response");
116
- });
117
-
118
- it("should publish refreshTokenFailed and rethrow when refresh fails", async () => {
119
- vi.mocked(axios.post).mockRejectedValue(new Error("Network error"));
120
-
121
- const tokenManager = new TokenManagerImpl(mockBroker);
122
- tokenManager.setInitialTokens(access_token, refresh_token);
123
-
124
- await expect(tokenManager.refreshToken()).rejects.toThrow("Network error");
125
- expect(mockBroker.publish).toHaveBeenCalledWith(BROKER_EVENTS.shell.refreshTokenFailed, {});
126
- });
127
-
128
- it("should not publish refreshTokenFailed when refresh succeeds", async () => {
129
- vi.mocked(axios.post).mockResolvedValue({
130
- data: { access_token: new_access_token, refresh_token: new_refresh_token },
131
- });
132
-
133
- const tokenManager = new TokenManagerImpl(mockBroker);
134
- tokenManager.setInitialTokens(access_token, refresh_token);
135
-
136
- await tokenManager.refreshToken();
137
- expect(mockBroker.publish).not.toHaveBeenCalled();
138
- });
139
- });
140
-
141
- describe("createTokenManager", () => {
142
- it("should return a singleton instance", () => {
143
- expect(createTokenManager(mockBroker)).toBe(createTokenManager(mockBroker));
144
- });
145
- });
146
- });
@@ -1,70 +0,0 @@
1
- import axios from "axios";
2
- import { BROKER_EVENTS } from "../broker/broker-events";
3
- import { PrimariaBroker } from "../broker/primaria-broker";
4
-
5
- /**
6
- * API pública de tokens disponible per als plugins via `api.tokenManager`.
7
- * Els plugins poden llegir el token actual o forçar-ne el refresc; NO poden
8
- * fixar els tokens inicials: això ho fa el host amb `setInitialTokens`, que
9
- * s'exporta com a funció i només funciona una vegada.
10
- */
11
- export interface TokenManager {
12
- getToken: () => string;
13
- refreshToken: () => Promise<string>;
14
- }
15
-
16
- let token: string;
17
- let refreshToken: string;
18
- let tokenInitialized = false;
19
-
20
- export class TokenManagerImpl implements TokenManager {
21
- constructor(private readonly broker: PrimariaBroker) {}
22
-
23
- getUrlParams = (): URLSearchParams => {
24
- return new URLSearchParams(window.location.search);
25
- };
26
-
27
- private initToken = () => {
28
- if (tokenInitialized) throw new Error("Token already initialized");
29
- tokenInitialized = true;
30
- const searchString = this.getUrlParams();
31
- token = searchString.get("access_token") || "";
32
- refreshToken = searchString.get("refresh_token") || "";
33
- return token;
34
- };
35
-
36
- setInitialTokens = (access_token: string, refresh_token: string) => {
37
- if (tokenInitialized) throw new Error("Token already initialized");
38
- token = access_token;
39
- refreshToken = refresh_token;
40
- tokenInitialized = true;
41
- };
42
-
43
- getToken = () => {
44
- if (!tokenInitialized) this.initToken();
45
- return token;
46
- };
47
-
48
- refreshToken = async () => {
49
- if (!tokenInitialized) this.initToken();
50
- try {
51
- const response = await axios.post("/api/token/refresh", { token: refreshToken });
52
- const { access_token, refresh_token } = response.data;
53
- if (!access_token) throw new Error("Invalid refresh token response");
54
- token = access_token;
55
- refreshToken = refresh_token;
56
- return token;
57
- } catch (error) {
58
- this.broker.publish(BROKER_EVENTS.shell.refreshTokenFailed, {});
59
- throw error;
60
- }
61
- };
62
- }
63
-
64
- let tokenManager: TokenManagerImpl;
65
-
66
- export const createTokenManager = (broker: PrimariaBroker) => {
67
- if (tokenManager) return tokenManager;
68
- tokenManager = new TokenManagerImpl(broker);
69
- return tokenManager;
70
- };
@@ -1,79 +0,0 @@
1
- import { jwtDecode } from "jwt-decode";
2
- import { TokenManager } from "../token-manager/token-manager";
3
-
4
- interface Identifier {
5
- type: string;
6
- value: string;
7
- }
8
-
9
- interface JWTPayload {
10
- access_info?: {
11
- role_type?: string;
12
- trace_user_given_name?: string;
13
- trace_user_family_name?: string;
14
- module_code?: string;
15
- identifier?: Identifier[];
16
- };
17
- }
18
-
19
- export interface UserManager {
20
- getRole: () => string | undefined;
21
- isUserRoleAdministrative: () => boolean;
22
- getFullName: () => string | undefined;
23
- getSector: () => string | undefined;
24
- getDNI: () => string | undefined;
25
- }
26
-
27
- export class UserManagerImpl implements UserManager {
28
- constructor(private tokenManager: TokenManager) {}
29
-
30
- private getAccessInfo(): JWTPayload["access_info"] | undefined {
31
- const token = this.tokenManager.getToken();
32
- if (!token) return undefined;
33
- try {
34
- return jwtDecode<JWTPayload>(token).access_info;
35
- } catch (error) {
36
- console.error("Error decoding JWT token:", error);
37
- return undefined;
38
- }
39
- }
40
-
41
- getRole = (): string | undefined => {
42
- return this.getAccessInfo()?.role_type;
43
- };
44
-
45
- isUserRoleAdministrative = (): boolean => {
46
- return this.getRole() === "ADM";
47
- };
48
-
49
- getFullName = (): string | undefined => {
50
- const accessInfo = this.getAccessInfo();
51
- if (!accessInfo) return undefined;
52
-
53
- const givenName = accessInfo.trace_user_given_name;
54
- const familyName = accessInfo.trace_user_family_name;
55
-
56
- if (!givenName && !familyName) return undefined;
57
-
58
- return [familyName, givenName].filter(Boolean).join(" ");
59
- };
60
-
61
- getSector = (): string | undefined => {
62
- return this.getAccessInfo()?.module_code;
63
- };
64
-
65
- getDNI = (): string | undefined => {
66
- const identifiers = this.getAccessInfo()?.identifier;
67
- if (!identifiers) return undefined;
68
-
69
- const dniIdentifier = identifiers.find(id => id.type === "DNI");
70
- return dniIdentifier?.value;
71
- };
72
- }
73
-
74
- let userManager: UserManager;
75
- export const createUserManager = (tokenManager: TokenManager): UserManager => {
76
- if (userManager) return userManager;
77
- userManager = new UserManagerImpl(tokenManager);
78
- return userManager;
79
- };
@@ -1,41 +0,0 @@
1
- import { PrimariaShell } from "./UI/components/primaria-shell/primaria-shell";
2
- import { activityMonitor, sessionRefreshTimer, shellApi, shellInternals } from "./api/api";
3
- import { EcapContext } from "./api/context-manager/context-manager";
4
- import { useFeatures } from "./features/bootstrapper";
5
- import { useLocalization } from "./locales";
6
- import { useUI } from "./UI/bootstrapper";
7
-
8
- let shellInitialized = false;
9
-
10
- /**
11
- * Arrenca el shell. L'exporta el paquet perquè el host (`primary/app`, el sandbox) l'ha de cridar,
12
- * i per això també el pot importar un plugin: només funciona una vegada, abans de carregar cap
13
- * plugin, i no torna a funcionar fins que el shell s'ha desmuntat.
14
- */
15
- export const initializeShell = (hostAppElement: HTMLElement, ecapContext?: EcapContext) => {
16
- if (shellInitialized) throw new Error("Shell already initialized");
17
- shellInitialized = true;
18
- if (ecapContext) {
19
- shellInternals.initializeContext(ecapContext);
20
- }
21
-
22
- activityMonitor.start();
23
- sessionRefreshTimer.start();
24
- useLocalization(shellApi);
25
- useUI();
26
- useFeatures(shellApi);
27
- const shell = new PrimariaShell();
28
- hostAppElement.appendChild(shell as any);
29
- };
30
-
31
- /** Permet tornar a arrencar el shell un cop desmuntat. Només el crida `disposeShell`. */
32
- export const resetShellInitialization = () => {
33
- shellInitialized = false;
34
- };
35
-
36
- /**
37
- * Fixa els tokens inicials quan el host els rep d'ECAP en lloc de la URL. Només funciona una
38
- * vegada: a partir del primer token, llegit o fixat, llança `Token already initialized`.
39
- */
40
- export const setInitialTokens = (accessToken: string, refreshToken: string) =>
41
- shellInternals.setInitialTokens(accessToken, refreshToken);
package/src/constants.ts DELETED
@@ -1 +0,0 @@
1
- export const primariaShellId = "primaria-shell";
package/src/disposer.ts DELETED
@@ -1,19 +0,0 @@
1
- import { activityMonitor, sessionRefreshTimer, shellApi, shellInternals } from "./api/api";
2
- import { resetShellInitialization } from "./bootstrapper";
3
- import { disposeFeatures } from "./features/bootstrapper";
4
- import { ExitShellPayload } from "./features/exit/request";
5
- export const disposeShell = async () => {
6
- await disposeFeatures();
7
- shellInternals.closeAllDialogs();
8
- sessionRefreshTimer.stop();
9
- activityMonitor.stop();
10
- resetShellInitialization();
11
- };
12
-
13
- export const raiseCloseEvent = () => {
14
- shellApi.ecapEventManager.publish("CLOSE_FORM", "", {});
15
- };
16
-
17
- export const raiseCustomCloseEvent = (event: ExitShellPayload) => {
18
- shellApi.ecapEventManager.publish(event.ecapEvent as string, "", event.payload);
19
- };
@@ -1,21 +0,0 @@
1
- import { PrimariaApi, shellInternals } from "../api/api";
2
- import { container } from "../infrastructure/ioc/container";
3
- import { TYPES } from "../infrastructure/ioc/types";
4
- import { disposeExitShell, useExitShell } from "./exit/bootstrapper";
5
- import { disposeGetUserInfo, useGetUserInfo } from "./get-user-info/bootstrapper";
6
- import { GetUserInfo } from "./get-user-info/request";
7
-
8
- export const useFeatures = (api: PrimariaApi) => {
9
- container.bind(TYPES.primaryApi).toConstantValue(api);
10
- useGetUserInfo(api);
11
- useExitShell(api);
12
- api.broker.send(new GetUserInfo());
13
- };
14
-
15
- export const disposeFeatures = async () => {
16
- disposeGetUserInfo();
17
- disposeExitShell();
18
- container.unbindAll();
19
- await shellInternals.destroyRegions();
20
- shellInternals.clearBroker();
21
- };
@@ -1,17 +0,0 @@
1
- import { PrimariaApi } from "../../api/api";
2
- import { BrokerDisposableHandler } from "../../api/broker/primaria-broker";
3
- import { container } from "../../infrastructure/ioc/container";
4
- import { registerRequest } from "../utils";
5
- import { ExitShellHandler } from "./handler";
6
- import { ExitShell } from "./request";
7
-
8
- let request: BrokerDisposableHandler;
9
-
10
- export const useExitShell = (api: PrimariaApi) => {
11
- disposeExitShell();
12
- request = registerRequest(api, container)(ExitShell, ExitShellHandler);
13
- };
14
-
15
- export const disposeExitShell = () => {
16
- request?.dispose();
17
- };