analytica-frontend-lib 1.0.73 → 1.0.74

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.
Files changed (67) hide show
  1. package/dist/Auth/AuthProvider/index.d.mts +3 -0
  2. package/dist/Auth/AuthProvider/index.d.ts +3 -0
  3. package/dist/Auth/AuthProvider/index.js +211 -0
  4. package/dist/Auth/AuthProvider/index.js.map +1 -0
  5. package/dist/Auth/AuthProvider/index.mjs +187 -0
  6. package/dist/Auth/AuthProvider/index.mjs.map +1 -0
  7. package/dist/Auth/ProtectedRoute/index.d.mts +3 -0
  8. package/dist/Auth/ProtectedRoute/index.d.ts +3 -0
  9. package/dist/Auth/ProtectedRoute/index.js +211 -0
  10. package/dist/Auth/ProtectedRoute/index.js.map +1 -0
  11. package/dist/Auth/ProtectedRoute/index.mjs +187 -0
  12. package/dist/Auth/ProtectedRoute/index.mjs.map +1 -0
  13. package/dist/Auth/PublicRoute/index.d.mts +3 -0
  14. package/dist/Auth/PublicRoute/index.d.ts +3 -0
  15. package/dist/Auth/PublicRoute/index.js +211 -0
  16. package/dist/Auth/PublicRoute/index.js.map +1 -0
  17. package/dist/Auth/PublicRoute/index.mjs +187 -0
  18. package/dist/Auth/PublicRoute/index.mjs.map +1 -0
  19. package/dist/Auth/index.d.mts +106 -19
  20. package/dist/Auth/index.d.ts +106 -19
  21. package/dist/Auth/index.js +21 -0
  22. package/dist/Auth/index.js.map +1 -1
  23. package/dist/Auth/index.mjs +21 -0
  24. package/dist/Auth/index.mjs.map +1 -1
  25. package/dist/Auth/useAuth/index.d.mts +3 -0
  26. package/dist/Auth/useAuth/index.d.ts +3 -0
  27. package/dist/Auth/useAuth/index.js +211 -0
  28. package/dist/Auth/useAuth/index.js.map +1 -0
  29. package/dist/Auth/useAuth/index.mjs +187 -0
  30. package/dist/Auth/useAuth/index.mjs.map +1 -0
  31. package/dist/Auth/useAuthGuard/index.d.mts +3 -0
  32. package/dist/Auth/useAuthGuard/index.d.ts +3 -0
  33. package/dist/Auth/useAuthGuard/index.js +211 -0
  34. package/dist/Auth/useAuthGuard/index.js.map +1 -0
  35. package/dist/Auth/useAuthGuard/index.mjs +187 -0
  36. package/dist/Auth/useAuthGuard/index.mjs.map +1 -0
  37. package/dist/Auth/useRouteAuth/index.d.mts +3 -0
  38. package/dist/Auth/useRouteAuth/index.d.ts +3 -0
  39. package/dist/Auth/useRouteAuth/index.js +211 -0
  40. package/dist/Auth/useRouteAuth/index.js.map +1 -0
  41. package/dist/Auth/useRouteAuth/index.mjs +187 -0
  42. package/dist/Auth/useRouteAuth/index.mjs.map +1 -0
  43. package/dist/Auth/useUrlAuthentication/index.d.mts +58 -0
  44. package/dist/Auth/useUrlAuthentication/index.d.ts +58 -0
  45. package/dist/Auth/useUrlAuthentication/index.js +94 -0
  46. package/dist/Auth/useUrlAuthentication/index.js.map +1 -0
  47. package/dist/Auth/useUrlAuthentication/index.mjs +69 -0
  48. package/dist/Auth/useUrlAuthentication/index.mjs.map +1 -0
  49. package/dist/Auth/withAuth/index.d.mts +3 -0
  50. package/dist/Auth/withAuth/index.d.ts +3 -0
  51. package/dist/Auth/withAuth/index.js +211 -0
  52. package/dist/Auth/withAuth/index.js.map +1 -0
  53. package/dist/Auth/withAuth/index.mjs +187 -0
  54. package/dist/Auth/withAuth/index.mjs.map +1 -0
  55. package/dist/Auth/zustandAuthAdapter/index.d.mts +75 -0
  56. package/dist/Auth/zustandAuthAdapter/index.d.ts +75 -0
  57. package/dist/Auth/zustandAuthAdapter/index.js +70 -0
  58. package/dist/Auth/zustandAuthAdapter/index.js.map +1 -0
  59. package/dist/Auth/zustandAuthAdapter/index.mjs +45 -0
  60. package/dist/Auth/zustandAuthAdapter/index.mjs.map +1 -0
  61. package/dist/index.d.mts +2 -0
  62. package/dist/index.d.ts +2 -0
  63. package/dist/index.js +133 -0
  64. package/dist/index.js.map +1 -1
  65. package/dist/index.mjs +131 -0
  66. package/dist/index.mjs.map +1 -1
  67. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -5855,6 +5855,14 @@ var ProtectedRoute = ({
5855
5855
  return /* @__PURE__ */ jsx31(Fragment7, { children: loadingComponent || defaultLoadingComponent });
5856
5856
  }
5857
5857
  if (!isAuthenticated) {
5858
+ if (typeof window !== "undefined") {
5859
+ const rootDomain = getRootDomain();
5860
+ const currentLocation = `${window.location.protocol}//${window.location.hostname}${window.location.port ? ":" + window.location.port : ""}`;
5861
+ if (rootDomain !== currentLocation) {
5862
+ window.location.href = rootDomain;
5863
+ return null;
5864
+ }
5865
+ }
5858
5866
  return /* @__PURE__ */ jsx31(Navigate, { to: redirectTo, replace: true });
5859
5867
  }
5860
5868
  if (additionalCheck && !additionalCheck({ isAuthenticated, isLoading, ...authState })) {
@@ -5900,6 +5908,127 @@ var useRouteAuth = (fallbackPath = "/") => {
5900
5908
  redirectToLogin
5901
5909
  };
5902
5910
  };
5911
+ var getRootDomain = () => {
5912
+ const { hostname, protocol, port } = window.location;
5913
+ const portStr = port ? ":" + port : "";
5914
+ if (hostname === "localhost") {
5915
+ return `${protocol}//${hostname}${portStr}`;
5916
+ }
5917
+ const parts = hostname.split(".");
5918
+ if (parts.length > 2) {
5919
+ const base = parts.slice(-2).join(".");
5920
+ return `${protocol}//${base}${portStr}`;
5921
+ }
5922
+ return `${protocol}//${hostname}${portStr}`;
5923
+ };
5924
+
5925
+ // src/components/Auth/zustandAuthAdapter.ts
5926
+ function createZustandAuthAdapter(useAuthStore) {
5927
+ return {
5928
+ /**
5929
+ * Check if the user is authenticated based on sessionInfo and tokens
5930
+ *
5931
+ * @returns {Promise<boolean>} Promise that resolves to authentication status
5932
+ */
5933
+ checkAuth: async () => {
5934
+ const { sessionInfo, tokens } = useAuthStore.getState();
5935
+ return Boolean(sessionInfo && tokens);
5936
+ },
5937
+ /**
5938
+ * Get the current user from the store
5939
+ *
5940
+ * @returns {unknown} Current user data from the store
5941
+ */
5942
+ getUser: () => useAuthStore.getState().user,
5943
+ /**
5944
+ * Get the current session information from the store
5945
+ *
5946
+ * @returns {unknown} Current session info from the store
5947
+ */
5948
+ getSessionInfo: () => useAuthStore.getState().sessionInfo,
5949
+ /**
5950
+ * Get the current authentication tokens from the store
5951
+ *
5952
+ * @returns {unknown} Current tokens from the store
5953
+ */
5954
+ getTokens: () => useAuthStore.getState().tokens,
5955
+ /**
5956
+ * Sign out the user by calling the store's signOut function if available
5957
+ *
5958
+ * @returns {void}
5959
+ */
5960
+ signOut: () => {
5961
+ const signOutFn = useAuthStore.getState().signOut;
5962
+ if (typeof signOutFn === "function") signOutFn();
5963
+ }
5964
+ };
5965
+ }
5966
+
5967
+ // src/components/Auth/useUrlAuthentication.ts
5968
+ import { useEffect as useEffect9 } from "react";
5969
+ import { useLocation as useLocation2 } from "react-router-dom";
5970
+ var getAuthParams = (location, extractParams) => {
5971
+ const searchParams = new URLSearchParams(location.search);
5972
+ return extractParams ? extractParams(searchParams) : {
5973
+ sessionId: searchParams.get("sessionId"),
5974
+ token: searchParams.get("token"),
5975
+ refreshToken: searchParams.get("refreshToken")
5976
+ };
5977
+ };
5978
+ var hasValidAuthParams = (authParams) => {
5979
+ return !!(authParams?.sessionId && authParams?.token && authParams?.refreshToken);
5980
+ };
5981
+ var hasValidProfileData = (data) => {
5982
+ return data !== null && typeof data === "object" && data !== void 0;
5983
+ };
5984
+ var handleProfileSelection = (responseData, setSelectedProfile) => {
5985
+ if (!setSelectedProfile) return;
5986
+ if (!hasValidProfileData(responseData)) return;
5987
+ const profileId = responseData.profileId;
5988
+ const isValidProfileId = profileId !== null && profileId !== void 0;
5989
+ if (isValidProfileId) {
5990
+ setSelectedProfile({
5991
+ id: profileId
5992
+ });
5993
+ }
5994
+ };
5995
+ function useUrlAuthentication(options) {
5996
+ const location = useLocation2();
5997
+ useEffect9(() => {
5998
+ const handleAuthentication = async () => {
5999
+ const authParams = getAuthParams(location, options.extractParams);
6000
+ if (!hasValidAuthParams(authParams)) {
6001
+ return;
6002
+ }
6003
+ try {
6004
+ options.setTokens({
6005
+ token: authParams.token,
6006
+ refreshToken: authParams.refreshToken
6007
+ });
6008
+ const response = await options.api.get(options.endpoint, {
6009
+ headers: {
6010
+ Authorization: `Bearer ${authParams.token}`
6011
+ }
6012
+ });
6013
+ options.setSessionInfo(response.data.data);
6014
+ handleProfileSelection(response.data.data, options.setSelectedProfile);
6015
+ options.clearParamsFromURL?.();
6016
+ } catch (error) {
6017
+ console.error("Erro ao obter informa\xE7\xF5es da sess\xE3o:", error);
6018
+ }
6019
+ };
6020
+ handleAuthentication();
6021
+ }, [
6022
+ location.search,
6023
+ options.setSessionInfo,
6024
+ options.setSelectedProfile,
6025
+ options.setTokens,
6026
+ options.api,
6027
+ options.endpoint,
6028
+ options.extractParams,
6029
+ options.clearParamsFromURL
6030
+ ]);
6031
+ }
5903
6032
  export {
5904
6033
  Alert_default as Alert,
5905
6034
  AlertDialog,
@@ -5966,10 +6095,12 @@ export {
5966
6095
  TextArea_default as TextArea,
5967
6096
  Toast_default as Toast,
5968
6097
  Toaster_default as Toaster,
6098
+ createZustandAuthAdapter,
5969
6099
  useAuth,
5970
6100
  useAuthGuard,
5971
6101
  useRouteAuth,
5972
6102
  ToastStore_default as useToastStore,
6103
+ useUrlAuthentication,
5973
6104
  withAuth
5974
6105
  };
5975
6106
  //# sourceMappingURL=index.mjs.map