varminer-app-header 2.2.3 → 2.2.4
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/AppHeader.d.ts.map +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +132 -10
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +132 -9
- 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 +6 -1
- package/dist/utils/localStorage.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/AppHeader.d.ts.map
CHANGED
|
@@ -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,
|
|
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,CAszBvC,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ interface UserProfile {
|
|
|
11
11
|
}
|
|
12
12
|
interface AppHeaderProps {
|
|
13
13
|
language?: 'en' | 'es';
|
|
14
|
+
/** When provided, used as Bearer token for profile picture and other authenticated requests. */
|
|
15
|
+
accessToken?: string | null;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
declare const AppHeader: React__default.FC<AppHeaderProps>;
|
|
@@ -119,7 +121,12 @@ declare const getAllDataFromStorage: () => any;
|
|
|
119
121
|
* @returns Profile picture URL or null if user_id is not available
|
|
120
122
|
*/
|
|
121
123
|
declare const getProfilePictureUrl: (baseUrl?: string) => string | null;
|
|
122
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Get access token from all known storage keys (header, IAM, userdb, and plain keys).
|
|
126
|
+
* persist:userdb shape: authDetails (stringified) contains auth.accessToken.
|
|
127
|
+
*/
|
|
128
|
+
declare function getAccessTokenForRequest(): string | undefined;
|
|
129
|
+
declare const fetchProfilePictureAsBlobUrl: (baseUrl?: string, accessTokenOverride?: string | null) => Promise<string | null>;
|
|
123
130
|
|
|
124
|
-
export { AppHeader, DrawerProvider, PERSIST_HEADER_KEY, USER_DETAILS_STORAGE_KEY, fetchProfilePictureAsBlobUrl, getAllDataFromStorage, getI18nLocaleFromStorage, getMessageCountFromStorage, getNotificationCountFromStorage, getProfilePictureUrl, getStoredUserDetails, getTranslations, getUserDataFromStorage, setHeaderAuth, setI18nLocaleToStorage, translations, useDrawer };
|
|
131
|
+
export { AppHeader, DrawerProvider, PERSIST_HEADER_KEY, USER_DETAILS_STORAGE_KEY, fetchProfilePictureAsBlobUrl, getAccessTokenForRequest, getAllDataFromStorage, getI18nLocaleFromStorage, getMessageCountFromStorage, getNotificationCountFromStorage, getProfilePictureUrl, getStoredUserDetails, getTranslations, getUserDataFromStorage, setHeaderAuth, setI18nLocaleToStorage, translations, useDrawer };
|
|
125
132
|
export type { AppHeaderProps, HeaderAuthState, SupportedLanguage, Translations, UserDetailsItem, UserDetailsStoredResponse, UserProfile };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE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m.js
CHANGED
|
@@ -401,13 +401,129 @@ function getAccessTokenFromAuth(auth) {
|
|
|
401
401
|
auth.token;
|
|
402
402
|
return typeof token === "string" && token.length > 0 ? token : undefined;
|
|
403
403
|
}
|
|
404
|
-
|
|
404
|
+
/** True if string looks like a JWT (three base64 parts) or a bearer token, not JSON. */
|
|
405
|
+
function looksLikeToken(s) {
|
|
406
|
+
return s.length > 0 && !s.trimStart().startsWith("{") && !s.trimStart().startsWith("[");
|
|
407
|
+
}
|
|
408
|
+
/** Recursively find first string value at keys accessToken, access_token, or token. */
|
|
409
|
+
function findTokenInObject(obj) {
|
|
410
|
+
if (obj === null || obj === undefined)
|
|
411
|
+
return undefined;
|
|
412
|
+
if (typeof obj === "string")
|
|
413
|
+
return looksLikeToken(obj) ? obj : undefined;
|
|
414
|
+
if (typeof obj !== "object")
|
|
415
|
+
return undefined;
|
|
416
|
+
const rec = obj;
|
|
417
|
+
const direct = rec.accessToken ?? rec.access_token ?? rec.token;
|
|
418
|
+
if (typeof direct === "string" && looksLikeToken(direct))
|
|
419
|
+
return direct;
|
|
420
|
+
for (const key of Object.keys(rec)) {
|
|
421
|
+
const found = findTokenInObject(rec[key]);
|
|
422
|
+
if (found)
|
|
423
|
+
return found;
|
|
424
|
+
}
|
|
425
|
+
return undefined;
|
|
426
|
+
}
|
|
427
|
+
/** Parse redux-persist style value (may be double stringified). */
|
|
428
|
+
function parsePersistValue(raw) {
|
|
429
|
+
if (!raw)
|
|
430
|
+
return null;
|
|
431
|
+
try {
|
|
432
|
+
const first = JSON.parse(raw);
|
|
433
|
+
if (typeof first === "string") {
|
|
434
|
+
try {
|
|
435
|
+
return JSON.parse(first);
|
|
436
|
+
}
|
|
437
|
+
catch {
|
|
438
|
+
return first;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return first;
|
|
442
|
+
}
|
|
443
|
+
catch {
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
/** Get a nested value that may be a string (need parse) or already an object. */
|
|
448
|
+
function parseNestedValue(val) {
|
|
449
|
+
if (val == null)
|
|
450
|
+
return null;
|
|
451
|
+
if (typeof val === "string")
|
|
452
|
+
return parsePersistValue(val);
|
|
453
|
+
return val;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Extract access token from persist:userdb shape: authDetails (string) → parse → auth.accessToken.
|
|
457
|
+
* Structure: { authDetails: "{\"auth\":{\"accessToken\":\"...\"}}", profileInformation: "...", _persist: "..." }
|
|
458
|
+
*/
|
|
459
|
+
function getTokenFromUserDbPersist(parsed) {
|
|
460
|
+
const authDetails = parsed.authDetails;
|
|
461
|
+
const inner = parseNestedValue(authDetails);
|
|
462
|
+
const obj = typeof inner === "object" && inner !== null ? inner : null;
|
|
463
|
+
if (!obj)
|
|
464
|
+
return undefined;
|
|
465
|
+
const auth = obj.auth;
|
|
466
|
+
const authObj = typeof auth === "object" && auth !== null ? auth : null;
|
|
467
|
+
if (!authObj)
|
|
468
|
+
return undefined;
|
|
469
|
+
const token = authObj.accessToken ??
|
|
470
|
+
authObj.access_token ??
|
|
471
|
+
authObj.token;
|
|
472
|
+
return typeof token === "string" && looksLikeToken(token) ? token : undefined;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Get access token from all known storage keys (header, IAM, userdb, and plain keys).
|
|
476
|
+
* persist:userdb shape: authDetails (stringified) contains auth.accessToken.
|
|
477
|
+
*/
|
|
478
|
+
function getAccessTokenForRequest() {
|
|
479
|
+
const keysToTry = [
|
|
480
|
+
PERSIST_HEADER_KEY,
|
|
481
|
+
"persist:linn-i-am",
|
|
482
|
+
"persist:userdb",
|
|
483
|
+
"token",
|
|
484
|
+
"accessToken",
|
|
485
|
+
"auth",
|
|
486
|
+
];
|
|
487
|
+
for (const key of keysToTry) {
|
|
488
|
+
const raw = localStorage.getItem(key);
|
|
489
|
+
if (!raw)
|
|
490
|
+
continue;
|
|
491
|
+
const parsed = key.startsWith("persist:") ? parsePersistValue(raw) : (() => { try {
|
|
492
|
+
return JSON.parse(raw);
|
|
493
|
+
}
|
|
494
|
+
catch {
|
|
495
|
+
return raw;
|
|
496
|
+
} })();
|
|
497
|
+
const token = findTokenInObject(parsed);
|
|
498
|
+
if (token)
|
|
499
|
+
return token;
|
|
500
|
+
if (key.startsWith("persist:")) {
|
|
501
|
+
const outer = typeof parsed === "object" && parsed !== null ? parsed : null;
|
|
502
|
+
if (outer) {
|
|
503
|
+
if (key === "persist:userdb") {
|
|
504
|
+
const fromUserDb = getTokenFromUserDbPersist(outer);
|
|
505
|
+
if (fromUserDb)
|
|
506
|
+
return fromUserDb;
|
|
507
|
+
}
|
|
508
|
+
for (const k of Object.keys(outer)) {
|
|
509
|
+
const inner = parseNestedValue(outer[k]);
|
|
510
|
+
const t = findTokenInObject(inner);
|
|
511
|
+
if (t)
|
|
512
|
+
return t;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return getAccessTokenFromAuth(getAllDataFromStorage().auth);
|
|
518
|
+
}
|
|
519
|
+
const fetchProfilePictureAsBlobUrl = async (baseUrl = "http://objectstore.impact0mics.local:9012", accessTokenOverride) => {
|
|
405
520
|
try {
|
|
406
521
|
const profilePictureUrl = getProfilePictureUrl(baseUrl);
|
|
407
522
|
if (!profilePictureUrl)
|
|
408
523
|
return null;
|
|
409
|
-
const
|
|
410
|
-
|
|
524
|
+
const accessToken = (typeof accessTokenOverride === "string" && accessTokenOverride.length > 0
|
|
525
|
+
? accessTokenOverride
|
|
526
|
+
: null) ?? getAccessTokenForRequest();
|
|
411
527
|
const headers = {};
|
|
412
528
|
if (accessToken) {
|
|
413
529
|
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
@@ -543,7 +659,7 @@ const DEFAULT_ROUTES = {
|
|
|
543
659
|
profile: "/user/profile",
|
|
544
660
|
logout: "/user/login",
|
|
545
661
|
};
|
|
546
|
-
const AppHeader = ({ language: languageProp }) => {
|
|
662
|
+
const AppHeader = ({ language: languageProp, accessToken: accessTokenProp }) => {
|
|
547
663
|
// Get initial language from props, URL, localStorage, or default to 'en'
|
|
548
664
|
const getInitialLanguage = () => {
|
|
549
665
|
// Priority 1: Props
|
|
@@ -640,12 +756,18 @@ const AppHeader = ({ language: languageProp }) => {
|
|
|
640
756
|
userRole = userRole || profileData.role || profileData.userRole || "";
|
|
641
757
|
}
|
|
642
758
|
}
|
|
759
|
+
const avatarSrc = storedUser?.avatar ??
|
|
760
|
+
allData.auth?.avatar ??
|
|
761
|
+
allData.profile?.avatar;
|
|
762
|
+
const initialsVal = storedUser?.initials ??
|
|
763
|
+
allData.auth?.initials ??
|
|
764
|
+
allData.profile?.initials;
|
|
643
765
|
return {
|
|
644
766
|
name: userName || "",
|
|
645
767
|
email: userEmail || "",
|
|
646
768
|
role: userRole || "",
|
|
647
|
-
avatar:
|
|
648
|
-
initials:
|
|
769
|
+
avatar: typeof avatarSrc === "string" ? avatarSrc : undefined,
|
|
770
|
+
initials: typeof initialsVal === "string" ? initialsVal : undefined,
|
|
649
771
|
};
|
|
650
772
|
});
|
|
651
773
|
const [notificationCount, setNotificationCount] = React__default.useState(() => {
|
|
@@ -660,8 +782,8 @@ const AppHeader = ({ language: languageProp }) => {
|
|
|
660
782
|
// Fetch profile picture from API when component mounts or user data changes
|
|
661
783
|
React__default.useEffect(() => {
|
|
662
784
|
const fetchProfilePicture = async () => {
|
|
663
|
-
|
|
664
|
-
const blobUrl = await fetchProfilePictureAsBlobUrl();
|
|
785
|
+
const token = accessTokenProp ?? getAccessTokenForRequest();
|
|
786
|
+
const blobUrl = await fetchProfilePictureAsBlobUrl(undefined, token ?? undefined);
|
|
665
787
|
if (blobUrl) {
|
|
666
788
|
// Clean up previous blob URL if it exists
|
|
667
789
|
setProfilePictureBlobUrl((prevUrl) => {
|
|
@@ -682,7 +804,7 @@ const AppHeader = ({ language: languageProp }) => {
|
|
|
682
804
|
return null;
|
|
683
805
|
});
|
|
684
806
|
};
|
|
685
|
-
}, []); //
|
|
807
|
+
}, [accessTokenProp]); // Refetch when accessToken prop changes (e.g. after login)
|
|
686
808
|
React__default.useEffect(() => {
|
|
687
809
|
const allData = getAllDataFromStorage();
|
|
688
810
|
let userName = "";
|
|
@@ -1014,5 +1136,5 @@ const AppHeader = ({ language: languageProp }) => {
|
|
|
1014
1136
|
}, children: jsx(MoreIcon, {}) }) })] }) }), renderMobileMenu, renderMenu] }));
|
|
1015
1137
|
};
|
|
1016
1138
|
|
|
1017
|
-
export { AppHeader, DrawerProvider, PERSIST_HEADER_KEY, USER_DETAILS_STORAGE_KEY, fetchProfilePictureAsBlobUrl, getAllDataFromStorage, getI18nLocaleFromStorage, getMessageCountFromStorage, getNotificationCountFromStorage, getProfilePictureUrl, getStoredUserDetails, getTranslations, getUserDataFromStorage, setHeaderAuth, setI18nLocaleToStorage, translations, useDrawer };
|
|
1139
|
+
export { AppHeader, DrawerProvider, PERSIST_HEADER_KEY, USER_DETAILS_STORAGE_KEY, fetchProfilePictureAsBlobUrl, getAccessTokenForRequest, getAllDataFromStorage, getI18nLocaleFromStorage, getMessageCountFromStorage, getNotificationCountFromStorage, getProfilePictureUrl, getStoredUserDetails, getTranslations, getUserDataFromStorage, setHeaderAuth, setI18nLocaleToStorage, translations, useDrawer };
|
|
1018
1140
|
//# sourceMappingURL=index.esm.js.map
|