@uxland/primary-shell 7.3.0 → 7.4.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.
- package/dist/index.js +29 -12
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +3 -3
- package/dist/index.umd.cjs.map +1 -1
- package/dist/primary/shell/src/UI/bootstrapper.d.ts +1 -1
- package/dist/primary/shell/src/UI/internal-views/handle-views.d.ts +1 -1
- package/dist/primary/shell/src/api/api.d.ts +2 -0
- package/dist/primary/shell/src/api/user-manager/user-manager.d.ts +12 -0
- package/dist/primary/shell/src/bootstrapper.d.ts +1 -1
- package/dist/primary/shell/src/handle-plugins.d.ts +1 -1
- package/package.json +1 -1
- package/src/UI/bootstrapper.ts +2 -2
- package/src/UI/internal-views/handle-views.ts +4 -3
- package/src/api/api.ts +4 -0
- package/src/api/user-manager/user-manager.ts +45 -0
- package/src/bootstrapper.ts +2 -2
- package/src/handle-plugins.ts +6 -6
- package/dist/primary/shell/src/domain/is-user-role-administrative.d.ts +0 -1
- package/src/domain/is-user-role-administrative.ts +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useUI: (
|
|
1
|
+
export declare const useUI: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useInternalViews: (
|
|
1
|
+
export declare const useInternalViews: () => void;
|
|
@@ -9,6 +9,7 @@ import { PdfViewerManager } from './pdf-viewer-manager/pdf-viewer-manager';
|
|
|
9
9
|
import { PluginBusyManager } from './plugin-busy-manager/plugin-busy-manager';
|
|
10
10
|
import { PrimariaRegionManager } from './region-manager/region-manager';
|
|
11
11
|
import { TokenManager } from './token-manager/token-manager';
|
|
12
|
+
import { UserManager } from './user-manager/user-manager';
|
|
12
13
|
export interface PrimariaApi extends HarmonixApi {
|
|
13
14
|
httpClient: HttpClient;
|
|
14
15
|
interactionService: PrimariaInteractionService;
|
|
@@ -17,6 +18,7 @@ export interface PrimariaApi extends HarmonixApi {
|
|
|
17
18
|
regionManager: PrimariaRegionManager;
|
|
18
19
|
globalStateManager: PrimariaGlobalStateManager;
|
|
19
20
|
tokenManager: TokenManager;
|
|
21
|
+
userManager: UserManager;
|
|
20
22
|
ecapEventManager: EcapEventManager;
|
|
21
23
|
pluginBusyManager: PluginBusyManager;
|
|
22
24
|
pdfViewerManager: PdfViewerManager;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TokenManager } from '../token-manager/token-manager';
|
|
2
|
+
export interface UserManager {
|
|
3
|
+
getRole: () => string | undefined;
|
|
4
|
+
isUserRoleAdministrative: () => boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare class UserManagerImpl implements UserManager {
|
|
7
|
+
private tokenManager;
|
|
8
|
+
constructor(tokenManager: TokenManager);
|
|
9
|
+
getRole: () => string | undefined;
|
|
10
|
+
isUserRoleAdministrative: () => boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const createUserManager: (tokenManager: TokenManager) => UserManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const initializeShell: (hostAppElement: HTMLElement
|
|
1
|
+
export declare const initializeShell: (hostAppElement: HTMLElement) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PluginDefinition, Plugin as PluginType } from '@uxland/harmonix';
|
|
2
2
|
import { PrimariaApi } from './api/api';
|
|
3
3
|
export type { PluginDefinition, PluginInfo } from '@uxland/harmonix';
|
|
4
|
-
export declare const bootstrapPlugins: (plugins: PluginDefinition[]
|
|
4
|
+
export declare const bootstrapPlugins: (plugins: PluginDefinition[]) => Promise<void>;
|
|
5
5
|
export declare const disposePlugins: () => Promise<void[]>;
|
|
6
6
|
export type Plugin = PluginType<PrimariaApi>;
|
package/package.json
CHANGED
package/src/UI/bootstrapper.ts
CHANGED
|
@@ -3,12 +3,12 @@ import { useComponents } from "./components/bootstrapper";
|
|
|
3
3
|
import { useSharedUI } from "./shared-components/bootstrapper";
|
|
4
4
|
import { useInternalViews } from "./internal-views/handle-views";
|
|
5
5
|
|
|
6
|
-
export const useUI = (
|
|
6
|
+
export const useUI = () => {
|
|
7
7
|
regionAdapterRegistry.registerAdapterFactory(
|
|
8
8
|
"primaria-content-switcher",
|
|
9
9
|
selectableAdapterFactory,
|
|
10
10
|
);
|
|
11
11
|
useSharedUI();
|
|
12
12
|
useComponents();
|
|
13
|
-
useInternalViews(
|
|
13
|
+
useInternalViews();
|
|
14
14
|
};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { shellApi } from "../../api/api";
|
|
1
2
|
import { registerPDFVisorMainView } from "../../api/pdf-viewer-manager/handle-views";
|
|
2
|
-
import { isUserRoleAdministrative } from "../../domain/is-user-role-administrative";
|
|
3
3
|
import { registerAdministrativeNavMenuViews, registerDoctorNavMenuViews } from "./upper-nav-views";
|
|
4
4
|
|
|
5
5
|
const registerMainViews = () => {
|
|
6
6
|
registerPDFVisorMainView();
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
export const useInternalViews = (
|
|
9
|
+
export const useInternalViews = () => {
|
|
10
10
|
registerMainViews();
|
|
11
|
-
|
|
11
|
+
const isUserRoleAdministrative = shellApi.userManager.isUserRoleAdministrative();
|
|
12
|
+
if((isUserRoleAdministrative))
|
|
12
13
|
registerAdministrativeNavMenuViews();
|
|
13
14
|
else
|
|
14
15
|
registerDoctorNavMenuViews();
|
package/src/api/api.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
} from "./plugin-busy-manager/plugin-busy-manager";
|
|
25
25
|
import { PrimariaRegionManager, createRegionManagerProxy } from "./region-manager/region-manager";
|
|
26
26
|
import { TokenManager, createTokenManager } from "./token-manager/token-manager";
|
|
27
|
+
import { UserManager, createUserManager } from "./user-manager/user-manager";
|
|
27
28
|
|
|
28
29
|
const broker = createBroker();
|
|
29
30
|
|
|
@@ -35,6 +36,7 @@ export interface PrimariaApi extends HarmonixApi {
|
|
|
35
36
|
regionManager: PrimariaRegionManager;
|
|
36
37
|
globalStateManager: PrimariaGlobalStateManager;
|
|
37
38
|
tokenManager: TokenManager;
|
|
39
|
+
userManager: UserManager;
|
|
38
40
|
ecapEventManager: EcapEventManager;
|
|
39
41
|
pluginBusyManager: PluginBusyManager;
|
|
40
42
|
pdfViewerManager: PdfViewerManager;
|
|
@@ -43,6 +45,7 @@ export interface PrimariaApi extends HarmonixApi {
|
|
|
43
45
|
const regionManager: RegionManager = createRegionManager("primaria");
|
|
44
46
|
export const PrimariaRegionHost: any = createRegionHost(regionManager as any);
|
|
45
47
|
const tokenManager = createTokenManager();
|
|
48
|
+
const userManager = createUserManager(tokenManager);
|
|
46
49
|
const globalStateManager: PrimariaGlobalStateManager = createGlobalStateManager(broker);
|
|
47
50
|
const pluginBusyManager = new PluginBusyManagerImpl(broker);
|
|
48
51
|
const interactionService = new ParimariaInteractionServiceImpl();
|
|
@@ -69,6 +72,7 @@ export const primariaApiFactory: ApiFactory<PrimariaApi> = (
|
|
|
69
72
|
createLocaleManager: createLocaleManager(pluginInfo.pluginId) as any,
|
|
70
73
|
globalStateManager,
|
|
71
74
|
tokenManager,
|
|
75
|
+
userManager,
|
|
72
76
|
ecapEventManager,
|
|
73
77
|
pluginBusyManager,
|
|
74
78
|
interactionService,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jwtDecode } from "jwt-decode";
|
|
2
|
+
import { TokenManager } from "../token-manager/token-manager";
|
|
3
|
+
|
|
4
|
+
interface JWTPayload {
|
|
5
|
+
access_info?: {
|
|
6
|
+
role_type?: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface UserManager {
|
|
11
|
+
getRole: () => string | undefined;
|
|
12
|
+
isUserRoleAdministrative: () => boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class UserManagerImpl implements UserManager {
|
|
16
|
+
constructor(private tokenManager: TokenManager) {}
|
|
17
|
+
|
|
18
|
+
getRole = (): string | undefined => {
|
|
19
|
+
const token = this.tokenManager.getToken();
|
|
20
|
+
if (!token) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const payload = jwtDecode<JWTPayload>(token);
|
|
26
|
+
const role = payload.access_info?.role_type;
|
|
27
|
+
return role;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error("Error decoding JWT token:", error);
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
isUserRoleAdministrative = (): boolean => {
|
|
35
|
+
const userRole = this.getRole();
|
|
36
|
+
return userRole === "ADM";
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let userManager: UserManager;
|
|
41
|
+
export const createUserManager = (tokenManager: TokenManager): UserManager => {
|
|
42
|
+
if (userManager) return userManager;
|
|
43
|
+
userManager = new UserManagerImpl(tokenManager);
|
|
44
|
+
return userManager;
|
|
45
|
+
};
|
package/src/bootstrapper.ts
CHANGED
|
@@ -4,9 +4,9 @@ import { useFeatures } from "./features/bootstrapper";
|
|
|
4
4
|
import { useLocalization } from "./locales";
|
|
5
5
|
import { useUI } from "./UI/bootstrapper";
|
|
6
6
|
|
|
7
|
-
export const initializeShell = (hostAppElement: HTMLElement
|
|
7
|
+
export const initializeShell = (hostAppElement: HTMLElement) => {
|
|
8
8
|
useLocalization(shellApi);
|
|
9
|
-
useUI(
|
|
9
|
+
useUI();
|
|
10
10
|
useFeatures(shellApi);
|
|
11
11
|
const shell = new PrimariaShell();
|
|
12
12
|
hostAppElement.appendChild(shell as any);
|
package/src/handle-plugins.ts
CHANGED
|
@@ -13,8 +13,7 @@ import {
|
|
|
13
13
|
initialize as adminClinicalMonitoringInitialize,
|
|
14
14
|
dispose as adminClinicalMonitoringDispose,
|
|
15
15
|
} from "../../../plugins/admin-clinical-monitoring/src/plugin";
|
|
16
|
-
import { PrimariaApi, primariaApiFactory } from "./api/api";
|
|
17
|
-
import { isUserRoleAdministrative } from "./domain/is-user-role-administrative";
|
|
16
|
+
import { PrimariaApi, primariaApiFactory, shellApi } from "./api/api";
|
|
18
17
|
|
|
19
18
|
let bootstrappedPlugins = [] as BootstrappedPlugin[];
|
|
20
19
|
|
|
@@ -51,15 +50,16 @@ const administrativeInternalPlugins: PluginDefinition[] = [
|
|
|
51
50
|
},
|
|
52
51
|
];
|
|
53
52
|
|
|
54
|
-
const getPluginsByUserRole = (
|
|
55
|
-
if (isUserRoleAdministrative
|
|
53
|
+
const getPluginsByUserRole = (isUserRoleAdministrative: boolean) => {
|
|
54
|
+
if (isUserRoleAdministrative) {
|
|
56
55
|
return commonPlugins.concat(administrativeInternalPlugins);
|
|
57
56
|
}
|
|
58
57
|
return commonPlugins.concat(doctorInternalPlugins);
|
|
59
58
|
};
|
|
60
59
|
|
|
61
|
-
export const bootstrapPlugins = async (plugins: PluginDefinition[]
|
|
62
|
-
const
|
|
60
|
+
export const bootstrapPlugins = async (plugins: PluginDefinition[]) => {
|
|
61
|
+
const isUserRoleAdministrative = shellApi.userManager.isUserRoleAdministrative();
|
|
62
|
+
const internalPlugins = getPluginsByUserRole(isUserRoleAdministrative);
|
|
63
63
|
const finalPlugins = internalPlugins.concat(plugins || []);
|
|
64
64
|
bootstrappedPlugins = await pluginBootstrapper(finalPlugins, primariaApiFactory);
|
|
65
65
|
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isUserRoleAdministrative: (userRole?: string) => userRole is "ADM";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const isUserRoleAdministrative = (userRole?: string) => userRole === "ADM";
|