@cupcodev/ui 1.2.4 → 1.2.52
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.cjs +101 -6
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +101 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -22563,8 +22563,22 @@ var buildHandle2 = (value, email, fallbackId) => {
|
|
|
22563
22563
|
var resolveCurrentUserId = (user) => {
|
|
22564
22564
|
const sub = toStringOrUndefined(user == null ? void 0 : user.sub);
|
|
22565
22565
|
if (sub) return sub;
|
|
22566
|
+
const id = toStringOrUndefined(user == null ? void 0 : user.id);
|
|
22567
|
+
if (id) return id;
|
|
22568
|
+
const userId = toStringOrUndefined(user == null ? void 0 : user.userId);
|
|
22569
|
+
if (userId) return userId;
|
|
22566
22570
|
return null;
|
|
22567
22571
|
};
|
|
22572
|
+
var resolveUserIdFromClaims = (claims) => {
|
|
22573
|
+
var _a65, _b5, _c, _d, _e;
|
|
22574
|
+
return (_e = (_d = (_c = (_b5 = (_a65 = toStringOrUndefined(claims.sub)) != null ? _a65 : toStringOrUndefined(claims.user_id)) != null ? _b5 : toStringOrUndefined(claims.userId)) != null ? _c : toStringOrUndefined(claims.uid)) != null ? _d : toStringOrUndefined(claims.id)) != null ? _e : toStringOrUndefined(claims["https://cupcode.com/user_id"]);
|
|
22575
|
+
};
|
|
22576
|
+
var resolveEmailFromClaims = (claims) => {
|
|
22577
|
+
var _a65, _b5;
|
|
22578
|
+
const candidate = (_b5 = (_a65 = toStringOrUndefined(claims.email)) != null ? _a65 : toStringOrUndefined(claims["https://cupcode.com/email"])) != null ? _b5 : toStringOrUndefined(claims.preferred_username);
|
|
22579
|
+
if (!candidate || !candidate.includes("@")) return void 0;
|
|
22580
|
+
return candidate.toLowerCase();
|
|
22581
|
+
};
|
|
22568
22582
|
var formatMessageTime = (rawTimestamp) => {
|
|
22569
22583
|
if (!rawTimestamp) return "";
|
|
22570
22584
|
const parsed = new Date(rawTimestamp);
|
|
@@ -22829,7 +22843,7 @@ var MainNavbar = ({
|
|
|
22829
22843
|
ctaHref = "/login",
|
|
22830
22844
|
pathname,
|
|
22831
22845
|
onNavigate,
|
|
22832
|
-
authStatus
|
|
22846
|
+
authStatus,
|
|
22833
22847
|
authUser,
|
|
22834
22848
|
presenceStatus,
|
|
22835
22849
|
onPresenceStatusChange,
|
|
@@ -22846,6 +22860,8 @@ var MainNavbar = ({
|
|
|
22846
22860
|
const [isChatSending, setIsChatSending] = (0, import_react19.useState)(false);
|
|
22847
22861
|
const [chatError, setChatError] = (0, import_react19.useState)(null);
|
|
22848
22862
|
const [resolvedSenderId, setResolvedSenderId] = (0, import_react19.useState)(null);
|
|
22863
|
+
const [tokenDerivedUserId, setTokenDerivedUserId] = (0, import_react19.useState)(null);
|
|
22864
|
+
const [tokenDerivedEmail, setTokenDerivedEmail] = (0, import_react19.useState)(void 0);
|
|
22849
22865
|
const [persistedProfileAvatarValue, setPersistedProfileAvatarValue] = (0, import_react19.useState)(void 0);
|
|
22850
22866
|
const [accountsLanguage, setAccountsLanguage] = (0, import_react19.useState)("pt-BR");
|
|
22851
22867
|
const [accountsRecentActivity, setAccountsRecentActivity] = (0, import_react19.useState)([]);
|
|
@@ -22865,8 +22881,17 @@ var MainNavbar = ({
|
|
|
22865
22881
|
if (typeof window !== "undefined") return window.location.pathname || "/";
|
|
22866
22882
|
return "/";
|
|
22867
22883
|
}, [pathname]);
|
|
22868
|
-
const currentUserId = (0, import_react19.useMemo)(() =>
|
|
22869
|
-
|
|
22884
|
+
const currentUserId = (0, import_react19.useMemo)(() => {
|
|
22885
|
+
var _a66;
|
|
22886
|
+
return (_a66 = resolveCurrentUserId(authUser)) != null ? _a66 : tokenDerivedUserId;
|
|
22887
|
+
}, [authUser, tokenDerivedUserId]);
|
|
22888
|
+
const authEmail = (0, import_react19.useMemo)(
|
|
22889
|
+
() => {
|
|
22890
|
+
var _a66, _b6;
|
|
22891
|
+
return (_b6 = (_a66 = toStringOrUndefined(authUser == null ? void 0 : authUser.email)) == null ? void 0 : _a66.toLowerCase()) != null ? _b6 : tokenDerivedEmail;
|
|
22892
|
+
},
|
|
22893
|
+
[authUser == null ? void 0 : authUser.email, tokenDerivedEmail]
|
|
22894
|
+
);
|
|
22870
22895
|
const isChatSuperAdmin = (0, import_react19.useMemo)(() => {
|
|
22871
22896
|
var _a66, _b6;
|
|
22872
22897
|
const roleTokens = `${(_a66 = authUser == null ? void 0 : authUser.role) != null ? _a66 : ""} ${(_b6 = authUser == null ? void 0 : authUser.jobTitle) != null ? _b6 : ""}`.toLowerCase();
|
|
@@ -22880,7 +22905,77 @@ var MainNavbar = ({
|
|
|
22880
22905
|
}, []);
|
|
22881
22906
|
const resolvedProfileAvatarUrl = (_b5 = (_a65 = resolveChatAvatarUrl(persistedProfileAvatarValue)) != null ? _a65 : authUser == null ? void 0 : authUser.picture) != null ? _b5 : void 0;
|
|
22882
22907
|
const effectiveCurrentUserId = resolvedSenderId != null ? resolvedSenderId : currentUserId;
|
|
22883
|
-
const
|
|
22908
|
+
const hasStoredAccessToken = (() => {
|
|
22909
|
+
if (typeof window === "undefined") return false;
|
|
22910
|
+
try {
|
|
22911
|
+
return Boolean(sessionStorage.getItem(ACCESS_TOKEN_STORAGE_KEY));
|
|
22912
|
+
} catch (e) {
|
|
22913
|
+
return false;
|
|
22914
|
+
}
|
|
22915
|
+
})();
|
|
22916
|
+
const resolvedAuthStatus = (0, import_react19.useMemo)(() => {
|
|
22917
|
+
if (authStatus) return authStatus;
|
|
22918
|
+
if ((authUser == null ? void 0 : authUser.sub) || (authUser == null ? void 0 : authUser.id) || (authUser == null ? void 0 : authUser.userId) || (authUser == null ? void 0 : authUser.email)) {
|
|
22919
|
+
return "authenticated";
|
|
22920
|
+
}
|
|
22921
|
+
if (tokenDerivedUserId || tokenDerivedEmail || hasStoredAccessToken) {
|
|
22922
|
+
return "authenticated";
|
|
22923
|
+
}
|
|
22924
|
+
return "unauthenticated";
|
|
22925
|
+
}, [
|
|
22926
|
+
authStatus,
|
|
22927
|
+
authUser == null ? void 0 : authUser.email,
|
|
22928
|
+
authUser == null ? void 0 : authUser.id,
|
|
22929
|
+
authUser == null ? void 0 : authUser.sub,
|
|
22930
|
+
authUser == null ? void 0 : authUser.userId,
|
|
22931
|
+
hasStoredAccessToken,
|
|
22932
|
+
tokenDerivedEmail,
|
|
22933
|
+
tokenDerivedUserId
|
|
22934
|
+
]);
|
|
22935
|
+
const isAuthenticated = resolvedAuthStatus === "authenticated";
|
|
22936
|
+
(0, import_react19.useEffect)(() => {
|
|
22937
|
+
if (authStatus === "unauthenticated") {
|
|
22938
|
+
setTokenDerivedUserId(null);
|
|
22939
|
+
setTokenDerivedEmail(void 0);
|
|
22940
|
+
return;
|
|
22941
|
+
}
|
|
22942
|
+
let canceled = false;
|
|
22943
|
+
const resolveIdentityFromToken = async () => {
|
|
22944
|
+
var _a66, _b6;
|
|
22945
|
+
try {
|
|
22946
|
+
let token = null;
|
|
22947
|
+
if (typeof window !== "undefined") {
|
|
22948
|
+
try {
|
|
22949
|
+
token = sessionStorage.getItem(ACCESS_TOKEN_STORAGE_KEY);
|
|
22950
|
+
} catch (e) {
|
|
22951
|
+
token = null;
|
|
22952
|
+
}
|
|
22953
|
+
}
|
|
22954
|
+
if (!token && getAccessToken) {
|
|
22955
|
+
token = await getAccessToken();
|
|
22956
|
+
}
|
|
22957
|
+
if (!token) {
|
|
22958
|
+
if (!canceled) {
|
|
22959
|
+
setTokenDerivedUserId(null);
|
|
22960
|
+
setTokenDerivedEmail(void 0);
|
|
22961
|
+
}
|
|
22962
|
+
return;
|
|
22963
|
+
}
|
|
22964
|
+
const claims = (_a66 = decodeJwt(token)) != null ? _a66 : {};
|
|
22965
|
+
if (canceled) return;
|
|
22966
|
+
setTokenDerivedUserId((_b6 = resolveUserIdFromClaims(claims)) != null ? _b6 : null);
|
|
22967
|
+
setTokenDerivedEmail(resolveEmailFromClaims(claims));
|
|
22968
|
+
} catch (error) {
|
|
22969
|
+
if (isRuntimeDev()) {
|
|
22970
|
+
console.warn("[chat] Falha ao resolver identidade via access token:", error.message);
|
|
22971
|
+
}
|
|
22972
|
+
}
|
|
22973
|
+
};
|
|
22974
|
+
void resolveIdentityFromToken();
|
|
22975
|
+
return () => {
|
|
22976
|
+
canceled = true;
|
|
22977
|
+
};
|
|
22978
|
+
}, [authStatus, getAccessToken]);
|
|
22884
22979
|
(0, import_react19.useEffect)(() => {
|
|
22885
22980
|
if (!isAuthenticated) {
|
|
22886
22981
|
setResolvedSenderId(null);
|
|
@@ -24241,8 +24336,8 @@ var MainNavbar = ({
|
|
|
24241
24336
|
actions: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
|
|
24242
24337
|
UserMenuCupcode,
|
|
24243
24338
|
{
|
|
24244
|
-
isAuthenticated:
|
|
24245
|
-
isLoading:
|
|
24339
|
+
isAuthenticated: resolvedAuthStatus === "authenticated",
|
|
24340
|
+
isLoading: resolvedAuthStatus === "loading",
|
|
24246
24341
|
loginLabel: ctaLabel,
|
|
24247
24342
|
displayName: authUser == null ? void 0 : authUser.name,
|
|
24248
24343
|
username: (_c = authUser == null ? void 0 : authUser.preferredUsername) != null ? _c : authUser == null ? void 0 : authUser.nickname,
|
package/dist/index.d.cts
CHANGED
|
@@ -442,6 +442,8 @@ declare const UserMenuCupcode: React.FC<UserMenuCupcodeProps>;
|
|
|
442
442
|
type MainNavbarAuthStatus = "loading" | "authenticated" | "unauthenticated";
|
|
443
443
|
type MainNavbarAuthUser = {
|
|
444
444
|
sub?: string;
|
|
445
|
+
id?: string;
|
|
446
|
+
userId?: string;
|
|
445
447
|
name?: string;
|
|
446
448
|
email?: string;
|
|
447
449
|
picture?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -442,6 +442,8 @@ declare const UserMenuCupcode: React.FC<UserMenuCupcodeProps>;
|
|
|
442
442
|
type MainNavbarAuthStatus = "loading" | "authenticated" | "unauthenticated";
|
|
443
443
|
type MainNavbarAuthUser = {
|
|
444
444
|
sub?: string;
|
|
445
|
+
id?: string;
|
|
446
|
+
userId?: string;
|
|
445
447
|
name?: string;
|
|
446
448
|
email?: string;
|
|
447
449
|
picture?: string;
|
package/dist/index.js
CHANGED
|
@@ -22222,8 +22222,22 @@ var buildHandle2 = (value, email, fallbackId) => {
|
|
|
22222
22222
|
var resolveCurrentUserId = (user) => {
|
|
22223
22223
|
const sub = toStringOrUndefined(user == null ? void 0 : user.sub);
|
|
22224
22224
|
if (sub) return sub;
|
|
22225
|
+
const id = toStringOrUndefined(user == null ? void 0 : user.id);
|
|
22226
|
+
if (id) return id;
|
|
22227
|
+
const userId = toStringOrUndefined(user == null ? void 0 : user.userId);
|
|
22228
|
+
if (userId) return userId;
|
|
22225
22229
|
return null;
|
|
22226
22230
|
};
|
|
22231
|
+
var resolveUserIdFromClaims = (claims) => {
|
|
22232
|
+
var _a65, _b5, _c, _d, _e;
|
|
22233
|
+
return (_e = (_d = (_c = (_b5 = (_a65 = toStringOrUndefined(claims.sub)) != null ? _a65 : toStringOrUndefined(claims.user_id)) != null ? _b5 : toStringOrUndefined(claims.userId)) != null ? _c : toStringOrUndefined(claims.uid)) != null ? _d : toStringOrUndefined(claims.id)) != null ? _e : toStringOrUndefined(claims["https://cupcode.com/user_id"]);
|
|
22234
|
+
};
|
|
22235
|
+
var resolveEmailFromClaims = (claims) => {
|
|
22236
|
+
var _a65, _b5;
|
|
22237
|
+
const candidate = (_b5 = (_a65 = toStringOrUndefined(claims.email)) != null ? _a65 : toStringOrUndefined(claims["https://cupcode.com/email"])) != null ? _b5 : toStringOrUndefined(claims.preferred_username);
|
|
22238
|
+
if (!candidate || !candidate.includes("@")) return void 0;
|
|
22239
|
+
return candidate.toLowerCase();
|
|
22240
|
+
};
|
|
22227
22241
|
var formatMessageTime = (rawTimestamp) => {
|
|
22228
22242
|
if (!rawTimestamp) return "";
|
|
22229
22243
|
const parsed = new Date(rawTimestamp);
|
|
@@ -22488,7 +22502,7 @@ var MainNavbar = ({
|
|
|
22488
22502
|
ctaHref = "/login",
|
|
22489
22503
|
pathname,
|
|
22490
22504
|
onNavigate,
|
|
22491
|
-
authStatus
|
|
22505
|
+
authStatus,
|
|
22492
22506
|
authUser,
|
|
22493
22507
|
presenceStatus,
|
|
22494
22508
|
onPresenceStatusChange,
|
|
@@ -22505,6 +22519,8 @@ var MainNavbar = ({
|
|
|
22505
22519
|
const [isChatSending, setIsChatSending] = useState13(false);
|
|
22506
22520
|
const [chatError, setChatError] = useState13(null);
|
|
22507
22521
|
const [resolvedSenderId, setResolvedSenderId] = useState13(null);
|
|
22522
|
+
const [tokenDerivedUserId, setTokenDerivedUserId] = useState13(null);
|
|
22523
|
+
const [tokenDerivedEmail, setTokenDerivedEmail] = useState13(void 0);
|
|
22508
22524
|
const [persistedProfileAvatarValue, setPersistedProfileAvatarValue] = useState13(void 0);
|
|
22509
22525
|
const [accountsLanguage, setAccountsLanguage] = useState13("pt-BR");
|
|
22510
22526
|
const [accountsRecentActivity, setAccountsRecentActivity] = useState13([]);
|
|
@@ -22524,8 +22540,17 @@ var MainNavbar = ({
|
|
|
22524
22540
|
if (typeof window !== "undefined") return window.location.pathname || "/";
|
|
22525
22541
|
return "/";
|
|
22526
22542
|
}, [pathname]);
|
|
22527
|
-
const currentUserId = useMemo8(() =>
|
|
22528
|
-
|
|
22543
|
+
const currentUserId = useMemo8(() => {
|
|
22544
|
+
var _a66;
|
|
22545
|
+
return (_a66 = resolveCurrentUserId(authUser)) != null ? _a66 : tokenDerivedUserId;
|
|
22546
|
+
}, [authUser, tokenDerivedUserId]);
|
|
22547
|
+
const authEmail = useMemo8(
|
|
22548
|
+
() => {
|
|
22549
|
+
var _a66, _b6;
|
|
22550
|
+
return (_b6 = (_a66 = toStringOrUndefined(authUser == null ? void 0 : authUser.email)) == null ? void 0 : _a66.toLowerCase()) != null ? _b6 : tokenDerivedEmail;
|
|
22551
|
+
},
|
|
22552
|
+
[authUser == null ? void 0 : authUser.email, tokenDerivedEmail]
|
|
22553
|
+
);
|
|
22529
22554
|
const isChatSuperAdmin = useMemo8(() => {
|
|
22530
22555
|
var _a66, _b6;
|
|
22531
22556
|
const roleTokens = `${(_a66 = authUser == null ? void 0 : authUser.role) != null ? _a66 : ""} ${(_b6 = authUser == null ? void 0 : authUser.jobTitle) != null ? _b6 : ""}`.toLowerCase();
|
|
@@ -22539,7 +22564,77 @@ var MainNavbar = ({
|
|
|
22539
22564
|
}, []);
|
|
22540
22565
|
const resolvedProfileAvatarUrl = (_b5 = (_a65 = resolveChatAvatarUrl(persistedProfileAvatarValue)) != null ? _a65 : authUser == null ? void 0 : authUser.picture) != null ? _b5 : void 0;
|
|
22541
22566
|
const effectiveCurrentUserId = resolvedSenderId != null ? resolvedSenderId : currentUserId;
|
|
22542
|
-
const
|
|
22567
|
+
const hasStoredAccessToken = (() => {
|
|
22568
|
+
if (typeof window === "undefined") return false;
|
|
22569
|
+
try {
|
|
22570
|
+
return Boolean(sessionStorage.getItem(ACCESS_TOKEN_STORAGE_KEY));
|
|
22571
|
+
} catch (e) {
|
|
22572
|
+
return false;
|
|
22573
|
+
}
|
|
22574
|
+
})();
|
|
22575
|
+
const resolvedAuthStatus = useMemo8(() => {
|
|
22576
|
+
if (authStatus) return authStatus;
|
|
22577
|
+
if ((authUser == null ? void 0 : authUser.sub) || (authUser == null ? void 0 : authUser.id) || (authUser == null ? void 0 : authUser.userId) || (authUser == null ? void 0 : authUser.email)) {
|
|
22578
|
+
return "authenticated";
|
|
22579
|
+
}
|
|
22580
|
+
if (tokenDerivedUserId || tokenDerivedEmail || hasStoredAccessToken) {
|
|
22581
|
+
return "authenticated";
|
|
22582
|
+
}
|
|
22583
|
+
return "unauthenticated";
|
|
22584
|
+
}, [
|
|
22585
|
+
authStatus,
|
|
22586
|
+
authUser == null ? void 0 : authUser.email,
|
|
22587
|
+
authUser == null ? void 0 : authUser.id,
|
|
22588
|
+
authUser == null ? void 0 : authUser.sub,
|
|
22589
|
+
authUser == null ? void 0 : authUser.userId,
|
|
22590
|
+
hasStoredAccessToken,
|
|
22591
|
+
tokenDerivedEmail,
|
|
22592
|
+
tokenDerivedUserId
|
|
22593
|
+
]);
|
|
22594
|
+
const isAuthenticated = resolvedAuthStatus === "authenticated";
|
|
22595
|
+
useEffect16(() => {
|
|
22596
|
+
if (authStatus === "unauthenticated") {
|
|
22597
|
+
setTokenDerivedUserId(null);
|
|
22598
|
+
setTokenDerivedEmail(void 0);
|
|
22599
|
+
return;
|
|
22600
|
+
}
|
|
22601
|
+
let canceled = false;
|
|
22602
|
+
const resolveIdentityFromToken = async () => {
|
|
22603
|
+
var _a66, _b6;
|
|
22604
|
+
try {
|
|
22605
|
+
let token = null;
|
|
22606
|
+
if (typeof window !== "undefined") {
|
|
22607
|
+
try {
|
|
22608
|
+
token = sessionStorage.getItem(ACCESS_TOKEN_STORAGE_KEY);
|
|
22609
|
+
} catch (e) {
|
|
22610
|
+
token = null;
|
|
22611
|
+
}
|
|
22612
|
+
}
|
|
22613
|
+
if (!token && getAccessToken) {
|
|
22614
|
+
token = await getAccessToken();
|
|
22615
|
+
}
|
|
22616
|
+
if (!token) {
|
|
22617
|
+
if (!canceled) {
|
|
22618
|
+
setTokenDerivedUserId(null);
|
|
22619
|
+
setTokenDerivedEmail(void 0);
|
|
22620
|
+
}
|
|
22621
|
+
return;
|
|
22622
|
+
}
|
|
22623
|
+
const claims = (_a66 = decodeJwt(token)) != null ? _a66 : {};
|
|
22624
|
+
if (canceled) return;
|
|
22625
|
+
setTokenDerivedUserId((_b6 = resolveUserIdFromClaims(claims)) != null ? _b6 : null);
|
|
22626
|
+
setTokenDerivedEmail(resolveEmailFromClaims(claims));
|
|
22627
|
+
} catch (error) {
|
|
22628
|
+
if (isRuntimeDev()) {
|
|
22629
|
+
console.warn("[chat] Falha ao resolver identidade via access token:", error.message);
|
|
22630
|
+
}
|
|
22631
|
+
}
|
|
22632
|
+
};
|
|
22633
|
+
void resolveIdentityFromToken();
|
|
22634
|
+
return () => {
|
|
22635
|
+
canceled = true;
|
|
22636
|
+
};
|
|
22637
|
+
}, [authStatus, getAccessToken]);
|
|
22543
22638
|
useEffect16(() => {
|
|
22544
22639
|
if (!isAuthenticated) {
|
|
22545
22640
|
setResolvedSenderId(null);
|
|
@@ -23900,8 +23995,8 @@ var MainNavbar = ({
|
|
|
23900
23995
|
actions: /* @__PURE__ */ jsx45("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsx45(
|
|
23901
23996
|
UserMenuCupcode,
|
|
23902
23997
|
{
|
|
23903
|
-
isAuthenticated:
|
|
23904
|
-
isLoading:
|
|
23998
|
+
isAuthenticated: resolvedAuthStatus === "authenticated",
|
|
23999
|
+
isLoading: resolvedAuthStatus === "loading",
|
|
23905
24000
|
loginLabel: ctaLabel,
|
|
23906
24001
|
displayName: authUser == null ? void 0 : authUser.name,
|
|
23907
24002
|
username: (_c = authUser == null ? void 0 : authUser.preferredUsername) != null ? _c : authUser == null ? void 0 : authUser.nickname,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cupcodev/ui",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.52",
|
|
5
5
|
"packageManager": "pnpm@10.28.2+sha512.41872f037ad22f7348e3b1debbaf7e867cfd448f2726d9cf74c08f19507c31d2c8e7a11525b983febc2df640b5438dee6023ebb1f84ed43cc2d654d2bc326264",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs",
|