analytica-frontend-lib 1.0.72 → 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 (81) hide show
  1. package/dist/Accordation/index.js +119 -0
  2. package/dist/Accordation/index.js.map +1 -1
  3. package/dist/Accordation/index.mjs +119 -0
  4. package/dist/Accordation/index.mjs.map +1 -1
  5. package/dist/Auth/AuthProvider/index.d.mts +3 -0
  6. package/dist/Auth/AuthProvider/index.d.ts +3 -0
  7. package/dist/Auth/AuthProvider/index.js +211 -0
  8. package/dist/Auth/AuthProvider/index.js.map +1 -0
  9. package/dist/Auth/AuthProvider/index.mjs +187 -0
  10. package/dist/Auth/AuthProvider/index.mjs.map +1 -0
  11. package/dist/Auth/ProtectedRoute/index.d.mts +3 -0
  12. package/dist/Auth/ProtectedRoute/index.d.ts +3 -0
  13. package/dist/Auth/ProtectedRoute/index.js +211 -0
  14. package/dist/Auth/ProtectedRoute/index.js.map +1 -0
  15. package/dist/Auth/ProtectedRoute/index.mjs +187 -0
  16. package/dist/Auth/ProtectedRoute/index.mjs.map +1 -0
  17. package/dist/Auth/PublicRoute/index.d.mts +3 -0
  18. package/dist/Auth/PublicRoute/index.d.ts +3 -0
  19. package/dist/Auth/PublicRoute/index.js +211 -0
  20. package/dist/Auth/PublicRoute/index.js.map +1 -0
  21. package/dist/Auth/PublicRoute/index.mjs +187 -0
  22. package/dist/Auth/PublicRoute/index.mjs.map +1 -0
  23. package/dist/Auth/index.d.mts +106 -19
  24. package/dist/Auth/index.d.ts +106 -19
  25. package/dist/Auth/index.js +21 -0
  26. package/dist/Auth/index.js.map +1 -1
  27. package/dist/Auth/index.mjs +21 -0
  28. package/dist/Auth/index.mjs.map +1 -1
  29. package/dist/Auth/useAuth/index.d.mts +3 -0
  30. package/dist/Auth/useAuth/index.d.ts +3 -0
  31. package/dist/Auth/useAuth/index.js +211 -0
  32. package/dist/Auth/useAuth/index.js.map +1 -0
  33. package/dist/Auth/useAuth/index.mjs +187 -0
  34. package/dist/Auth/useAuth/index.mjs.map +1 -0
  35. package/dist/Auth/useAuthGuard/index.d.mts +3 -0
  36. package/dist/Auth/useAuthGuard/index.d.ts +3 -0
  37. package/dist/Auth/useAuthGuard/index.js +211 -0
  38. package/dist/Auth/useAuthGuard/index.js.map +1 -0
  39. package/dist/Auth/useAuthGuard/index.mjs +187 -0
  40. package/dist/Auth/useAuthGuard/index.mjs.map +1 -0
  41. package/dist/Auth/useRouteAuth/index.d.mts +3 -0
  42. package/dist/Auth/useRouteAuth/index.d.ts +3 -0
  43. package/dist/Auth/useRouteAuth/index.js +211 -0
  44. package/dist/Auth/useRouteAuth/index.js.map +1 -0
  45. package/dist/Auth/useRouteAuth/index.mjs +187 -0
  46. package/dist/Auth/useRouteAuth/index.mjs.map +1 -0
  47. package/dist/Auth/useUrlAuthentication/index.d.mts +58 -0
  48. package/dist/Auth/useUrlAuthentication/index.d.ts +58 -0
  49. package/dist/Auth/useUrlAuthentication/index.js +94 -0
  50. package/dist/Auth/useUrlAuthentication/index.js.map +1 -0
  51. package/dist/Auth/useUrlAuthentication/index.mjs +69 -0
  52. package/dist/Auth/useUrlAuthentication/index.mjs.map +1 -0
  53. package/dist/Auth/withAuth/index.d.mts +3 -0
  54. package/dist/Auth/withAuth/index.d.ts +3 -0
  55. package/dist/Auth/withAuth/index.js +211 -0
  56. package/dist/Auth/withAuth/index.js.map +1 -0
  57. package/dist/Auth/withAuth/index.mjs +187 -0
  58. package/dist/Auth/withAuth/index.mjs.map +1 -0
  59. package/dist/Auth/zustandAuthAdapter/index.d.mts +75 -0
  60. package/dist/Auth/zustandAuthAdapter/index.d.ts +75 -0
  61. package/dist/Auth/zustandAuthAdapter/index.js +70 -0
  62. package/dist/Auth/zustandAuthAdapter/index.js.map +1 -0
  63. package/dist/Auth/zustandAuthAdapter/index.mjs +45 -0
  64. package/dist/Auth/zustandAuthAdapter/index.mjs.map +1 -0
  65. package/dist/Card/index.d.mts +10 -1
  66. package/dist/Card/index.d.ts +10 -1
  67. package/dist/Card/index.js +121 -0
  68. package/dist/Card/index.js.map +1 -1
  69. package/dist/Card/index.mjs +120 -0
  70. package/dist/Card/index.mjs.map +1 -1
  71. package/dist/index.css +48 -0
  72. package/dist/index.css.map +1 -1
  73. package/dist/index.d.mts +2 -0
  74. package/dist/index.d.ts +2 -0
  75. package/dist/index.js +252 -0
  76. package/dist/index.js.map +1 -1
  77. package/dist/index.mjs +250 -0
  78. package/dist/index.mjs.map +1 -1
  79. package/dist/styles.css +48 -0
  80. package/dist/styles.css.map +1 -1
  81. package/package.json +1 -1
