varminer-app-header 2.2.9 → 2.3.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/README.md +93 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.esm.js +16 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +16 -11
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/localStorage.d.ts +2 -2
- package/dist/utils/localStorage.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -390,17 +390,20 @@ const getAllDataFromStorage = () => {
|
|
|
390
390
|
};
|
|
391
391
|
/**
|
|
392
392
|
* Get profile picture URL from object store API using user_id.
|
|
393
|
-
* @param baseUrl - Base URL for the object store API (
|
|
394
|
-
* @returns Profile picture URL or null if user_id is not available
|
|
393
|
+
* @param baseUrl - Base URL for the object store API (e.g. from objectStoreUrl prop). When missing or empty, returns null.
|
|
394
|
+
* @returns Profile picture URL or null if user_id or baseUrl is not available
|
|
395
395
|
*/
|
|
396
396
|
const VERIFICATION_USER_ID = 4590; // set to null to use only storage userId
|
|
397
|
-
const getProfilePictureUrl = (baseUrl
|
|
397
|
+
const getProfilePictureUrl = (baseUrl) => {
|
|
398
398
|
try {
|
|
399
|
+
const url = typeof baseUrl === "string" && baseUrl.trim() ? baseUrl.trim() : null;
|
|
400
|
+
if (!url)
|
|
401
|
+
return null;
|
|
399
402
|
const allData = getAllDataFromStorage();
|
|
400
403
|
const userId = allData.decodedToken?.user_id ?? allData.auth?.user_id ?? getStoredUserDetails()?.userId ?? VERIFICATION_USER_ID ?? null;
|
|
401
404
|
if (userId == null)
|
|
402
405
|
return null;
|
|
403
|
-
return `${
|
|
406
|
+
return `${url.replace(/\/$/, "")}/v1/objectStore/profilePicture/path/${userId}`;
|
|
404
407
|
}
|
|
405
408
|
catch (err) {
|
|
406
409
|
console.error("Error getting profile picture URL:", err);
|
|
@@ -415,8 +418,8 @@ function getKeyFromS3Uri(s3Uri) {
|
|
|
415
418
|
/**
|
|
416
419
|
* Fetch profile picture: (1) GET path API for JSON with filePath/s3Uri, (2) GET download API with key; download returns JSON with base64 fileContent.
|
|
417
420
|
* Path API: { statusResponse, filePath, s3Uri, errors }. Download API: { statusResponse, fileName, contentType, fileContent (base64), errors }.
|
|
418
|
-
* @param baseUrl - Base URL for the object store API (
|
|
419
|
-
* @returns Promise that resolves to blob URL string or null if fetch fails
|
|
421
|
+
* @param baseUrl - Base URL for the object store API (e.g. from objectStoreUrl prop). When missing or empty, returns null without fetching.
|
|
422
|
+
* @returns Promise that resolves to blob URL string or null if fetch fails or baseUrl not provided
|
|
420
423
|
*/
|
|
421
424
|
/** Resolve access token from auth object (supports accessToken, access_token, token). */
|
|
422
425
|
function getAccessTokenFromAuth(auth) {
|
|
@@ -542,11 +545,14 @@ function getAccessTokenForRequest() {
|
|
|
542
545
|
}
|
|
543
546
|
return getAccessTokenFromAuth(getAllDataFromStorage().auth);
|
|
544
547
|
}
|
|
545
|
-
const fetchProfilePictureAsBlobUrl = async (baseUrl
|
|
548
|
+
const fetchProfilePictureAsBlobUrl = async (baseUrl, accessTokenOverride) => {
|
|
546
549
|
try {
|
|
547
550
|
const profilePicturePathUrl = getProfilePictureUrl(baseUrl);
|
|
548
551
|
if (!profilePicturePathUrl)
|
|
549
552
|
return null;
|
|
553
|
+
const cleanBase = typeof baseUrl === "string" && baseUrl.trim() ? baseUrl.trim().replace(/\/$/, "") : "";
|
|
554
|
+
if (!cleanBase)
|
|
555
|
+
return null;
|
|
550
556
|
const accessToken = (typeof accessTokenOverride === "string" && accessTokenOverride.length > 0
|
|
551
557
|
? accessTokenOverride
|
|
552
558
|
: null) ?? getAccessTokenForRequest();
|
|
@@ -586,7 +592,6 @@ const fetchProfilePictureAsBlobUrl = async (baseUrl = "http://objectstore.impact
|
|
|
586
592
|
return null;
|
|
587
593
|
}
|
|
588
594
|
// Step 2: GET download API → JSON with fileContent (base64) and contentType
|
|
589
|
-
const cleanBase = baseUrl.replace(/\/$/, "");
|
|
590
595
|
const downloadUrl = `${cleanBase}/v1/objectStore/download?key=${encodeURIComponent(downloadKey)}`;
|
|
591
596
|
const imageResponse = await fetch(downloadUrl, { method: "GET", headers });
|
|
592
597
|
if (!imageResponse.ok) {
|
|
@@ -735,7 +740,7 @@ const DEFAULT_ROUTES = {
|
|
|
735
740
|
profile: "/user/profile",
|
|
736
741
|
logout: "/user/login",
|
|
737
742
|
};
|
|
738
|
-
const AppHeader = ({ language: languageProp, accessToken: accessTokenProp }) => {
|
|
743
|
+
const AppHeader = ({ language: languageProp, accessToken: accessTokenProp, objectStoreUrl }) => {
|
|
739
744
|
// Get initial language from props, URL, localStorage, or default to 'en'
|
|
740
745
|
const getInitialLanguage = () => {
|
|
741
746
|
// Priority 1: Props
|
|
@@ -859,7 +864,7 @@ const AppHeader = ({ language: languageProp, accessToken: accessTokenProp }) =>
|
|
|
859
864
|
React.useEffect(() => {
|
|
860
865
|
const fetchProfilePicture = async () => {
|
|
861
866
|
const token = accessTokenProp ?? getAccessTokenForRequest();
|
|
862
|
-
const blobUrl = await fetchProfilePictureAsBlobUrl(undefined, token ?? undefined);
|
|
867
|
+
const blobUrl = await fetchProfilePictureAsBlobUrl(objectStoreUrl ?? undefined, token ?? undefined);
|
|
863
868
|
if (blobUrl) {
|
|
864
869
|
// Clean up previous blob URL if it exists
|
|
865
870
|
setProfilePictureBlobUrl((prevUrl) => {
|
|
@@ -880,7 +885,7 @@ const AppHeader = ({ language: languageProp, accessToken: accessTokenProp }) =>
|
|
|
880
885
|
return null;
|
|
881
886
|
});
|
|
882
887
|
};
|
|
883
|
-
}, [accessTokenProp]); // Refetch when accessToken
|
|
888
|
+
}, [accessTokenProp, objectStoreUrl]); // Refetch when accessToken or objectStoreUrl changes (e.g. after login or env switch)
|
|
884
889
|
React.useEffect(() => {
|
|
885
890
|
const allData = getAllDataFromStorage();
|
|
886
891
|
let userName = "";
|