varminer-app-header 2.6.4 → 2.6.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.
package/dist/index.js CHANGED
@@ -179,18 +179,19 @@ const getUserDataFromStorage = () => {
179
179
  initials: name ? name.split(/\s+/).map((s) => s[0]).join("").slice(0, 2).toUpperCase() : undefined,
180
180
  };
181
181
  }
182
- // authDetails.auth.user has firstname/lastname (lowercase n) + activeRole
182
+ // authDetails.auth.user has firstname/lastname (lowercase n) or firstName/lastName (camelCase) + activeRole
183
183
  const authDetailsRaw = parseNested(outer.authDetails);
184
184
  const auth = authDetailsRaw?.auth;
185
185
  const userObj = auth?.user;
186
- if (auth && (userObj?.firstname || userObj?.lastname)) {
187
- const first = userObj?.firstname || "";
188
- const last = userObj?.lastname || "";
189
- const name = [first, last].filter(Boolean).join(" ").trim();
190
- const role = auth.activeRole || "";
186
+ const firstFromUser = (userObj?.firstname ?? userObj?.firstName ?? userObj?.given_name ?? userObj?.first_name) || "";
187
+ const lastFromUser = (userObj?.lastname ?? userObj?.lastName ?? userObj?.family_name ?? userObj?.last_name) || "";
188
+ const emailFromUser = (userObj?.email ?? userObj?.emailAddress) || (auth?.email ?? auth?.sub) || "";
189
+ if (auth && (firstFromUser || lastFromUser || emailFromUser)) {
190
+ const name = [firstFromUser, lastFromUser].filter(Boolean).join(" ").trim();
191
+ const role = auth.activeRole || auth.role || "";
191
192
  return {
192
193
  name,
193
- email: "",
194
+ email: emailFromUser,
194
195
  role,
195
196
  avatar: undefined,
196
197
  initials: name ? name.split(/\s+/).map((s) => s[0]).join("").slice(0, 2).toUpperCase() : undefined,
@@ -355,49 +356,7 @@ const getAllDataFromStorage = () => {
355
356
  console.error("Error parsing header persist:", err);
356
357
  }
357
358
  }
358
- // Fallback: try IAM persist key (persist:linn-i-am) then persist:userdb
359
- const tryParsePersistForAuth = (raw) => {
360
- if (!raw)
361
- return null;
362
- try {
363
- const outer = JSON.parse(raw);
364
- const parseNested = (v) => typeof v === "string" ? (() => { try {
365
- return JSON.parse(v);
366
- }
367
- catch {
368
- return v;
369
- } })() : v;
370
- for (const key of Object.keys(outer)) {
371
- const parsed = parseNested(outer[key]);
372
- if (parsed?.accessToken || parsed?.access_token || parsed?.token || parsed?.refreshToken)
373
- return parsed;
374
- if (parsed?.auth && typeof parsed.auth === "object") {
375
- const a = parsed.auth;
376
- if (a.accessToken || a.access_token || a.token)
377
- return a;
378
- }
379
- }
380
- }
381
- catch {
382
- /* ignore */
383
- }
384
- return null;
385
- };
386
- const iamPersist = localStorage.getItem("persist:linn-i-am");
387
- const iamAuth = tryParsePersistForAuth(iamPersist);
388
- if (iamAuth) {
389
- const token = (iamAuth.accessToken ?? iamAuth.access_token ?? iamAuth.token);
390
- if (token) {
391
- const decodedToken = decodeJWT(token);
392
- return {
393
- ...emptyStorageResult(),
394
- auth: iamAuth,
395
- decodedToken: decodedToken ? Object.fromEntries(Object.entries(decodedToken).map(([k, v]) => [k, v ?? null])) : null,
396
- rawData: iamAuth,
397
- };
398
- }
399
- }
400
- // Fallback: read access token from persist:userdb (e.g. legacy or shared auth)
359
+ // Fallback: read access token from persist:userdb
401
360
  const userDbString = localStorage.getItem("persist:userdb");
402
361
  if (!userDbString) {
403
362
  return emptyStorageResult();
@@ -598,7 +557,6 @@ function getTokenFromUserDbPersist(parsed) {
598
557
  function getAccessTokenForRequest() {
599
558
  const keysToTry = [
600
559
  PERSIST_HEADER_KEY,
601
- "persist:linn-i-am",
602
560
  "persist:userdb",
603
561
  "token",
604
562
  "accessToken",
@@ -864,6 +822,35 @@ const AppHeader = ({ language: languageProp, accessToken: accessTokenProp, objec
864
822
  let userName = "";
865
823
  let userEmail = "";
866
824
  let userRole = "";
825
+ // === DEBUG ===
826
+ const _allLSKeys = [];
827
+ for (let i = 0; i < localStorage.length; i++) {
828
+ const k = localStorage.key(i);
829
+ if (k)
830
+ _allLSKeys.push(k);
831
+ }
832
+ const _dbgRaw = {};
833
+ _allLSKeys.forEach(k => {
834
+ const v = localStorage.getItem(k);
835
+ if (v) {
836
+ try {
837
+ _dbgRaw[k] = JSON.parse(v);
838
+ }
839
+ catch {
840
+ _dbgRaw[k] = v;
841
+ }
842
+ }
843
+ else {
844
+ _dbgRaw[k] = null;
845
+ }
846
+ });
847
+ console.warn("▶▶▶ [AppHeader DEBUG] ALL localStorage keys:", _allLSKeys);
848
+ console.warn("▶▶▶ [AppHeader DEBUG] ALL localStorage values:", _dbgRaw);
849
+ console.warn("▶▶▶ [AppHeader DEBUG] linn-i-am-userDetails:", localStorage.getItem("linn-i-am-userDetails"));
850
+ console.warn("▶▶▶ [AppHeader DEBUG] persist:userdb (raw):", localStorage.getItem("persist:userdb"));
851
+ console.warn("▶▶▶ [AppHeader DEBUG] getAllDataFromStorage():", allData);
852
+ console.warn("▶▶▶ [AppHeader DEBUG] getUserDataFromStorage():", getUserDataFromStorage());
853
+ // === END DEBUG ===
867
854
  const buildNameFromFirstLast = (obj) => {
868
855
  if (!obj || typeof obj !== "object")
869
856
  return "";
@@ -888,8 +875,9 @@ const AppHeader = ({ language: languageProp, accessToken: accessTokenProp, objec
888
875
  }
889
876
  if (allData.auth) {
890
877
  const auth = allData.auth;
891
- userEmail = userEmail || auth.email || auth.sub || "";
892
- userName = userName || auth.name || buildNameFromFirstLast(auth) || "";
878
+ const authUser = auth.user;
879
+ userEmail = userEmail || auth.email || auth.sub || authUser?.email || authUser?.emailAddress || "";
880
+ userName = userName || auth.name || buildNameFromFirstLast(auth) || buildNameFromFirstLast(authUser) || "";
893
881
  userRole = userRole || auth.role || auth.activeRole || "";
894
882
  }
895
883
  if (allData.userDetails) {
@@ -932,13 +920,15 @@ const AppHeader = ({ language: languageProp, accessToken: accessTokenProp, objec
932
920
  const initialsVal = storedUser?.initials ??
933
921
  allData.auth?.initials ??
934
922
  allData.profile?.initials;
935
- return {
923
+ const resolvedUser = {
936
924
  name: userName || "",
937
925
  email: userEmail || "",
938
926
  role: userRole || "",
939
927
  avatar: typeof avatarSrc === "string" ? avatarSrc : undefined,
940
928
  initials: typeof initialsVal === "string" ? initialsVal : undefined,
941
929
  };
930
+ console.warn("▶▶▶ [AppHeader DEBUG] Resolved user state (name/email/role):", resolvedUser);
931
+ return resolvedUser;
942
932
  });
943
933
  const [notificationCount, setNotificationCount] = React.useState(() => {
944
934
  const count = getNotificationCountFromStorage();
@@ -1006,8 +996,9 @@ const AppHeader = ({ language: languageProp, accessToken: accessTokenProp, objec
1006
996
  }
1007
997
  if (allData.auth) {
1008
998
  const auth = allData.auth;
1009
- userEmail = userEmail || auth.email || auth.sub || "";
1010
- userName = userName || auth.name || buildNameFromFirstLast(auth) || "";
999
+ const authUser = auth.user;
1000
+ userEmail = userEmail || auth.email || auth.sub || authUser?.email || authUser?.emailAddress || "";
1001
+ userName = userName || auth.name || buildNameFromFirstLast(auth) || buildNameFromFirstLast(authUser) || "";
1011
1002
  userRole = userRole || auth.role || auth.activeRole || "";
1012
1003
  userAvatar = userAvatar || auth.avatar || undefined;
1013
1004
  userInitials = userInitials || auth.initials || undefined;
@@ -1218,7 +1209,7 @@ const AppHeader = ({ language: languageProp, accessToken: accessTokenProp, objec
1218
1209
  width: "100%",
1219
1210
  maxWidth: 360,
1220
1211
  pointerEvents: "none",
1221
- }, component: "div", "aria-hidden": "true", tabIndex: -1, children: jsxRuntime.jsxs(material.ListItem, { alignItems: "flex-start", className: "profile-menu-item", children: [jsxRuntime.jsx(material.ListItemAvatar, { children: isOnlineStatus ? (jsxRuntime.jsx(OnlineBadge, { overlap: "circular", anchorOrigin: { vertical: "bottom", horizontal: "right" }, variant: "dot", title: t.online, "aria-label": `${t.online} status badge`, "data-testid": "online-badge", children: jsxRuntime.jsx(material.Avatar, { sx: { bgcolor: colors.deepOrange[500] }, alt: user.name, title: user.name, src: user.avatar, children: getInitials() }) })) : (jsxRuntime.jsx(OfflineBadge, { overlap: "circular", anchorOrigin: { vertical: "bottom", horizontal: "right" }, variant: "dot", title: t.offline, "aria-label": `${t.offline} status badge`, "data-testid": "offline-badge", children: jsxRuntime.jsx(material.Avatar, { sx: { bgcolor: colors.deepOrange[500] }, alt: user.name, title: user.name, src: user.avatar, children: getInitials() }) })) }), jsxRuntime.jsx(material.ListItemText, { primary: jsxRuntime.jsx(material.Typography, { className: "profile-name", component: "span", children: user.name || user.email }), secondary: jsxRuntime.jsxs(React.Fragment, { children: [user.name && user.email ? (jsxRuntime.jsx(material.Typography, { className: "profile-email", component: "p", children: user.email })) : null, jsxRuntime.jsxs(material.Typography, { className: "profile-role", component: "p", children: [t.role, ": ", user.role] })] }) })] }) }));
1212
+ }, component: "div", "aria-hidden": "true", tabIndex: -1, children: jsxRuntime.jsxs(material.ListItem, { alignItems: "flex-start", className: "profile-menu-item", children: [jsxRuntime.jsx(material.ListItemAvatar, { children: isOnlineStatus ? (jsxRuntime.jsx(OnlineBadge, { overlap: "circular", anchorOrigin: { vertical: "bottom", horizontal: "right" }, variant: "dot", title: t.online, "aria-label": `${t.online} status badge`, "data-testid": "online-badge", children: jsxRuntime.jsx(material.Avatar, { sx: { bgcolor: colors.deepOrange[500] }, alt: user.name, title: user.name, src: user.avatar, children: getInitials() }) })) : (jsxRuntime.jsx(OfflineBadge, { overlap: "circular", anchorOrigin: { vertical: "bottom", horizontal: "right" }, variant: "dot", title: t.offline, "aria-label": `${t.offline} status badge`, "data-testid": "offline-badge", children: jsxRuntime.jsx(material.Avatar, { sx: { bgcolor: colors.deepOrange[500] }, alt: user.name, title: user.name, src: user.avatar, children: getInitials() }) })) }), jsxRuntime.jsx(material.ListItemText, { primaryTypographyProps: { component: "span" }, secondaryTypographyProps: { component: "span" }, primary: jsxRuntime.jsx(material.Typography, { className: "profile-name", component: "span", children: user.name || user.email }), secondary: jsxRuntime.jsxs(React.Fragment, { children: [user.name && user.email ? (jsxRuntime.jsx(material.Typography, { className: "profile-email", component: "span", display: "block", children: user.email })) : null, jsxRuntime.jsxs(material.Typography, { className: "profile-role", component: "span", display: "block", children: [t.role, ": ", user.role] })] }) })] }) }));
1222
1213
  const renderMenu = (jsxRuntime.jsxs(material.Menu, { anchorEl: anchorEl, id: "account-menu", open: open, onClose: handleClose, onClick: handleClose, slotProps: {
1223
1214
  paper: {
1224
1215
  elevation: 0,