package/dist/index.d.mts CHANGED
@@ -30,6 +30,8 @@ export { default as Menu, MenuContent, MenuItem, MenuOverflow } from './Menu/ind
30
30
  export { CardActivitiesResults, CardPerformance, CardProgress, CardQuestions, CardResults, CardSimulado, CardStatus, CardTopic } from './Card/index.mjs';
31
31
  export { Skeleton, SkeletonCard, SkeletonCircle, SkeletonList, SkeletonRectangle, SkeletonRounded, SkeletonTable, SkeletonText } from './Skeleton/index.mjs';
32
32
  export { AuthProvider, ProtectedRoute, PublicRoute, useAuth, useAuthGuard, useRouteAuth, withAuth } from './Auth/index.mjs';
33
+ export { createZustandAuthAdapter } from './Auth/zustandAuthAdapter/index.mjs';
34
+ export { useUrlAuthentication } from './Auth/useUrlAuthentication/index.mjs';
33
35
  import 'react/jsx-runtime';
34
36
  import 'react';
35
37
  import 'zustand';
package/dist/index.d.ts CHANGED
@@ -30,6 +30,8 @@ export { default as Menu, MenuContent, MenuItem, MenuOverflow } from './Menu/ind
30
30
  export { CardActivitiesResults, CardPerformance, CardProgress, CardQuestions, CardResults, CardSimulado, CardStatus, CardTopic } from './Card/index.js';
31
31
  export { Skeleton, SkeletonCard, SkeletonCircle, SkeletonList, SkeletonRectangle, SkeletonRounded, SkeletonTable, SkeletonText } from './Skeleton/index.js';
32
32
  export { AuthProvider, ProtectedRoute, PublicRoute, useAuth, useAuthGuard, useRouteAuth, withAuth } from './Auth/index.js';
33
+ export { createZustandAuthAdapter } from './Auth/zustandAuthAdapter/index.js';
34
+ export { useUrlAuthentication } from './Auth/useUrlAuthentication/index.js';
33
35
  import 'react/jsx-runtime';
34
36
  import 'react';
35
37
  import 'zustand';
