@equinor/amplify-component-lib 13.1.3 → 13.2.1
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/atoms/style/colors.d.ts +33 -3
- package/dist/atoms/style/colors.js +1 -1
- package/dist/atoms/style/darkTokens.js +16 -1
- package/dist/atoms/style/lightTokens.js +16 -1
- package/dist/deprecated/ExpandingIconButton/ExpandingIconButton.d.ts +2 -2
- package/dist/deprecated/IconToggleButton.d.ts +2 -2
- package/dist/molecules/Tag/Tag.js +1 -0
- package/dist/providers/AuthProvider/AuthProviderInner.js +1 -1
- package/package.json +1 -1
|
@@ -10,6 +10,9 @@ declare const colors: {
|
|
|
10
10
|
readonly background__tutorial_card: {
|
|
11
11
|
readonly rgba: "var(--amplify_ui_background_tutorial_card, rgba(222, 237, 238, 1))";
|
|
12
12
|
};
|
|
13
|
+
readonly background__success: {
|
|
14
|
+
readonly rgba: "var(--amplify_ui_background_success, rgba(230, 250, 236, 1))";
|
|
15
|
+
};
|
|
13
16
|
readonly background__default: {
|
|
14
17
|
hex: string;
|
|
15
18
|
hsla: string;
|
|
@@ -60,15 +63,42 @@ declare const colors: {
|
|
|
60
63
|
readonly primary__pressed: {
|
|
61
64
|
readonly rgba: "var(--amplify_interactive_primary_pressed, rgba(19, 46, 49, 1))";
|
|
62
65
|
};
|
|
66
|
+
readonly primary__nested_hover: {
|
|
67
|
+
readonly rgba: "var(--amplify_interactive_primary__nested_hover, rgba(187, 219, 223, 1))";
|
|
68
|
+
};
|
|
69
|
+
readonly danger__text_hover: {
|
|
70
|
+
readonly rgba: "var(--amplify_interactive_danger__text_hover, rgba(154, 16, 38, 1))";
|
|
71
|
+
};
|
|
72
|
+
readonly danger__nested_hover: {
|
|
73
|
+
readonly rgba: "var(--amplify_interactive_danger__nested_hover, rgba(255, 208, 206, 1))";
|
|
74
|
+
};
|
|
75
|
+
readonly warning__text_hover: {
|
|
76
|
+
readonly rgba: "var(--amplify_interactive_warning__text_hover, rgba(155, 73, 0, 1))";
|
|
77
|
+
};
|
|
78
|
+
readonly warning__nested_hover: {
|
|
79
|
+
readonly rgba: "var(--amplify_interactive_warning__nested_hover, rgba(246, 202, 170, 1))";
|
|
80
|
+
};
|
|
81
|
+
readonly success__text_hover: {
|
|
82
|
+
readonly rgba: "var(--amplify_interactive_success__text_hover, rgba(32, 105, 31, 1))";
|
|
83
|
+
};
|
|
84
|
+
readonly success__nested_hover: {
|
|
85
|
+
readonly rgba: "var(--amplify_interactive_success__nested_hover, rgba(195, 243, 210, 1))";
|
|
86
|
+
};
|
|
87
|
+
readonly info__text: {
|
|
88
|
+
readonly rgba: "var(--amplify_interactive_info__text, rgba(0, 112, 169, 1))";
|
|
89
|
+
};
|
|
90
|
+
readonly info__text_hover: {
|
|
91
|
+
readonly rgba: "var(--amplify_interactive_info__text_hover, rgba(8, 88, 131, 1))";
|
|
92
|
+
};
|
|
93
|
+
readonly info__nested_hover: {
|
|
94
|
+
readonly rgba: "var(--amplify_interactive_info__nested_hover, rgba(181, 218, 245, 1))";
|
|
95
|
+
};
|
|
63
96
|
readonly tutorial__active_step: {
|
|
64
97
|
readonly rgba: "var(--amplify_interactive_tutorial_active_step, rgba(0, 112, 121, 1))";
|
|
65
98
|
};
|
|
66
99
|
readonly tutorial__inactive_step: {
|
|
67
100
|
readonly rgba: "var(--amplify_interactive_tutorial_inactive_step, rgba(168, 206, 209, 1))";
|
|
68
101
|
};
|
|
69
|
-
readonly inner_hover: {
|
|
70
|
-
readonly rgba: "var(--amplify_interactive_inner_hover, rgba(198, 223, 225, 1))";
|
|
71
|
-
};
|
|
72
102
|
readonly primary__selected_highlight: {
|
|
73
103
|
hex: string;
|
|
74
104
|
hsla: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{tokens as e}from"../../node_modules/@equinor/eds-tokens/dist/esm/base/index.js";const{colors:t}=e,n={...t,ui:{...t.ui,background__light_medium:{rgba:`var(--amplify_ui_background_light_medium, rgba(235, 235, 235, 1))`},background__heavy:{rgba:`var(--amplify_ui_background_heavy, rgba(189, 189, 189, 1))`},background__tutorial_card:{rgba:`var(--amplify_ui_background_tutorial_card, rgba(222, 237, 238, 1))`}},interactive:{...t.interactive,primary__pressed:{rgba:`var(--amplify_interactive_primary_pressed, rgba(19, 46, 49, 1))`},
|
|
1
|
+
import{tokens as e}from"../../node_modules/@equinor/eds-tokens/dist/esm/base/index.js";const{colors:t}=e,n={...t,ui:{...t.ui,background__light_medium:{rgba:`var(--amplify_ui_background_light_medium, rgba(235, 235, 235, 1))`},background__heavy:{rgba:`var(--amplify_ui_background_heavy, rgba(189, 189, 189, 1))`},background__tutorial_card:{rgba:`var(--amplify_ui_background_tutorial_card, rgba(222, 237, 238, 1))`},background__success:{rgba:`var(--amplify_ui_background_success, rgba(230, 250, 236, 1))`}},interactive:{...t.interactive,primary__pressed:{rgba:`var(--amplify_interactive_primary_pressed, rgba(19, 46, 49, 1))`},primary__nested_hover:{rgba:`var(--amplify_interactive_primary__nested_hover, rgba(187, 219, 223, 1))`},danger__text_hover:{rgba:`var(--amplify_interactive_danger__text_hover, rgba(154, 16, 38, 1))`},danger__nested_hover:{rgba:`var(--amplify_interactive_danger__nested_hover, rgba(255, 208, 206, 1))`},warning__text_hover:{rgba:`var(--amplify_interactive_warning__text_hover, rgba(155, 73, 0, 1))`},warning__nested_hover:{rgba:`var(--amplify_interactive_warning__nested_hover, rgba(246, 202, 170, 1))`},success__text_hover:{rgba:`var(--amplify_interactive_success__text_hover, rgba(32, 105, 31, 1))`},success__nested_hover:{rgba:`var(--amplify_interactive_success__nested_hover, rgba(195, 243, 210, 1))`},info__text:{rgba:`var(--amplify_interactive_info__text, rgba(0, 112, 169, 1))`},info__text_hover:{rgba:`var(--amplify_interactive_info__text_hover, rgba(8, 88, 131, 1))`},info__nested_hover:{rgba:`var(--amplify_interactive_info__nested_hover, rgba(181, 218, 245, 1))`},tutorial__active_step:{rgba:`var(--amplify_interactive_tutorial_active_step, rgba(0, 112, 121, 1))`},tutorial__inactive_step:{rgba:`var(--amplify_interactive_tutorial_inactive_step, rgba(168, 206, 209, 1))`}},dataviz:{primary:{lighter:`var(--amplify_dataviz_primary_lighter, rgba(206, 229, 255, 1))`,muted:`var(--amplify_dataviz_primary_muted, rgba(74, 149, 236, 1))`,default:`var(--amplify_dataviz_primary_default, rgba(0, 107, 229, 1))`,darker:`var(--amplify_dataviz_primary_darker, rgba(0, 83, 178, 1))`,primary10:`var(--amplify_dataviz_primary_10, rgba(235, 245, 255, 1))`,primary20:`var(--amplify_dataviz_primary_20, rgba(211, 231, 253, 1))`,primary30:`var(--amplify_dataviz_primary_30, rgba(167, 206, 251, 1))`,primary40:`var(--amplify_dataviz_primary_40, rgba(133, 187, 250, 1))`,primary50:`var(--amplify_dataviz_primary_50, rgba(89, 163, 248, 1))`,primary60:`var(--amplify_dataviz_primary_60, rgba(40, 136, 246, 1))`,primary70:`var(--amplify_dataviz_primary_70, rgba(10, 115, 235, 1))`,primary80:`var(--amplify_dataviz_primary_80, rgba(8, 91, 186, 1))`,primary90:`var(--amplify_dataviz_primary_90, rgba(5, 60, 122, 1))`},darkblue:{lighter:`var(--amplify_dataviz_darkblue_lighter, rgba(191, 220, 252, 1))`,default:`var(--amplify_dataviz_darkblue_default, rgba(0, 71, 153, 1))`,darker:`var(--amplify_dataviz_darkblue_darker, rgba(4, 48, 98, 1))`},lightblue:{lighter:`var(--amplify_dataviz_lightblue_lighter, rgba(211, 238, 253, 1))`,default:`var(--amplify_dataviz_lightblue_default, rgba(133, 208, 250, 1))`,darker:`var(--amplify_dataviz_lightblue_darker, rgba(35, 170, 246, 1))`},lightgreen:{lighter:`var(--amplify_dataviz_lightgreen_lighter, rgba(220, 241, 236, 1))`,default:`var(--amplify_dataviz_lightgreen_default, rgba(10, 194, 154, 1))`,darker:`var(--amplify_dataviz_lightgreen_darker, rgba(8, 145, 115, 1))`},darkgreen:{lighter:`var(--amplify_dataviz_darkgreen_lighter, rgba(200, 237, 227, 1))`,default:`var(--amplify_dataviz_darkgreen_default, rgba(0, 102, 76, 1))`,darker:`var(--amplify_dataviz_darkgreen_darker, rgba(0, 61, 46, 1))`},darkpink:{lighter:`var(--amplify_dataviz_darkpink_lighter, rgba(252, 212, 229, 1))`,muted:`var(--amplify_dataviz_darkpink_muted, rgba(242, 129, 176, 1))`,default:`var(--amplify_dataviz_darkpink_default, rgba(169, 30, 88, 1))`,darker:`var(--amplify_dataviz_darkpink_darker, rgba(135, 18, 67, 1))`},lightpink:{lighter:`var(--amplify_dataviz_lightpink_lighter, rgba(255, 219, 222, 1))`,default:`var(--amplify_dataviz_lightpink_default, rgba(255, 128, 138, 1))`,darker:`var(--amplify_dataviz_lightpink_darker, rgba(225, 81, 93, 1))`,deep:`var(--amplify_dataviz_lightpink_deep, rgba(143, 23, 33, 1))`},darkyellow:{lighter:`var(--amplify_dataviz_darkyellow_lighter, rgba(244, 226, 195, 1))`,default:`var(--amplify_dataviz_darkyellow_default, rgba(160, 112, 28, 1))`,darker:`var(--amplify_dataviz_darkyellow_darker, rgba(121, 85, 21, 1))`,deep:`var(--amplify_dataviz_darkyellow_deep, rgba(98, 77, 42, 1))`},lightyellow:{lighter:`var(--amplify_dataviz_lightyellow_lighter, rgba(255, 240, 194, 1))`,default:`var(--amplify_dataviz_lightyellow_default, rgba(253, 203, 53, 1))`,darker:`var(--amplify_dataviz_lightyellow_darker, rgba(227, 171, 2, 1))`,deep:`var(--amplify_dataviz_lightyellow_deep, rgba(200, 150, 0, 1))`},orange:{lighter:`var(--amplify_dataviz_orange_lighter, rgba(255, 222, 198, 1))`,muted:`var(--amplify_dataviz_orange_muted, rgba(255, 173, 99, 1))`,default:`var(--amplify_dataviz_orange_default, rgba(227, 128, 36, 1))`,darker:`var(--amplify_dataviz_orange_darker, rgba(121, 61, 21, 1))`},darkpurple:{lighter:`var(--amplify_dataviz_darkpurple_lighter, rgba(232, 209, 246, 1))`,default:`var(--amplify_dataviz_darkpurple_default, rgba(147, 20, 219, 1))`,darker:`var(--amplify_dataviz_darkpurple_darker, rgba(97, 1, 152, 1))`},lightpurple:{lighter:`var(--amplify_dataviz_lightpurple_lighter, rgba(234, 224, 255, 1))`,default:`var(--amplify_dataviz_lightpurple_default, rgba(186, 153, 255, 1))`,darker:`var(--amplify_dataviz_lightpurple_darker, rgba(155, 89, 242, 1))`},darkgray:{lighter:`var(--amplify-dataviz_darkgray_lighter, rgba(173, 173, 173, 1))`,default:`var(--amplify_dataviz_darkgray_default, rgba(122, 122, 122,1))`,darker:`var(--amplify-dataviz_darkgray_darker, rgba(86, 86, 86,1))`,deep:`var(--amplify-dataviz_darkgray_deep, rgba(69, 69, 69, 1))`},lightgray:{pale:`var(--amplify_dataviz_lightgray_pale, rgba(235, 238, 240, 1))`,lighter:`var(--amplify_dataviz_lightgray_lighter, rgba(194, 200, 204, 1))`,default:`var(--amplify_dataviz_lightgray_default, rgba(144, 155, 162, 1))`,darker:`var(--amplify_dataviz_lightgray_darker, rgba(91, 102, 108, 1))`}}},r={warning:n.interactive.warning__resting.rgba,error:n.interactive.danger__resting.rgba,success:n.interactive.success__resting.rgba,dirty:n.infographic.substitute__blue_ocean.rgba},i={warning:n.interactive.warning__hover.rgba,error:n.interactive.danger__hover.rgba,success:n.interactive.success__hover.rgba,dirty:n.infographic.substitute__blue_ocean.rgba};export{r as VARIANT_COLORS,i as VARIANT_HELPER_TEXT_COLORS,n as colors};
|
|
@@ -8,7 +8,20 @@ import{css as e}from"styled-components";const t=e`
|
|
|
8
8
|
|
|
9
9
|
--amplify_interactive_tutorial_active_step: rgba(154, 202, 206, 1);
|
|
10
10
|
--amplify_interactive_tutorial_inactive_step: rgba(96, 125, 127, 1);
|
|
11
|
-
--
|
|
11
|
+
--amplify_interactive_primary__nested_hover: rgba(62, 115, 120, 1);
|
|
12
|
+
|
|
13
|
+
--amplify_interactive_danger__text_hover: rgba(255, 193, 191, 1);
|
|
14
|
+
--amplify_interactive_danger__nested_hover: rgba(146, 58, 60, 1);
|
|
15
|
+
|
|
16
|
+
--amplify_interactive_warning__text_hover: rgba(255, 173, 99, 1);
|
|
17
|
+
--amplify_interactive_warning__nested_hover: rgba(151, 87, 27, 1);
|
|
18
|
+
|
|
19
|
+
--amplify_interactive_success__text_hover: rgba(188, 242, 184, 1);
|
|
20
|
+
--amplify_interactive_success__nested_hover: rgba(0, 95, 87, 1);
|
|
21
|
+
|
|
22
|
+
--amplify_interactive_info__text: rgba(183, 232, 255, 1);
|
|
23
|
+
--amplify_interactive_info__text_hover: rgba(162, 224, 255, 1);
|
|
24
|
+
--amplify_interactive_info__nested_hover: rgba(49, 111, 152, 1);
|
|
12
25
|
|
|
13
26
|
/* Override super specific text colors to just default text color */
|
|
14
27
|
--eds_heading__h1_bold_color: var(--eds_text_static_icons__default);
|
|
@@ -78,6 +91,8 @@ import{css as e}from"styled-components";const t=e`
|
|
|
78
91
|
--amplify_ui_background_light_medium: rgba(40, 58, 72, 1);
|
|
79
92
|
--amplify_ui_background_heavy: rgba(50, 72, 89, 1);
|
|
80
93
|
--amplify_ui_background_tutorial_card: rgba(50, 72, 89, 1);
|
|
94
|
+
--amplify_ui_background_success: rgba(0, 151, 123, 1);
|
|
95
|
+
|
|
81
96
|
--eds_ui_background__scrim: rgba(0, 0, 0, 0.4);
|
|
82
97
|
--eds_ui_background__overlay: rgba(0, 0, 0, 0.8);
|
|
83
98
|
--eds_ui_background__medium: rgba(44, 64, 79, 1);
|
|
@@ -3,11 +3,26 @@ import{css as e}from"styled-components";const t=e`
|
|
|
3
3
|
--amplify_ui_background_light_medium: rgba(235, 235, 235, 1);
|
|
4
4
|
--amplify_ui_background_heavy: rgba(189, 189, 189, 1);
|
|
5
5
|
--amplify_ui_background_tutorial_card: rgba(222, 237, 238, 1);
|
|
6
|
+
--amplify_ui_background_success: rgba(230, 250, 236, 1);
|
|
6
7
|
|
|
7
8
|
--amplify_interactive_primary_pressed: rgba(19, 46, 49, 1);
|
|
9
|
+
--amplify_interactive_primary__nested_hover: rgba(187, 219, 223, 1);
|
|
10
|
+
|
|
11
|
+
--amplify_interactive_danger__text_hover: rgba(154, 16, 38, 1);
|
|
12
|
+
--amplify_interactive_danger__nested_hover: rgba(255, 208, 206, 1);
|
|
13
|
+
|
|
14
|
+
--amplify_interactive_warning__text_hover: rgba(155, 73, 0, 1);
|
|
15
|
+
--amplify_interactive_warning__nested_hover: rgba(246, 202, 170, 1);
|
|
16
|
+
|
|
17
|
+
--amplify_interactive_success__text_hover: rgba(32, 105, 31, 1);
|
|
18
|
+
--amplify_interactive_success__nested_hover: rgba(195, 243, 210, 1);
|
|
19
|
+
|
|
20
|
+
--amplify_interactive_info__text: rgba(0, 112, 169, 1);
|
|
21
|
+
--amplify_interactive_info__text_hover: rgba(8, 88, 131, 1);
|
|
22
|
+
--amplify_interactive_info__nested_hover: rgba(181, 218, 245, 1);
|
|
23
|
+
|
|
8
24
|
--amplify_interactive_tutorial_active_step: rgba(0, 112, 121, 1);
|
|
9
25
|
--amplify_interactive_tutorial_inactive_step: rgba(168, 206, 209, 1);
|
|
10
|
-
--amplify_interactive_inner_hover: rgba(198, 223, 225, 1);
|
|
11
26
|
|
|
12
27
|
--amplify_dataviz_primary_default: rgba(0, 107, 229, 1);
|
|
13
28
|
--amplify_dataviz_primary_darker: rgba(0, 83, 178, 1);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react4 from "react";
|
|
2
2
|
import { IconData } from "@equinor/eds-icons";
|
|
3
3
|
|
|
4
4
|
//#region src/deprecated/ExpandingIconButton/ExpandingIconButton.d.ts
|
|
@@ -12,6 +12,6 @@ interface ExpandingIconButtonProps {
|
|
|
12
12
|
/**
|
|
13
13
|
* @deprecated Being deprecated from amplify-component-lib move into app if you want the implementation
|
|
14
14
|
*/
|
|
15
|
-
declare const ExpandingIconButton:
|
|
15
|
+
declare const ExpandingIconButton: react4.ForwardRefExoticComponent<ExpandingIconButtonProps & react4.RefAttributes<HTMLDivElement>>;
|
|
16
16
|
//#endregion
|
|
17
17
|
export { ExpandingIconButton };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react2 from "react";
|
|
2
2
|
import { IconData } from "@equinor/eds-icons";
|
|
3
3
|
|
|
4
4
|
//#region src/deprecated/IconToggleButton.d.ts
|
|
@@ -21,6 +21,6 @@ interface IconToggleButtonProps {
|
|
|
21
21
|
/**
|
|
22
22
|
* @deprecated Being deprecated from amplify-component-lib move into app if you want the implementation
|
|
23
23
|
*/
|
|
24
|
-
declare const IconToggleButton:
|
|
24
|
+
declare const IconToggleButton: react2.ForwardRefExoticComponent<IconToggleButtonProps & react2.RefAttributes<HTMLButtonElement>>;
|
|
25
25
|
//#endregion
|
|
26
26
|
export { IconToggleButton };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{auth as e,environment as t}from"../../atoms/utils/auth_environment.js";import{FullPageSpinner as n}from"../../molecules/FullPageSpinner/FullPageSpinner.js";import{MissingAccessToApp as r}from"../../organisms/Status/collections/MissingAccessToApp.js";import{useEffect as i,useRef as a,useState as o}from"react";import{useMsal as s,useMsalAuthentication as c}from"@azure/msal-react";import{BrowserAuthError as l,BrowserAuthErrorCodes as u,InteractionRequiredAuthError as d,InteractionType as f}from"@azure/msal-browser";import{jsx as p}from"react/jsx-runtime";import{jwtDecode as m}from"jwt-decode";const{GRAPH_ENDPOINTS:h,GRAPH_REQUESTS_LOGIN:g,GRAPH_REQUESTS_PHOTO:_,GRAPH_REQUESTS_BACKEND:v,fetchMsGraph:y,isInIframe:b}=e,{getApiScope:x}=t,S=({children:e,account:t,setAccount:S,setPhoto:C,setRoles:w,authState:T,setAuthState:E,withoutLoader:D,loadingComponent:O,unauthorizedComponent:k,withoutBackend:A})=>{let{instance:j,accounts:M,inProgress:N}=s(),{login:P,result:F,error:I,acquireToken:L}=c(f.Silent,g),[R,z]=o(!1),B=a(!1);return i(()=>{R||(async()=>{console.log(`[AuthProvider] Initializing`),await j.initialize(),console.log(`[AuthProvider] Finished initializing`),z(!0)})().catch(e=>{console.error(`[AuthProvider] Error during initialization`,e)})},[j,R]),i(()=>{R&&(I instanceof d&&!b()&&T!==`unauthorized`?(console.error(I),console.log(`[AuthProvider] No account found, need to login via. redirect`),P(f.Redirect,g).catch(e=>{console.error(`[AuthProvider] Error during login`,e)})):F?.account&&!t?(console.log(`[AuthProvider] Found account in useMsalAuth result, setting that one as active`),j.setActiveAccount(F.account),S(F.account)):M.length>0&&!t?(console.log(`[AuthProvider] Found account in accounts array, setting that one as active`),j.setActiveAccount(M[0]),S(M[0])):I instanceof l&&I.errorCode===u.timedOut?(console.error(I),console.log(`[AuthProvider] Trying to login again via. redirect due to monitor window timeout`),P(f.Redirect,g).catch(e=>{console.error(`[AuthProvider] Error during login`,e)})):I&&console.error(`[AuthProvider] Unexpected error:`,I))},[t,M,I,j,R,P,F,S,T]),i(()=>{if(!t||!R||B.current||N!==`none`)return;B.current=!0;let e=async()=>{try{let e=await L(f.Silent,_);if(e){let t=await y(h.PHOTO,e.accessToken);if(t.status===404)return null;let n=await t.blob();C((window.URL??window.webkitURL).createObjectURL(n))}}catch(e){console.error(e)}},n=async()=>{try{let e=await L(f.Silent,v(x(import.meta.env.VITE_API_SCOPE)));if(console.log(`[AuthProvider] Successfully acquired token`),e&&e.accessToken){console.log(`[AuthProvider] Decoding token`);let t=m(e.accessToken);if(console.log(`[AuthProvider] Token was valid`),t.roles)console.log(`[AuthProvider] Found roles`),w(t.roles);else throw Error(`Could not find roles in token`);E(`authorized`)}}catch(e){console.error(`[AuthProvider] Token error when trying to get roles!`,e),E(`unauthorized`)}};(async()=>{await e(),A?E(`authorized`):await n()})()},[t,L,I,R,N,E,C,w,A]),T===`unauthorized`?k??p(r,{}):D?e:T===`loading`||t===void 0?O??p(n,{variant:`application`}):e};export{S as AuthProviderInner};
|
|
1
|
+
import{auth as e,environment as t}from"../../atoms/utils/auth_environment.js";import{FullPageSpinner as n}from"../../molecules/FullPageSpinner/FullPageSpinner.js";import{MissingAccessToApp as r}from"../../organisms/Status/collections/MissingAccessToApp.js";import{useEffect as i,useRef as a,useState as o}from"react";import{useMsal as s,useMsalAuthentication as c}from"@azure/msal-react";import{BrowserAuthError as l,BrowserAuthErrorCodes as u,InteractionRequiredAuthError as d,InteractionType as f}from"@azure/msal-browser";import{jsx as p}from"react/jsx-runtime";import{jwtDecode as m}from"jwt-decode";const{GRAPH_ENDPOINTS:h,GRAPH_REQUESTS_LOGIN:g,GRAPH_REQUESTS_PHOTO:_,GRAPH_REQUESTS_BACKEND:v,fetchMsGraph:y,isInIframe:b}=e,{getApiScope:x}=t,S=({children:e,account:t,setAccount:S,setPhoto:C,setRoles:w,authState:T,setAuthState:E,withoutLoader:D,loadingComponent:O,unauthorizedComponent:k,withoutBackend:A})=>{let{instance:j,accounts:M,inProgress:N}=s(),{login:P,result:F,error:I,acquireToken:L}=c(f.Silent,g),[R,z]=o(!1),B=a(!1);return i(()=>{R||(async()=>{console.log(`[AuthProvider] Initializing`),await j.initialize(),console.log(`[AuthProvider] Finished initializing`),z(!0)})().catch(e=>{console.error(`[AuthProvider] Error during initialization`,e)})},[j,R]),i(()=>{R&&(I instanceof d&&!b()&&T!==`unauthorized`?(console.error(I),console.log(`[AuthProvider] No account found, need to login via. redirect`),P(f.Redirect,g).catch(e=>{console.error(`[AuthProvider] Error during login`,e)})):F?.account&&!t?(console.log(`[AuthProvider] Found account in useMsalAuth result, setting that one as active`),j.setActiveAccount(F.account),S(F.account)):M.length>0&&!t?(console.log(`[AuthProvider] Found account in accounts array, setting that one as active`),j.setActiveAccount(M[0]),S(M[0])):I instanceof l&&I.errorCode===u.timedOut&&!b()?(console.error(I),console.log(`[AuthProvider] Trying to login again via. redirect due to monitor window timeout`),P(f.Redirect,g).catch(e=>{console.error(`[AuthProvider] Error during login`,e)})):I&&console.error(`[AuthProvider] Unexpected error:`,I))},[t,M,I,j,R,P,F,S,T]),i(()=>{if(!t||!R||B.current||N!==`none`)return;B.current=!0;let e=async()=>{try{let e=await L(f.Silent,_);if(e){let t=await y(h.PHOTO,e.accessToken);if(t.status===404)return null;let n=await t.blob();C((window.URL??window.webkitURL).createObjectURL(n))}}catch(e){console.error(e)}},n=async()=>{try{let e=await L(f.Silent,v(x(import.meta.env.VITE_API_SCOPE)));if(console.log(`[AuthProvider] Successfully acquired token`),e&&e.accessToken){console.log(`[AuthProvider] Decoding token`);let t=m(e.accessToken);if(console.log(`[AuthProvider] Token was valid`),t.roles)console.log(`[AuthProvider] Found roles`),w(t.roles);else throw Error(`Could not find roles in token`);E(`authorized`)}}catch(e){console.error(`[AuthProvider] Token error when trying to get roles!`,e),E(`unauthorized`)}};(async()=>{await e(),A?E(`authorized`):await n()})()},[t,L,I,R,N,E,C,w,A]),T===`unauthorized`?k??p(r,{}):D?e:T===`loading`||t===void 0?O??p(n,{variant:`application`}):e};export{S as AuthProviderInner};
|