analytica-frontend-lib 1.1.92 → 1.1.93
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.d.mts +181 -3
- package/dist/index.d.ts +181 -3
- package/dist/index.js +320 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +315 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -9879,7 +9879,7 @@ var HeaderAlternative = forwardRef19(
|
|
|
9879
9879
|
);
|
|
9880
9880
|
|
|
9881
9881
|
// src/components/Auth/zustandAuthAdapter.ts
|
|
9882
|
-
function createZustandAuthAdapter(
|
|
9882
|
+
function createZustandAuthAdapter(useAuthStore2) {
|
|
9883
9883
|
return {
|
|
9884
9884
|
/**
|
|
9885
9885
|
* Check if the user is authenticated based on sessionInfo and tokens
|
|
@@ -9887,7 +9887,7 @@ function createZustandAuthAdapter(useAuthStore) {
|
|
|
9887
9887
|
* @returns {Promise<boolean>} Promise that resolves to authentication status
|
|
9888
9888
|
*/
|
|
9889
9889
|
checkAuth: async () => {
|
|
9890
|
-
const { sessionInfo, tokens } =
|
|
9890
|
+
const { sessionInfo, tokens } = useAuthStore2.getState();
|
|
9891
9891
|
return Boolean(sessionInfo && tokens);
|
|
9892
9892
|
},
|
|
9893
9893
|
/**
|
|
@@ -9895,26 +9895,26 @@ function createZustandAuthAdapter(useAuthStore) {
|
|
|
9895
9895
|
*
|
|
9896
9896
|
* @returns {unknown} Current user data from the store
|
|
9897
9897
|
*/
|
|
9898
|
-
getUser: () =>
|
|
9898
|
+
getUser: () => useAuthStore2.getState().user,
|
|
9899
9899
|
/**
|
|
9900
9900
|
* Get the current session information from the store
|
|
9901
9901
|
*
|
|
9902
9902
|
* @returns {unknown} Current session info from the store
|
|
9903
9903
|
*/
|
|
9904
|
-
getSessionInfo: () =>
|
|
9904
|
+
getSessionInfo: () => useAuthStore2.getState().sessionInfo,
|
|
9905
9905
|
/**
|
|
9906
9906
|
* Get the current authentication tokens from the store
|
|
9907
9907
|
*
|
|
9908
9908
|
* @returns {unknown} Current tokens from the store
|
|
9909
9909
|
*/
|
|
9910
|
-
getTokens: () =>
|
|
9910
|
+
getTokens: () => useAuthStore2.getState().tokens,
|
|
9911
9911
|
/**
|
|
9912
9912
|
* Sign out the user by calling the store's signOut function if available
|
|
9913
9913
|
*
|
|
9914
9914
|
* @returns {void}
|
|
9915
9915
|
*/
|
|
9916
9916
|
signOut: () => {
|
|
9917
|
-
const signOutFn =
|
|
9917
|
+
const signOutFn = useAuthStore2.getState().signOut;
|
|
9918
9918
|
if (typeof signOutFn === "function") signOutFn();
|
|
9919
9919
|
}
|
|
9920
9920
|
};
|
|
@@ -12485,6 +12485,310 @@ var QuizListResultByMateria = ({
|
|
|
12485
12485
|
] })
|
|
12486
12486
|
] });
|
|
12487
12487
|
};
|
|
12488
|
+
|
|
12489
|
+
// src/hooks/useAppInitialization.ts
|
|
12490
|
+
import { useMemo as useMemo7 } from "react";
|
|
12491
|
+
|
|
12492
|
+
// src/hooks/useInstitution.ts
|
|
12493
|
+
import { useEffect as useEffect22, useState as useState23 } from "react";
|
|
12494
|
+
function useInstitutionId() {
|
|
12495
|
+
const [institutionId, setInstitutionId] = useState23(() => {
|
|
12496
|
+
return document.querySelector('meta[name="institution-id"]')?.getAttribute("content") ?? null;
|
|
12497
|
+
});
|
|
12498
|
+
useEffect22(() => {
|
|
12499
|
+
const metaTag = document.querySelector('meta[name="institution-id"]');
|
|
12500
|
+
if (!metaTag) return;
|
|
12501
|
+
const observer = new MutationObserver(() => {
|
|
12502
|
+
const newValue = metaTag.getAttribute("content");
|
|
12503
|
+
setInstitutionId(newValue);
|
|
12504
|
+
});
|
|
12505
|
+
observer.observe(metaTag, {
|
|
12506
|
+
attributes: true,
|
|
12507
|
+
attributeFilter: ["content"]
|
|
12508
|
+
});
|
|
12509
|
+
return () => observer.disconnect();
|
|
12510
|
+
}, []);
|
|
12511
|
+
return institutionId;
|
|
12512
|
+
}
|
|
12513
|
+
|
|
12514
|
+
// src/store/appStore.ts
|
|
12515
|
+
import { create as create10 } from "zustand";
|
|
12516
|
+
import { createJSONStorage, persist as persist2 } from "zustand/middleware";
|
|
12517
|
+
var useAppStore = create10()(
|
|
12518
|
+
persist2(
|
|
12519
|
+
(set, get) => ({
|
|
12520
|
+
institutionId: null,
|
|
12521
|
+
initialized: false,
|
|
12522
|
+
/**
|
|
12523
|
+
* Set the institution ID
|
|
12524
|
+
* @param {string | null} institutionId - The institution ID from meta tag
|
|
12525
|
+
* @returns {void}
|
|
12526
|
+
*/
|
|
12527
|
+
setInstitutionId: (institutionId) => {
|
|
12528
|
+
set({ institutionId });
|
|
12529
|
+
},
|
|
12530
|
+
/**
|
|
12531
|
+
* Set the initialized state
|
|
12532
|
+
* @param {boolean} initialized - Whether the app has been initialized
|
|
12533
|
+
* @returns {void}
|
|
12534
|
+
*/
|
|
12535
|
+
setInitialized: (initialized) => {
|
|
12536
|
+
set({ initialized });
|
|
12537
|
+
},
|
|
12538
|
+
/**
|
|
12539
|
+
* Initialize the app by reading the institution ID from meta tag
|
|
12540
|
+
* @returns {void}
|
|
12541
|
+
*/
|
|
12542
|
+
initialize: (id) => {
|
|
12543
|
+
const { initialized } = get();
|
|
12544
|
+
if (initialized) {
|
|
12545
|
+
return;
|
|
12546
|
+
}
|
|
12547
|
+
set({
|
|
12548
|
+
institutionId: id,
|
|
12549
|
+
initialized: true
|
|
12550
|
+
});
|
|
12551
|
+
}
|
|
12552
|
+
}),
|
|
12553
|
+
{
|
|
12554
|
+
name: "@app-storage:analytica:v2" /* APP_STORAGE */,
|
|
12555
|
+
storage: createJSONStorage(() => localStorage)
|
|
12556
|
+
}
|
|
12557
|
+
)
|
|
12558
|
+
);
|
|
12559
|
+
|
|
12560
|
+
// src/store/authStore.ts
|
|
12561
|
+
import { create as create11 } from "zustand";
|
|
12562
|
+
import { createJSONStorage as createJSONStorage2, persist as persist3 } from "zustand/middleware";
|
|
12563
|
+
var useAuthStore = create11()(
|
|
12564
|
+
persist3(
|
|
12565
|
+
(set, get) => ({
|
|
12566
|
+
user: null,
|
|
12567
|
+
tokens: null,
|
|
12568
|
+
isAuthenticated: false,
|
|
12569
|
+
profiles: [],
|
|
12570
|
+
selectedProfile: null,
|
|
12571
|
+
sessionInfo: null,
|
|
12572
|
+
/**
|
|
12573
|
+
* Set the current user
|
|
12574
|
+
* @param {User | null} user - The user object or null to clear
|
|
12575
|
+
* @returns {void}
|
|
12576
|
+
*/
|
|
12577
|
+
setUser: (user) => {
|
|
12578
|
+
set({ user, isAuthenticated: !!user });
|
|
12579
|
+
},
|
|
12580
|
+
/**
|
|
12581
|
+
* Set the authentication tokens
|
|
12582
|
+
* @param {AuthTokens | null} tokens - The authentication tokens or null to clear
|
|
12583
|
+
* @returns {void}
|
|
12584
|
+
*/
|
|
12585
|
+
setTokens: (tokens) => {
|
|
12586
|
+
set({ tokens });
|
|
12587
|
+
},
|
|
12588
|
+
/**
|
|
12589
|
+
* Set user profiles
|
|
12590
|
+
* @param {UserProfile[]} profiles - Array of user profiles
|
|
12591
|
+
* @returns {void}
|
|
12592
|
+
*/
|
|
12593
|
+
setProfiles: (profiles) => {
|
|
12594
|
+
set({ profiles });
|
|
12595
|
+
},
|
|
12596
|
+
/**
|
|
12597
|
+
* Set the selected profile
|
|
12598
|
+
* @param {UserProfile | null} profile - The selected profile or null to clear
|
|
12599
|
+
* @returns {void}
|
|
12600
|
+
*/
|
|
12601
|
+
setSelectedProfile: (profile) => {
|
|
12602
|
+
set({ selectedProfile: profile });
|
|
12603
|
+
},
|
|
12604
|
+
/**
|
|
12605
|
+
* Set the session info
|
|
12606
|
+
* @param {SessionInfo | null} sessionInfo - The session info or null to clear
|
|
12607
|
+
* @returns {void}
|
|
12608
|
+
*/
|
|
12609
|
+
setSessionInfo: (sessionInfo) => {
|
|
12610
|
+
set({ sessionInfo });
|
|
12611
|
+
},
|
|
12612
|
+
/**
|
|
12613
|
+
* Sign in user with complete auth data
|
|
12614
|
+
* @param {User} user - The user object
|
|
12615
|
+
* @param {AuthTokens} tokens - The authentication tokens
|
|
12616
|
+
* @param {UserProfile[]} profiles - Array of user profiles
|
|
12617
|
+
* @returns {void}
|
|
12618
|
+
*/
|
|
12619
|
+
signIn: (user, tokens, profiles) => {
|
|
12620
|
+
set({
|
|
12621
|
+
user,
|
|
12622
|
+
tokens,
|
|
12623
|
+
profiles,
|
|
12624
|
+
isAuthenticated: true
|
|
12625
|
+
});
|
|
12626
|
+
},
|
|
12627
|
+
/**
|
|
12628
|
+
* Sign out user and clear all auth data
|
|
12629
|
+
* @returns {void}
|
|
12630
|
+
*/
|
|
12631
|
+
signOut: () => {
|
|
12632
|
+
set({
|
|
12633
|
+
user: null,
|
|
12634
|
+
tokens: null,
|
|
12635
|
+
isAuthenticated: false,
|
|
12636
|
+
profiles: [],
|
|
12637
|
+
selectedProfile: null,
|
|
12638
|
+
sessionInfo: null
|
|
12639
|
+
});
|
|
12640
|
+
},
|
|
12641
|
+
/**
|
|
12642
|
+
* Update user session data (after login completion)
|
|
12643
|
+
* @param {Partial<User>} sessionData - Partial user data to update
|
|
12644
|
+
* @returns {void}
|
|
12645
|
+
*/
|
|
12646
|
+
updateUserSession: (sessionData) => {
|
|
12647
|
+
const { user } = get();
|
|
12648
|
+
if (user) {
|
|
12649
|
+
const updatedUser = { ...user, ...sessionData };
|
|
12650
|
+
set({ user: updatedUser });
|
|
12651
|
+
}
|
|
12652
|
+
}
|
|
12653
|
+
}),
|
|
12654
|
+
{
|
|
12655
|
+
name: "@auth-storage:analytica:v2" /* AUTH_STORAGE */,
|
|
12656
|
+
storage: createJSONStorage2(() => localStorage)
|
|
12657
|
+
}
|
|
12658
|
+
)
|
|
12659
|
+
);
|
|
12660
|
+
|
|
12661
|
+
// src/hooks/useAppInitialization.ts
|
|
12662
|
+
function useAppInitialization() {
|
|
12663
|
+
const getInstitutionId = useInstitutionId();
|
|
12664
|
+
const { initialize, initialized, institutionId } = useAppStore();
|
|
12665
|
+
const authFunctions = useMemo7(
|
|
12666
|
+
() => ({
|
|
12667
|
+
checkAuth: async () => {
|
|
12668
|
+
const { sessionInfo, tokens } = useAuthStore.getState();
|
|
12669
|
+
return Boolean(sessionInfo && tokens);
|
|
12670
|
+
},
|
|
12671
|
+
signOut: () => {
|
|
12672
|
+
const { signOut } = useAuthStore.getState();
|
|
12673
|
+
signOut();
|
|
12674
|
+
},
|
|
12675
|
+
getUser: () => {
|
|
12676
|
+
const { user } = useAuthStore.getState();
|
|
12677
|
+
return user;
|
|
12678
|
+
},
|
|
12679
|
+
getSessionInfo: () => {
|
|
12680
|
+
const { sessionInfo } = useAuthStore.getState();
|
|
12681
|
+
return sessionInfo;
|
|
12682
|
+
},
|
|
12683
|
+
getTokens: () => {
|
|
12684
|
+
const { tokens } = useAuthStore.getState();
|
|
12685
|
+
return tokens;
|
|
12686
|
+
}
|
|
12687
|
+
}),
|
|
12688
|
+
[]
|
|
12689
|
+
);
|
|
12690
|
+
return {
|
|
12691
|
+
// Estado da inicialização
|
|
12692
|
+
getInstitutionId,
|
|
12693
|
+
initialize,
|
|
12694
|
+
initialized,
|
|
12695
|
+
institutionId,
|
|
12696
|
+
// Funções de autenticação
|
|
12697
|
+
authFunctions
|
|
12698
|
+
};
|
|
12699
|
+
}
|
|
12700
|
+
|
|
12701
|
+
// src/hooks/useAppContent.ts
|
|
12702
|
+
import { useCallback as useCallback7, useEffect as useEffect23, useMemo as useMemo8 } from "react";
|
|
12703
|
+
import { useNavigate } from "react-router-dom";
|
|
12704
|
+
function useAppContent(config) {
|
|
12705
|
+
const navigate = useNavigate();
|
|
12706
|
+
const { setTokens, setSessionInfo, setSelectedProfile } = useAuthStore();
|
|
12707
|
+
const {
|
|
12708
|
+
api,
|
|
12709
|
+
getInstitutionId,
|
|
12710
|
+
initialize,
|
|
12711
|
+
initialized,
|
|
12712
|
+
endpoint = "/auth/session-info",
|
|
12713
|
+
maxRetries = 1,
|
|
12714
|
+
retryDelay = 2e3,
|
|
12715
|
+
onClearParamsFromURL,
|
|
12716
|
+
onError,
|
|
12717
|
+
onNotFoundNavigation
|
|
12718
|
+
} = config;
|
|
12719
|
+
const apiConfig = useApiConfig(api);
|
|
12720
|
+
useTheme();
|
|
12721
|
+
const handleNotFoundNavigation = () => {
|
|
12722
|
+
if (onNotFoundNavigation) {
|
|
12723
|
+
onNotFoundNavigation();
|
|
12724
|
+
} else {
|
|
12725
|
+
navigate("/painel");
|
|
12726
|
+
}
|
|
12727
|
+
};
|
|
12728
|
+
const handleSetSelectedProfile = useCallback7(
|
|
12729
|
+
(profile) => {
|
|
12730
|
+
setSelectedProfile(profile);
|
|
12731
|
+
},
|
|
12732
|
+
[setSelectedProfile]
|
|
12733
|
+
);
|
|
12734
|
+
const handleClearParamsFromURL = useCallback7(() => {
|
|
12735
|
+
if (onClearParamsFromURL) {
|
|
12736
|
+
onClearParamsFromURL();
|
|
12737
|
+
} else {
|
|
12738
|
+
globalThis.location.replace("/painel");
|
|
12739
|
+
}
|
|
12740
|
+
}, [onClearParamsFromURL]);
|
|
12741
|
+
const handleError = useCallback7(
|
|
12742
|
+
(error) => {
|
|
12743
|
+
if (onError) {
|
|
12744
|
+
onError(error);
|
|
12745
|
+
} else {
|
|
12746
|
+
console.error("Erro ao obter informa\xE7\xF5es da sess\xE3o:", error);
|
|
12747
|
+
navigate("/", { replace: true });
|
|
12748
|
+
}
|
|
12749
|
+
},
|
|
12750
|
+
[navigate, onError]
|
|
12751
|
+
);
|
|
12752
|
+
const urlAuthConfig = useMemo8(
|
|
12753
|
+
() => ({
|
|
12754
|
+
setTokens,
|
|
12755
|
+
setSessionInfo,
|
|
12756
|
+
setSelectedProfile: handleSetSelectedProfile,
|
|
12757
|
+
api: apiConfig,
|
|
12758
|
+
endpoint,
|
|
12759
|
+
clearParamsFromURL: handleClearParamsFromURL,
|
|
12760
|
+
maxRetries,
|
|
12761
|
+
retryDelay,
|
|
12762
|
+
onError: handleError
|
|
12763
|
+
}),
|
|
12764
|
+
[
|
|
12765
|
+
setTokens,
|
|
12766
|
+
setSessionInfo,
|
|
12767
|
+
handleSetSelectedProfile,
|
|
12768
|
+
apiConfig,
|
|
12769
|
+
endpoint,
|
|
12770
|
+
handleClearParamsFromURL,
|
|
12771
|
+
maxRetries,
|
|
12772
|
+
retryDelay,
|
|
12773
|
+
handleError
|
|
12774
|
+
]
|
|
12775
|
+
);
|
|
12776
|
+
useUrlAuthentication(urlAuthConfig);
|
|
12777
|
+
const { sessionInfo } = useAuth();
|
|
12778
|
+
const institutionIdToUse = useMemo8(() => {
|
|
12779
|
+
return sessionInfo?.institutionId || getInstitutionId;
|
|
12780
|
+
}, [sessionInfo?.institutionId, getInstitutionId]);
|
|
12781
|
+
useEffect23(() => {
|
|
12782
|
+
if (institutionIdToUse && !initialized) {
|
|
12783
|
+
initialize(institutionIdToUse);
|
|
12784
|
+
}
|
|
12785
|
+
}, [institutionIdToUse, initialize, initialized]);
|
|
12786
|
+
return {
|
|
12787
|
+
handleNotFoundNavigation,
|
|
12788
|
+
urlAuthConfig,
|
|
12789
|
+
institutionIdToUse
|
|
12790
|
+
};
|
|
12791
|
+
}
|
|
12488
12792
|
export {
|
|
12489
12793
|
ANSWER_STATUS,
|
|
12490
12794
|
Alert_default as Alert,
|
|
@@ -12611,8 +12915,13 @@ export {
|
|
|
12611
12915
|
getSubjectName,
|
|
12612
12916
|
syncDropdownState,
|
|
12613
12917
|
useApiConfig,
|
|
12918
|
+
useAppContent,
|
|
12919
|
+
useAppInitialization,
|
|
12920
|
+
useAppStore,
|
|
12614
12921
|
useAuth,
|
|
12615
12922
|
useAuthGuard,
|
|
12923
|
+
useAuthStore,
|
|
12924
|
+
useInstitutionId,
|
|
12616
12925
|
useMobile,
|
|
12617
12926
|
useQuizStore,
|
|
12618
12927
|
useRouteAuth,
|