package/dist/index.js CHANGED
@@ -85,10 +85,12 @@ __export(src_exports, {
85
85
  TextArea: () => TextArea_default,
86
86
  Toast: () => Toast_default,
87
87
  Toaster: () => Toaster_default,
88
+ createZustandAuthAdapter: () => createZustandAuthAdapter,
88
89
  useAuth: () => useAuth,
89
90
  useAuthGuard: () => useAuthGuard,
90
91
  useRouteAuth: () => useRouteAuth,
91
92
  useToastStore: () => ToastStore_default,
93
+ useUrlAuthentication: () => useUrlAuthentication,
92
94
  withAuth: () => withAuth
93
95
  });
94
96
  module.exports = __toCommonJS(src_exports);
@@ -4090,6 +4092,125 @@ var CardSimulado = (0, import_react11.forwardRef)(
4090
4092
  );
4091
4093
  }
4092
4094
  );
4095
+ var CardTest = (0, import_react11.forwardRef)(
4096
+ ({
4097
+ title,
4098
+ duration,
4099
+ questionsCount,
4100
+ additionalInfo,
4101
+ selected = false,
4102
+ onSelect,
4103
+ className = "",
4104
+ ...props
4105
+ }, ref) => {
4106
+ const handleClick = () => {
4107
+ if (onSelect) {
4108
+ onSelect(!selected);
4109
+ }
4110
+ };
4111
+ const handleKeyDown = (event) => {
4112
+ if ((event.key === "Enter" || event.key === " ") && onSelect) {
4113
+ event.preventDefault();
4114
+ onSelect(!selected);
4115
+ }
4116
+ };
4117
+ const isSelectable = !!onSelect;
4118
+ const getQuestionsText = (count) => {
4119
+ const singular = count === 1 ? "quest\xE3o" : "quest\xF5es";
4120
+ return `${count} ${singular}`;
4121
+ };
4122
+ const displayInfo = questionsCount ? getQuestionsText(questionsCount) : additionalInfo || "";
4123
+ const baseClasses = "flex flex-row items-center p-4 gap-2 w-full max-w-full bg-background shadow-soft-shadow-1 rounded-xl isolate border-0 text-left";
4124
+ const interactiveClasses = isSelectable ? "cursor-pointer focus:outline-none focus:ring-2 focus:ring-primary-950 focus:ring-offset-2" : "";
4125
+ const selectedClasses = selected ? "ring-2 ring-primary-950 ring-offset-2" : "";
4126
+ if (isSelectable) {
4127
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4128
+ "button",
4129
+ {
4130
+ ref,
4131
+ type: "button",
4132
+ className: `${baseClasses} ${interactiveClasses} ${selectedClasses} ${className}`.trim(),
4133
+ onClick: handleClick,
4134
+ onKeyDown: handleKeyDown,
4135
+ "aria-pressed": selected,
4136
+ ...props,
4137
+ children: /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "flex flex-col justify-between gap-[27px] flex-grow min-h-[67px] w-full min-w-0", children: [
4138
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4139
+ Text_default,
4140
+ {
4141
+ size: "md",
4142
+ weight: "bold",
4143
+ className: "text-text-950 tracking-[0.2px] leading-[19px] truncate",
4144
+ children: title
4145
+ }
4146
+ ),
4147
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "flex flex-row justify-start items-end gap-4 w-full", children: [
4148
+ duration && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "flex flex-row items-center gap-1 flex-shrink-0", children: [
4149
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_phosphor_react10.Clock, { size: 16, className: "text-text-700" }),
4150
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4151
+ Text_default,
4152
+ {
4153
+ size: "sm",
4154
+ className: "text-text-700 leading-[21px] whitespace-nowrap",
4155
+ children: duration
4156
+ }
4157
+ )
4158
+ ] }),
4159
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4160
+ Text_default,
4161
+ {
4162
+ size: "sm",
4163
+ className: "text-text-700 leading-[21px] flex-grow truncate",
4164
+ children: displayInfo
4165
+ }
4166
+ )
4167
+ ] })
4168
+ ] })
4169
+ }
4170
+ );
4171
+ }
4172
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4173
+ "div",
4174
+ {
4175
+ ref,
4176
+ className: `${baseClasses} ${className}`.trim(),
4177
+ ...props,
4178
+ children: /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "flex flex-col justify-between gap-[27px] flex-grow min-h-[67px] w-full min-w-0", children: [
4179
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4180
+ Text_default,
4181
+ {
4182
+ size: "md",
4183
+ weight: "bold",
4184
+ className: "text-text-950 tracking-[0.2px] leading-[19px] truncate",
4185
+ children: title
4186
+ }
4187
+ ),
4188
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "flex flex-row justify-start items-end gap-4 w-full", children: [
4189
+ duration && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "flex flex-row items-center gap-1 flex-shrink-0", children: [
4190
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_phosphor_react10.Clock, { size: 16, className: "text-text-700" }),
4191
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4192
+ Text_default,
4193
+ {
4194
+ size: "sm",
4195
+ className: "text-text-700 leading-[21px] whitespace-nowrap",
4196
+ children: duration
4197
+ }
4198
+ )
4199
+ ] }),
4200
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
4201
+ Text_default,
4202
+ {
4203
+ size: "sm",
4204
+ className: "text-text-700 leading-[21px] flex-grow truncate min-w-0",
4205
+ children: displayInfo
4206
+ }
4207
+ )
4208
+ ] })
4209
+ ] })
4210
+ }
4211
+ );
4212
+ }
4213
+ );
4093
4214
 
