varminer-app-header 2.1.8 → 2.2.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.
@@ -1 +1 @@
1
- {"version":3,"file":"AppHeader.d.ts","sourceRoot":"","sources":["../src/AppHeader.tsx"],"names":[],"mappings":"AA4BA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAe,MAAM,SAAS,CAAC;AAKtD,OAAO,sBAAsB,CAAC;AAQ9B,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAixBvC,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"AppHeader.d.ts","sourceRoot":"","sources":["../src/AppHeader.tsx"],"names":[],"mappings":"AA4BA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAe,MAAM,SAAS,CAAC;AAKtD,OAAO,sBAAsB,CAAC;AAQ9B,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CA8yBvC,CAAC;AAEF,eAAe,SAAS,CAAC"}
package/dist/index.d.ts CHANGED
@@ -97,9 +97,9 @@ declare const setI18nLocaleToStorage: (locale: string) => void;
97
97
  */
98
98
  declare const getAllDataFromStorage: () => any;
99
99
  /**
100
- * Get profile picture URL from object store API using tenant_id and user_id from JWT token
100
+ * Get profile picture URL from object store API using user_id.
101
101
  * @param baseUrl - Base URL for the object store API (default: http://objectstore.impact0mics.local:9012)
102
- * @returns Profile picture URL or null if tenant_id or user_id is not available
102
+ * @returns Profile picture URL or null if user_id is not available
103
103
  */
104
104
  declare const getProfilePictureUrl: (baseUrl?: string) => string | null;
105
105
  /**
package/dist/index.esm.js CHANGED
@@ -356,32 +356,17 @@ const getAllDataFromStorage = () => {
356
356
  }
357
357
  };
358
358
  /**
359
- * Get profile picture URL from object store API using tenant_id and user_id from JWT token
359
+ * Get profile picture URL from object store API using user_id.
360
360
  * @param baseUrl - Base URL for the object store API (default: http://objectstore.impact0mics.local:9012)
361
- * @returns Profile picture URL or null if tenant_id or user_id is not available
361
+ * @returns Profile picture URL or null if user_id is not available
362
362
  */
363
363
  const getProfilePictureUrl = (baseUrl = "http://objectstore.impact0mics.local:9012") => {
364
364
  try {
365
365
  const allData = getAllDataFromStorage();
366
- // Get tenant_id and user_id from decoded token
367
- let tenantId = null;
368
- let userId = null;
369
- if (allData.decodedToken) {
370
- tenantId = allData.decodedToken.tenant_id || allData.decodedToken.tenant || null;
371
- userId = allData.decodedToken.user_id || null;
372
- }
373
- // If not found in decoded token, try auth data
374
- if ((!tenantId || !userId) && allData.auth) {
375
- tenantId = tenantId || allData.auth.tenant_id || allData.auth.tenant || null;
376
- userId = userId || allData.auth.user_id || null;
377
- }
378
- // Construct URL if we have both tenant_id and user_id
379
- if (tenantId && userId) {
380
- // Remove trailing slash from baseUrl if present
381
- const cleanBaseUrl = baseUrl.replace(/\/$/, '');
382
- return `${cleanBaseUrl}/v1/objectStore/profilePicture/path/${tenantId}/${userId}`;
383
- }
384
- return null;
366
+ const userId = allData.decodedToken?.user_id ?? allData.auth?.user_id ?? getStoredUserDetails()?.userId ?? null;
367
+ if (userId == null)
368
+ return null;
369
+ return `${baseUrl.replace(/\/$/, "")}/v1/objectStore/profilePicture/path/${userId}`;
385
370
  }
386
371
  catch (err) {
387
372
  console.error("Error getting profile picture URL:", err);
@@ -703,51 +688,68 @@ const AppHeader = ({ language: languageProp }) => {
703
688
  const [mobileMoreAnchorEl, setMobileMoreAnchorEl] = React__default.useState(null);
704
689
  const [user, setUser] = React__default.useState(() => {
705
690
  const allData = getAllDataFromStorage();
706
- // Try to get user data from various sources
707
691
  let userName = "";
708
692
  let userEmail = "";
709
693
  let userRole = "";
710
- // Priority 1: From decoded token
711
- if (allData.decodedToken) {
712
- userName = allData.decodedToken.sub || allData.decodedToken.email || "";
713
- userEmail = allData.decodedToken.sub || allData.decodedToken.email || "";
714
- userRole = allData.decodedToken.role || "";
715
- }
716
- // Priority 2: From auth data
717
- if (allData.auth) {
718
- userName = userName || allData.auth.name || allData.auth.email || "";
719
- userEmail = userEmail || allData.auth.email || allData.auth.sub || "";
720
- userRole = userRole || allData.auth.role || allData.auth.activeRole || "";
721
- }
722
- // Priority 3: From userDetails/user/profile
694
+ const buildNameFromFirstLast = (obj) => {
695
+ if (!obj || typeof obj !== "object")
696
+ return "";
697
+ const first = (obj.firstName ?? obj.given_name ?? obj.first_name);
698
+ const last = (obj.lastName ?? obj.family_name ?? obj.last_name);
699
+ return [first, last].filter(Boolean).join(" ").trim();
700
+ };
701
+ // Prefer getUserDataFromStorage first (IAM firstName+lastName or persist:userdb name)
723
702
  const storedUser = getUserDataFromStorage();
724
703
  if (storedUser) {
725
- userName = userName || storedUser.name || "";
704
+ userName = storedUser.name || "";
726
705
  userEmail = userEmail || storedUser.email || "";
727
706
  userRole = userRole || storedUser.role || "";
728
707
  }
729
- // Priority 4: From other parsed data
708
+ // Then enrich from decoded token (email from sub; name only if token has name/given_name/family_name, never use sub as name)
709
+ if (allData.decodedToken) {
710
+ const token = allData.decodedToken;
711
+ userEmail = userEmail || token.sub || token.email || "";
712
+ const tokenName = token.name || buildNameFromFirstLast(token);
713
+ userName = userName || (tokenName || "");
714
+ userRole = userRole || token.role || "";
715
+ }
716
+ if (allData.auth) {
717
+ const auth = allData.auth;
718
+ userEmail = userEmail || auth.email || auth.sub || "";
719
+ userName = userName || auth.name || buildNameFromFirstLast(auth) || "";
720
+ userRole = userRole || auth.role || auth.activeRole || "";
721
+ }
730
722
  if (allData.userDetails) {
731
- const userDetails = allData.userDetails.user || allData.userDetails.data || allData.userDetails;
732
- if (userDetails) {
733
- userName = userName || userDetails.name || userDetails.fullName || "";
734
- userEmail = userEmail || userDetails.email || userDetails.emailAddress || "";
735
- userRole = userRole || userDetails.role || userDetails.userRole || "";
723
+ const userDetails = allData.userDetails.user
724
+ || allData.userDetails.data
725
+ || allData.userDetails;
726
+ const details = userDetails;
727
+ if (details) {
728
+ userEmail = userEmail || details.email || details.emailAddress || "";
729
+ userName = userName || details.name || details.fullName || buildNameFromFirstLast(details) || "";
730
+ userRole = userRole || details.role || details.userRole || "";
736
731
  }
737
732
  }
738
733
  if (allData.user) {
739
- const userData = allData.user.user || allData.user.data || allData.user.currentUser || allData.user;
734
+ const u = allData.user.user
735
+ || allData.user.data
736
+ || allData.user.currentUser
737
+ || allData.user;
738
+ const userData = u;
740
739
  if (userData) {
741
- userName = userName || userData.name || userData.fullName || "";
742
740
  userEmail = userEmail || userData.email || userData.emailAddress || "";
741
+ userName = userName || userData.name || userData.fullName || buildNameFromFirstLast(userData) || "";
743
742
  userRole = userRole || userData.role || userData.userRole || "";
744
743
  }
745
744
  }
746
745
  if (allData.profile) {
747
- const profileData = allData.profile.user || allData.profile.data || allData.profile;
746
+ const p = allData.profile.user
747
+ || allData.profile.data
748
+ || allData.profile;
749
+ const profileData = p;
748
750
  if (profileData) {
749
- userName = userName || profileData.name || profileData.fullName || "";
750
751
  userEmail = userEmail || profileData.email || profileData.emailAddress || "";
752
+ userName = userName || profileData.name || profileData.fullName || buildNameFromFirstLast(profileData) || "";
751
753
  userRole = userRole || profileData.role || profileData.userRole || "";
752
754
  }
753
755
  }
@@ -796,67 +798,81 @@ const AppHeader = ({ language: languageProp }) => {
796
798
  }, []); // Only run once on mount - fetch when component loads
797
799
  React__default.useEffect(() => {
798
800
  const allData = getAllDataFromStorage();
799
- // Try to get user data from various sources
800
801
  let userName = "";
801
802
  let userEmail = "";
802
803
  let userRole = "";
803
- let userAvatar = undefined;
804
- let userInitials = undefined;
805
- // Priority 1: From decoded token
806
- if (allData.decodedToken) {
807
- userName = allData.decodedToken.sub || allData.decodedToken.email || "";
808
- userEmail = allData.decodedToken.sub || allData.decodedToken.email || "";
809
- userRole = allData.decodedToken.role || "";
810
- }
811
- // Priority 2: From auth data
812
- if (allData.auth) {
813
- userName = userName || allData.auth.name || allData.auth.email || "";
814
- userEmail = userEmail || allData.auth.email || allData.auth.sub || "";
815
- userRole = userRole || allData.auth.role || allData.auth.activeRole || "";
816
- userAvatar = userAvatar || allData.auth.avatar || undefined;
817
- userInitials = userInitials || allData.auth.initials || undefined;
818
- }
819
- // Priority 3: From userDetails/user/profile
804
+ let userAvatar;
805
+ let userInitials;
806
+ const buildNameFromFirstLast = (obj) => {
807
+ if (!obj || typeof obj !== "object")
808
+ return "";
809
+ const first = (obj.firstName ?? obj.given_name ?? obj.first_name);
810
+ const last = (obj.lastName ?? obj.family_name ?? obj.last_name);
811
+ return [first, last].filter(Boolean).join(" ").trim();
812
+ };
820
813
  const storedUser = getUserDataFromStorage();
821
814
  if (storedUser) {
822
- userName = userName || storedUser.name || "";
815
+ userName = storedUser.name || "";
823
816
  userEmail = userEmail || storedUser.email || "";
824
817
  userRole = userRole || storedUser.role || "";
825
- userAvatar = userAvatar || storedUser.avatar || undefined;
826
- userInitials = userInitials || storedUser.initials || undefined;
818
+ userAvatar = storedUser.avatar;
819
+ userInitials = storedUser.initials;
820
+ }
821
+ if (allData.decodedToken) {
822
+ const token = allData.decodedToken;
823
+ userEmail = userEmail || token.sub || token.email || "";
824
+ const tokenName = token.name || buildNameFromFirstLast(token);
825
+ userName = userName || (tokenName || "");
826
+ userRole = userRole || token.role || "";
827
+ }
828
+ if (allData.auth) {
829
+ const auth = allData.auth;
830
+ userEmail = userEmail || auth.email || auth.sub || "";
831
+ userName = userName || auth.name || buildNameFromFirstLast(auth) || "";
832
+ userRole = userRole || auth.role || auth.activeRole || "";
833
+ userAvatar = userAvatar || auth.avatar || undefined;
834
+ userInitials = userInitials || auth.initials || undefined;
827
835
  }
828
- // Priority 4: From other parsed data
829
836
  if (allData.userDetails) {
830
- const userDetails = allData.userDetails.user || allData.userDetails.data || allData.userDetails;
831
- if (userDetails) {
832
- userName = userName || userDetails.name || userDetails.fullName || "";
833
- userEmail = userEmail || userDetails.email || userDetails.emailAddress || "";
834
- userRole = userRole || userDetails.role || userDetails.userRole || "";
835
- userAvatar = userAvatar || userDetails.avatar || userDetails.profilePicture || undefined;
836
- userInitials = userInitials || userDetails.initials || undefined;
837
+ const userDetails = allData.userDetails.user
838
+ || allData.userDetails.data
839
+ || allData.userDetails;
840
+ const details = userDetails;
841
+ if (details) {
842
+ userEmail = userEmail || details.email || details.emailAddress || "";
843
+ userName = userName || details.name || details.fullName || buildNameFromFirstLast(details) || "";
844
+ userRole = userRole || details.role || details.userRole || "";
845
+ userAvatar = userAvatar || details.avatar || details.profilePicture || undefined;
846
+ userInitials = userInitials || details.initials || undefined;
837
847
  }
838
848
  }
839
849
  if (allData.user) {
840
- const userData = allData.user.user || allData.user.data || allData.user.currentUser || allData.user;
850
+ const u = allData.user.user
851
+ || allData.user.data
852
+ || allData.user.currentUser
853
+ || allData.user;
854
+ const userData = u;
841
855
  if (userData) {
842
- userName = userName || userData.name || userData.fullName || "";
843
856
  userEmail = userEmail || userData.email || userData.emailAddress || "";
857
+ userName = userName || userData.name || userData.fullName || buildNameFromFirstLast(userData) || "";
844
858
  userRole = userRole || userData.role || userData.userRole || "";
845
859
  userAvatar = userAvatar || userData.avatar || userData.profilePicture || undefined;
846
860
  userInitials = userInitials || userData.initials || undefined;
847
861
  }
848
862
  }
849
863
  if (allData.profile) {
850
- const profileData = allData.profile.user || allData.profile.data || allData.profile;
864
+ const p = allData.profile.user
865
+ || allData.profile.data
866
+ || allData.profile;
867
+ const profileData = p;
851
868
  if (profileData) {
852
- userName = userName || profileData.name || profileData.fullName || "";
853
869
  userEmail = userEmail || profileData.email || profileData.emailAddress || "";
870
+ userName = userName || profileData.name || profileData.fullName || buildNameFromFirstLast(profileData) || "";
854
871
  userRole = userRole || profileData.role || profileData.userRole || "";
855
872
  userAvatar = userAvatar || profileData.avatar || profileData.profilePicture || undefined;
856
873
  userInitials = userInitials || profileData.initials || undefined;
857
874
  }
858
875
  }
859
- // Use fetched blob URL if available, otherwise fall back to other sources
860
876
  setUser({
861
877
  name: userName || "",
862
878
  email: userEmail || "",