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.js
CHANGED
|
@@ -155,8 +155,13 @@ __export(src_exports, {
|
|
|
155
155
|
getSubjectName: () => getSubjectName,
|
|
156
156
|
syncDropdownState: () => syncDropdownState,
|
|
157
157
|
useApiConfig: () => useApiConfig,
|
|
158
|
+
useAppContent: () => useAppContent,
|
|
159
|
+
useAppInitialization: () => useAppInitialization,
|
|
160
|
+
useAppStore: () => useAppStore,
|
|
158
161
|
useAuth: () => useAuth,
|
|
159
162
|
useAuthGuard: () => useAuthGuard,
|
|
163
|
+
useAuthStore: () => useAuthStore,
|
|
164
|
+
useInstitutionId: () => useInstitutionId,
|
|
160
165
|
useMobile: () => useMobile,
|
|
161
166
|
useQuizStore: () => useQuizStore,
|
|
162
167
|
useRouteAuth: () => useRouteAuth,
|
|
@@ -9926,7 +9931,7 @@ var HeaderAlternative = (0, import_react31.forwardRef)(
|
|
|
9926
9931
|
);
|
|
9927
9932
|
|
|
9928
9933
|
// src/components/Auth/zustandAuthAdapter.ts
|
|
9929
|
-
function createZustandAuthAdapter(
|
|
9934
|
+
function createZustandAuthAdapter(useAuthStore2) {
|
|
9930
9935
|
return {
|
|
9931
9936
|
/**
|
|
9932
9937
|
* Check if the user is authenticated based on sessionInfo and tokens
|
|
@@ -9934,7 +9939,7 @@ function createZustandAuthAdapter(useAuthStore) {
|
|
|
9934
9939
|
* @returns {Promise<boolean>} Promise that resolves to authentication status
|
|
9935
9940
|
*/
|
|
9936
9941
|
checkAuth: async () => {
|
|
9937
|
-
const { sessionInfo, tokens } =
|
|
9942
|
+
const { sessionInfo, tokens } = useAuthStore2.getState();
|
|
9938
9943
|
return Boolean(sessionInfo && tokens);
|
|
9939
9944
|
},
|
|
9940
9945
|
/**
|
|
@@ -9942,26 +9947,26 @@ function createZustandAuthAdapter(useAuthStore) {
|
|
|
9942
9947
|
*
|
|
9943
9948
|
* @returns {unknown} Current user data from the store
|
|
9944
9949
|
*/
|
|
9945
|
-
getUser: () =>
|
|
9950
|
+
getUser: () => useAuthStore2.getState().user,
|
|
9946
9951
|
/**
|
|
9947
9952
|
* Get the current session information from the store
|
|
9948
9953
|
*
|
|
9949
9954
|
* @returns {unknown} Current session info from the store
|
|
9950
9955
|
*/
|
|
9951
|
-
getSessionInfo: () =>
|
|
9956
|
+
getSessionInfo: () => useAuthStore2.getState().sessionInfo,
|
|
9952
9957
|
/**
|
|
9953
9958
|
* Get the current authentication tokens from the store
|
|
9954
9959
|
*
|
|
9955
9960
|
* @returns {unknown} Current tokens from the store
|
|
9956
9961
|
*/
|
|
9957
|
-
getTokens: () =>
|
|
9962
|
+
getTokens: () => useAuthStore2.getState().tokens,
|
|
9958
9963
|
/**
|
|
9959
9964
|
* Sign out the user by calling the store's signOut function if available
|
|
9960
9965
|
*
|
|
9961
9966
|
* @returns {void}
|
|
9962
9967
|
*/
|
|
9963
9968
|
signOut: () => {
|
|
9964
|
-
const signOutFn =
|
|
9969
|
+
const signOutFn = useAuthStore2.getState().signOut;
|
|
9965
9970
|
if (typeof signOutFn === "function") signOutFn();
|
|
9966
9971
|
}
|
|
9967
9972
|
};
|
|
@@ -12514,6 +12519,310 @@ var QuizListResultByMateria = ({
|
|
|
12514
12519
|
] })
|
|
12515
12520
|
] });
|
|
12516
12521
|
};
|
|
12522
|
+
|
|
12523
|
+
// src/hooks/useAppInitialization.ts
|
|
12524
|
+
var import_react39 = require("react");
|
|
12525
|
+
|
|
12526
|
+
// src/hooks/useInstitution.ts
|
|
12527
|
+
var import_react38 = require("react");
|
|
12528
|
+
function useInstitutionId() {
|
|
12529
|
+
const [institutionId, setInstitutionId] = (0, import_react38.useState)(() => {
|
|
12530
|
+
return document.querySelector('meta[name="institution-id"]')?.getAttribute("content") ?? null;
|
|
12531
|
+
});
|
|
12532
|
+
(0, import_react38.useEffect)(() => {
|
|
12533
|
+
const metaTag = document.querySelector('meta[name="institution-id"]');
|
|
12534
|
+
if (!metaTag) return;
|
|
12535
|
+
const observer = new MutationObserver(() => {
|
|
12536
|
+
const newValue = metaTag.getAttribute("content");
|
|
12537
|
+
setInstitutionId(newValue);
|
|
12538
|
+
});
|
|
12539
|
+
observer.observe(metaTag, {
|
|
12540
|
+
attributes: true,
|
|
12541
|
+
attributeFilter: ["content"]
|
|
12542
|
+
});
|
|
12543
|
+
return () => observer.disconnect();
|
|
12544
|
+
}, []);
|
|
12545
|
+
return institutionId;
|
|
12546
|
+
}
|
|
12547
|
+
|
|
12548
|
+
// src/store/appStore.ts
|
|
12549
|
+
var import_zustand10 = require("zustand");
|
|
12550
|
+
var import_middleware4 = require("zustand/middleware");
|
|
12551
|
+
var useAppStore = (0, import_zustand10.create)()(
|
|
12552
|
+
(0, import_middleware4.persist)(
|
|
12553
|
+
(set, get) => ({
|
|
12554
|
+
institutionId: null,
|
|
12555
|
+
initialized: false,
|
|
12556
|
+
/**
|
|
12557
|
+
* Set the institution ID
|
|
12558
|
+
* @param {string | null} institutionId - The institution ID from meta tag
|
|
12559
|
+
* @returns {void}
|
|
12560
|
+
*/
|
|
12561
|
+
setInstitutionId: (institutionId) => {
|
|
12562
|
+
set({ institutionId });
|
|
12563
|
+
},
|
|
12564
|
+
/**
|
|
12565
|
+
* Set the initialized state
|
|
12566
|
+
* @param {boolean} initialized - Whether the app has been initialized
|
|
12567
|
+
* @returns {void}
|
|
12568
|
+
*/
|
|
12569
|
+
setInitialized: (initialized) => {
|
|
12570
|
+
set({ initialized });
|
|
12571
|
+
},
|
|
12572
|
+
/**
|
|
12573
|
+
* Initialize the app by reading the institution ID from meta tag
|
|
12574
|
+
* @returns {void}
|
|
12575
|
+
*/
|
|
12576
|
+
initialize: (id) => {
|
|
12577
|
+
const { initialized } = get();
|
|
12578
|
+
if (initialized) {
|
|
12579
|
+
return;
|
|
12580
|
+
}
|
|
12581
|
+
set({
|
|
12582
|
+
institutionId: id,
|
|
12583
|
+
initialized: true
|
|
12584
|
+
});
|
|
12585
|
+
}
|
|
12586
|
+
}),
|
|
12587
|
+
{
|
|
12588
|
+
name: "@app-storage:analytica:v2" /* APP_STORAGE */,
|
|
12589
|
+
storage: (0, import_middleware4.createJSONStorage)(() => localStorage)
|
|
12590
|
+
}
|
|
12591
|
+
)
|
|
12592
|
+
);
|
|
12593
|
+
|
|
12594
|
+
// src/store/authStore.ts
|
|
12595
|
+
var import_zustand11 = require("zustand");
|
|
12596
|
+
var import_middleware5 = require("zustand/middleware");
|
|
12597
|
+
var useAuthStore = (0, import_zustand11.create)()(
|
|
12598
|
+
(0, import_middleware5.persist)(
|
|
12599
|
+
(set, get) => ({
|
|
12600
|
+
user: null,
|
|
12601
|
+
tokens: null,
|
|
12602
|
+
isAuthenticated: false,
|
|
12603
|
+
profiles: [],
|
|
12604
|
+
selectedProfile: null,
|
|
12605
|
+
sessionInfo: null,
|
|
12606
|
+
/**
|
|
12607
|
+
* Set the current user
|
|
12608
|
+
* @param {User | null} user - The user object or null to clear
|
|
12609
|
+
* @returns {void}
|
|
12610
|
+
*/
|
|
12611
|
+
setUser: (user) => {
|
|
12612
|
+
set({ user, isAuthenticated: !!user });
|
|
12613
|
+
},
|
|
12614
|
+
/**
|
|
12615
|
+
* Set the authentication tokens
|
|
12616
|
+
* @param {AuthTokens | null} tokens - The authentication tokens or null to clear
|
|
12617
|
+
* @returns {void}
|
|
12618
|
+
*/
|
|
12619
|
+
setTokens: (tokens) => {
|
|
12620
|
+
set({ tokens });
|
|
12621
|
+
},
|
|
12622
|
+
/**
|
|
12623
|
+
* Set user profiles
|
|
12624
|
+
* @param {UserProfile[]} profiles - Array of user profiles
|
|
12625
|
+
* @returns {void}
|
|
12626
|
+
*/
|
|
12627
|
+
setProfiles: (profiles) => {
|
|
12628
|
+
set({ profiles });
|
|
12629
|
+
},
|
|
12630
|
+
/**
|
|
12631
|
+
* Set the selected profile
|
|
12632
|
+
* @param {UserProfile | null} profile - The selected profile or null to clear
|
|
12633
|
+
* @returns {void}
|
|
12634
|
+
*/
|
|
12635
|
+
setSelectedProfile: (profile) => {
|
|
12636
|
+
set({ selectedProfile: profile });
|
|
12637
|
+
},
|
|
12638
|
+
/**
|
|
12639
|
+
* Set the session info
|
|
12640
|
+
* @param {SessionInfo | null} sessionInfo - The session info or null to clear
|
|
12641
|
+
* @returns {void}
|
|
12642
|
+
*/
|
|
12643
|
+
setSessionInfo: (sessionInfo) => {
|
|
12644
|
+
set({ sessionInfo });
|
|
12645
|
+
},
|
|
12646
|
+
/**
|
|
12647
|
+
* Sign in user with complete auth data
|
|
12648
|
+
* @param {User} user - The user object
|
|
12649
|
+
* @param {AuthTokens} tokens - The authentication tokens
|
|
12650
|
+
* @param {UserProfile[]} profiles - Array of user profiles
|
|
12651
|
+
* @returns {void}
|
|
12652
|
+
*/
|
|
12653
|
+
signIn: (user, tokens, profiles) => {
|
|
12654
|
+
set({
|
|
12655
|
+
user,
|
|
12656
|
+
tokens,
|
|
12657
|
+
profiles,
|
|
12658
|
+
isAuthenticated: true
|
|
12659
|
+
});
|
|
12660
|
+
},
|
|
12661
|
+
/**
|
|
12662
|
+
* Sign out user and clear all auth data
|
|
12663
|
+
* @returns {void}
|
|
12664
|
+
*/
|
|
12665
|
+
signOut: () => {
|
|
12666
|
+
set({
|
|
12667
|
+
user: null,
|
|
12668
|
+
tokens: null,
|
|
12669
|
+
isAuthenticated: false,
|
|
12670
|
+
profiles: [],
|
|
12671
|
+
selectedProfile: null,
|
|
12672
|
+
sessionInfo: null
|
|
12673
|
+
});
|
|
12674
|
+
},
|
|
12675
|
+
/**
|
|
12676
|
+
* Update user session data (after login completion)
|
|
12677
|
+
* @param {Partial<User>} sessionData - Partial user data to update
|
|
12678
|
+
* @returns {void}
|
|
12679
|
+
*/
|
|
12680
|
+
updateUserSession: (sessionData) => {
|
|
12681
|
+
const { user } = get();
|
|
12682
|
+
if (user) {
|
|
12683
|
+
const updatedUser = { ...user, ...sessionData };
|
|
12684
|
+
set({ user: updatedUser });
|
|
12685
|
+
}
|
|
12686
|
+
}
|
|
12687
|
+
}),
|
|
12688
|
+
{
|
|
12689
|
+
name: "@auth-storage:analytica:v2" /* AUTH_STORAGE */,
|
|
12690
|
+
storage: (0, import_middleware5.createJSONStorage)(() => localStorage)
|
|
12691
|
+
}
|
|
12692
|
+
)
|
|
12693
|
+
);
|
|
12694
|
+
|
|
12695
|
+
// src/hooks/useAppInitialization.ts
|
|
12696
|
+
function useAppInitialization() {
|
|
12697
|
+
const getInstitutionId = useInstitutionId();
|
|
12698
|
+
const { initialize, initialized, institutionId } = useAppStore();
|
|
12699
|
+
const authFunctions = (0, import_react39.useMemo)(
|
|
12700
|
+
() => ({
|
|
12701
|
+
checkAuth: async () => {
|
|
12702
|
+
const { sessionInfo, tokens } = useAuthStore.getState();
|
|
12703
|
+
return Boolean(sessionInfo && tokens);
|
|
12704
|
+
},
|
|
12705
|
+
signOut: () => {
|
|
12706
|
+
const { signOut } = useAuthStore.getState();
|
|
12707
|
+
signOut();
|
|
12708
|
+
},
|
|
12709
|
+
getUser: () => {
|
|
12710
|
+
const { user } = useAuthStore.getState();
|
|
12711
|
+
return user;
|
|
12712
|
+
},
|
|
12713
|
+
getSessionInfo: () => {
|
|
12714
|
+
const { sessionInfo } = useAuthStore.getState();
|
|
12715
|
+
return sessionInfo;
|
|
12716
|
+
},
|
|
12717
|
+
getTokens: () => {
|
|
12718
|
+
const { tokens } = useAuthStore.getState();
|
|
12719
|
+
return tokens;
|
|
12720
|
+
}
|
|
12721
|
+
}),
|
|
12722
|
+
[]
|
|
12723
|
+
);
|
|
12724
|
+
return {
|
|
12725
|
+
// Estado da inicialização
|
|
12726
|
+
getInstitutionId,
|
|
12727
|
+
initialize,
|
|
12728
|
+
initialized,
|
|
12729
|
+
institutionId,
|
|
12730
|
+
// Funções de autenticação
|
|
12731
|
+
authFunctions
|
|
12732
|
+
};
|
|
12733
|
+
}
|
|
12734
|
+
|
|
12735
|
+
// src/hooks/useAppContent.ts
|
|
12736
|
+
var import_react40 = require("react");
|
|
12737
|
+
var import_react_router_dom3 = require("react-router-dom");
|
|
12738
|
+
function useAppContent(config) {
|
|
12739
|
+
const navigate = (0, import_react_router_dom3.useNavigate)();
|
|
12740
|
+
const { setTokens, setSessionInfo, setSelectedProfile } = useAuthStore();
|
|
12741
|
+
const {
|
|
12742
|
+
api,
|
|
12743
|
+
getInstitutionId,
|
|
12744
|
+
initialize,
|
|
12745
|
+
initialized,
|
|
12746
|
+
endpoint = "/auth/session-info",
|
|
12747
|
+
maxRetries = 1,
|
|
12748
|
+
retryDelay = 2e3,
|
|
12749
|
+
onClearParamsFromURL,
|
|
12750
|
+
onError,
|
|
12751
|
+
onNotFoundNavigation
|
|
12752
|
+
} = config;
|
|
12753
|
+
const apiConfig = useApiConfig(api);
|
|
12754
|
+
useTheme();
|
|
12755
|
+
const handleNotFoundNavigation = () => {
|
|
12756
|
+
if (onNotFoundNavigation) {
|
|
12757
|
+
onNotFoundNavigation();
|
|
12758
|
+
} else {
|
|
12759
|
+
navigate("/painel");
|
|
12760
|
+
}
|
|
12761
|
+
};
|
|
12762
|
+
const handleSetSelectedProfile = (0, import_react40.useCallback)(
|
|
12763
|
+
(profile) => {
|
|
12764
|
+
setSelectedProfile(profile);
|
|
12765
|
+
},
|
|
12766
|
+
[setSelectedProfile]
|
|
12767
|
+
);
|
|
12768
|
+
const handleClearParamsFromURL = (0, import_react40.useCallback)(() => {
|
|
12769
|
+
if (onClearParamsFromURL) {
|
|
12770
|
+
onClearParamsFromURL();
|
|
12771
|
+
} else {
|
|
12772
|
+
globalThis.location.replace("/painel");
|
|
12773
|
+
}
|
|
12774
|
+
}, [onClearParamsFromURL]);
|
|
12775
|
+
const handleError = (0, import_react40.useCallback)(
|
|
12776
|
+
(error) => {
|
|
12777
|
+
if (onError) {
|
|
12778
|
+
onError(error);
|
|
12779
|
+
} else {
|
|
12780
|
+
console.error("Erro ao obter informa\xE7\xF5es da sess\xE3o:", error);
|
|
12781
|
+
navigate("/", { replace: true });
|
|
12782
|
+
}
|
|
12783
|
+
},
|
|
12784
|
+
[navigate, onError]
|
|
12785
|
+
);
|
|
12786
|
+
const urlAuthConfig = (0, import_react40.useMemo)(
|
|
12787
|
+
() => ({
|
|
12788
|
+
setTokens,
|
|
12789
|
+
setSessionInfo,
|
|
12790
|
+
setSelectedProfile: handleSetSelectedProfile,
|
|
12791
|
+
api: apiConfig,
|
|
12792
|
+
endpoint,
|
|
12793
|
+
clearParamsFromURL: handleClearParamsFromURL,
|
|
12794
|
+
maxRetries,
|
|
12795
|
+
retryDelay,
|
|
12796
|
+
onError: handleError
|
|
12797
|
+
}),
|
|
12798
|
+
[
|
|
12799
|
+
setTokens,
|
|
12800
|
+
setSessionInfo,
|
|
12801
|
+
handleSetSelectedProfile,
|
|
12802
|
+
apiConfig,
|
|
12803
|
+
endpoint,
|
|
12804
|
+
handleClearParamsFromURL,
|
|
12805
|
+
maxRetries,
|
|
12806
|
+
retryDelay,
|
|
12807
|
+
handleError
|
|
12808
|
+
]
|
|
12809
|
+
);
|
|
12810
|
+
useUrlAuthentication(urlAuthConfig);
|
|
12811
|
+
const { sessionInfo } = useAuth();
|
|
12812
|
+
const institutionIdToUse = (0, import_react40.useMemo)(() => {
|
|
12813
|
+
return sessionInfo?.institutionId || getInstitutionId;
|
|
12814
|
+
}, [sessionInfo?.institutionId, getInstitutionId]);
|
|
12815
|
+
(0, import_react40.useEffect)(() => {
|
|
12816
|
+
if (institutionIdToUse && !initialized) {
|
|
12817
|
+
initialize(institutionIdToUse);
|
|
12818
|
+
}
|
|
12819
|
+
}, [institutionIdToUse, initialize, initialized]);
|
|
12820
|
+
return {
|
|
12821
|
+
handleNotFoundNavigation,
|
|
12822
|
+
urlAuthConfig,
|
|
12823
|
+
institutionIdToUse
|
|
12824
|
+
};
|
|
12825
|
+
}
|
|
12517
12826
|
// Annotate the CommonJS export names for ESM import in node:
|
|
12518
12827
|
0 && (module.exports = {
|
|
12519
12828
|
ANSWER_STATUS,
|
|
@@ -12641,8 +12950,13 @@ var QuizListResultByMateria = ({
|
|
|
12641
12950
|
getSubjectName,
|
|
12642
12951
|
syncDropdownState,
|
|
12643
12952
|
useApiConfig,
|
|
12953
|
+
useAppContent,
|
|
12954
|
+
useAppInitialization,
|
|
12955
|
+
useAppStore,
|
|
12644
12956
|
useAuth,
|
|
12645
12957
|
useAuthGuard,
|
|
12958
|
+
useAuthStore,
|
|
12959
|
+
useInstitutionId,
|
|
12646
12960
|
useMobile,
|
|
12647
12961
|
useQuizStore,
|
|
12648
12962
|
useRouteAuth,
|