4094
4215
  // src/components/Accordation/Accordation.tsx
4095
4216
  var import_phosphor_react11 = require("phosphor-react");
@@ -5753,6 +5874,14 @@ var ProtectedRoute = ({
5753
5874
  return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_jsx_runtime31.Fragment, { children: loadingComponent || defaultLoadingComponent });
5754
5875
  }
5755
5876
  if (!isAuthenticated) {
5877
+ if (typeof window !== "undefined") {
5878
+ const rootDomain = getRootDomain();
5879
+ const currentLocation = `${window.location.protocol}//${window.location.hostname}${window.location.port ? ":" + window.location.port : ""}`;
5880
+ if (rootDomain !== currentLocation) {
5881
+ window.location.href = rootDomain;
5882
+ return null;
5883
+ }
5884
+ }
5756
5885
  return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_react_router_dom.Navigate, { to: redirectTo, replace: true });
5757
5886
  }
5758
5887
  if (additionalCheck && !additionalCheck({ isAuthenticated, isLoading, ...authState })) {
@@ -5798,6 +5927,127 @@ var useRouteAuth = (fallbackPath = "/") => {
5798
5927
  redirectToLogin
5799
5928
  };
5800
5929
  };
5930
+ var getRootDomain = () => {
5931
+ const { hostname, protocol, port } = window.location;
5932
+ const portStr = port ? ":" + port : "";
5933
+ if (hostname === "localhost") {
5934
+ return `${protocol}//${hostname}${portStr}`;
5935
+ }
5936
+ const parts = hostname.split(".");
5937
+ if (parts.length > 2) {
5938
+ const base = parts.slice(-2).join(".");
5939
+ return `${protocol}//${base}${portStr}`;
5940
+ }
5941
+ return `${protocol}//${hostname}${portStr}`;
5942
+ };
5943
+
5944
+ // src/components/Auth/zustandAuthAdapter.ts
5945
+ function createZustandAuthAdapter(useAuthStore) {
5946
+ return {
5947
+ /**
5948
+ * Check if the user is authenticated based on sessionInfo and tokens
5949
+ *
5950
+ * @returns {Promise<boolean>} Promise that resolves to authentication status
5951
+ */
5952
+ checkAuth: async () => {
5953
+ const { sessionInfo, tokens } = useAuthStore.getState();
5954
+ return Boolean(sessionInfo && tokens);
5955
+ },
5956
+ /**
5957
+ * Get the current user from the store
5958
+ *
5959
+ * @returns {unknown} Current user data from the store
5960
+ */
5961
+ getUser: () => useAuthStore.getState().user,
5962
+ /**
5963
+ * Get the current session information from the store
5964
+ *
5965
+ * @returns {unknown} Current session info from the store
5966
+ */
5967
+ getSessionInfo: () => useAuthStore.getState().sessionInfo,
5968
+ /**
5969
+ * Get the current authentication tokens from the store
5970
+ *
5971
+ * @returns {unknown} Current tokens from the store
5972
+ */
5973
+ getTokens: () => useAuthStore.getState().tokens,
5974
+ /**
5975
+ * Sign out the user by calling the store's signOut function if available
5976
+ *
5977
+ * @returns {void}
5978
+ */
5979
+ signOut: () => {
5980
+ const signOutFn = useAuthStore.getState().signOut;
5981
+ if (typeof signOutFn === "function") signOutFn();
5982
+ }
5983
+ };
5984
+ }
5985
+
5986
+ // src/components/Auth/useUrlAuthentication.ts
5987
+ var import_react20 = require("react");
5988
+ var import_react_router_dom2 = require("react-router-dom");
5989
+ var getAuthParams = (location, extractParams) => {
5990
+ const searchParams = new URLSearchParams(location.search);
5991
+ return extractParams ? extractParams(searchParams) : {
5992
+ sessionId: searchParams.get("sessionId"),
5993
+ token: searchParams.get("token"),
5994
+ refreshToken: searchParams.get("refreshToken")
5995
+ };
5996
+ };
5997
+ var hasValidAuthParams = (authParams) => {
5998
+ return !!(authParams?.sessionId && authParams?.token && authParams?.refreshToken);
5999
+ };
6000
+ var hasValidProfileData = (data) => {
6001
+ return data !== null && typeof data === "object" && data !== void 0;
6002
+ };
6003
+ var handleProfileSelection = (responseData, setSelectedProfile) => {
6004
+ if (!setSelectedProfile) return;
6005
+ if (!hasValidProfileData(responseData)) return;
6006
+ const profileId = responseData.profileId;
6007
+ const isValidProfileId = profileId !== null && profileId !== void 0;
6008
+ if (isValidProfileId) {
6009
+ setSelectedProfile({
6010
+ id: profileId
6011
+ });
6012
+ }
6013
+ };
6014
+ function useUrlAuthentication(options) {
6015
+ const location = (0, import_react_router_dom2.useLocation)();
6016
+ (0, import_react20.useEffect)(() => {
6017
+ const handleAuthentication = async () => {
6018
+ const authParams = getAuthParams(location, options.extractParams);
6019
+ if (!hasValidAuthParams(authParams)) {
6020
+ return;
6021
+ }
6022
+ try {
6023
+ options.setTokens({
6024
+ token: authParams.token,
6025
+ refreshToken: authParams.refreshToken
6026
+ });
6027
+ const response = await options.api.get(options.endpoint, {
6028
+ headers: {
6029
+ Authorization: `Bearer ${authParams.token}`
6030
+ }
6031
+ });
6032
+ options.setSessionInfo(response.data.data);
6033
+ handleProfileSelection(response.data.data, options.setSelectedProfile);
6034
+ options.clearParamsFromURL?.();
6035
+ } catch (error) {
6036
+ console.error("Erro ao obter informa\xE7\xF5es da sess\xE3o:", error);
6037
+ }
6038
+ };
6039
+ handleAuthentication();
6040
+ }, [
6041
+ location.search,
6042
+ options.setSessionInfo,
6043
+ options.setSelectedProfile,
6044
+ options.setTokens,
6045
+ options.api,
6046
+ options.endpoint,
6047
+ options.extractParams,
6048
+ options.clearParamsFromURL
6049
+ ]);
6050
+ }
5801
6051
  // Annotate the CommonJS export names for ESM import in node:
5802
6052
  0 && (module.exports = {
5803
6053
  Alert,
@@ -5865,10 +6115,12 @@ var useRouteAuth = (fallbackPath = "/") => {
5865
6115
  TextArea,
5866
6116
  Toast,
5867
6117
  Toaster,
6118
+ createZustandAuthAdapter,
5868
6119
  useAuth,
5869
6120
  useAuthGuard,
5870
6121
  useRouteAuth,
5871
6122
  useToastStore,
6123
+ useUrlAuthentication,
5872
6124
  withAuth
5873
6125
  });
5874
6126
  //# sourceMappingURL=index.js.map