@nocios/crudify-ui 1.0.43 → 1.0.45

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.js CHANGED
@@ -54,16 +54,46 @@ var import_material = require("@mui/material");
54
54
  // src/components/CrudifyLogin/hooks/useCrudifyLogin.ts
55
55
  var import_react = require("react");
56
56
  var import_crudify_browser = __toESM(require("@nocios/crudify-browser"));
57
+
58
+ // src/components/CrudifyLogin/utils/cookies.ts
59
+ var getCookie = (name) => {
60
+ const match = document.cookie.match(new RegExp("(^|;)\\s*" + name + "=([^;]+)"));
61
+ return match ? match[2] : null;
62
+ };
63
+
64
+ // src/components/CrudifyLogin/hooks/useCrudifyLogin.ts
57
65
  var useCrudifyLogin = (config, _options = {}) => {
66
+ const finalConfig = (0, import_react.useMemo)(() => {
67
+ const publicApiKey = config.publicApiKey || getCookie("publicApiKey");
68
+ const env = config.env || getCookie("environment") || "prod";
69
+ const appName = config.appName || getCookie("appName") || "Crudia";
70
+ const loginActions = config.loginActions || (getCookie("loginActions") ?? "").split(",").map((action) => action.trim()).filter(Boolean) || [];
71
+ return {
72
+ publicApiKey,
73
+ env,
74
+ appName,
75
+ loginActions
76
+ };
77
+ }, [config]);
78
+ (0, import_react.useEffect)(() => {
79
+ if (finalConfig.publicApiKey) {
80
+ try {
81
+ import_crudify_browser.default.config(finalConfig.env);
82
+ import_crudify_browser.default.init(finalConfig.publicApiKey, "none");
83
+ } catch (error) {
84
+ console.error("Error initializing crudify:", error);
85
+ }
86
+ }
87
+ }, [finalConfig]);
58
88
  const crudifyMethods = (0, import_react.useMemo)(() => {
59
- if (!config.publicApiKey) {
89
+ if (!finalConfig.publicApiKey) {
60
90
  return null;
61
91
  }
62
92
  return {
63
93
  login: import_crudify_browser.default.login,
64
94
  transaction: import_crudify_browser.default.transaction
65
95
  };
66
- }, [config.publicApiKey, config.env]);
96
+ }, [finalConfig.publicApiKey]);
67
97
  return { crudify: crudifyMethods };
68
98
  };
69
99
 
@@ -891,12 +921,6 @@ var CheckCodeForm = ({ config, onNavigate, onError }) => {
891
921
  };
892
922
  var CheckCodeForm_default = CheckCodeForm;
893
923
 
894
- // src/components/CrudifyLogin/utils/cookies.ts
895
- var getCookie = (name) => {
896
- const match = document.cookie.match(new RegExp("(^|;)\\s*" + name + "=([^;]+)"));
897
- return match ? match[2] : null;
898
- };
899
-
900
924
  // src/components/CrudifyLogin/index.tsx
901
925
  var import_jsx_runtime5 = require("react/jsx-runtime");
902
926
  var CrudifyLogin = ({
@@ -915,10 +939,6 @@ var CrudifyLogin = ({
915
939
  let cookieConfig = {};
916
940
  if (autoReadFromCookies) {
917
941
  try {
918
- const publicApiKeyFromCookie = getCookie("publicApiKey");
919
- const envFromCookie = getCookie("environment") || "prod";
920
- const appNameFromCookie = getCookie("appName") || "Crudia";
921
- const loginActionsFromCookie = (getCookie("loginActions") ?? "").split(",").map((action) => action.trim()).filter(Boolean);
922
942
  let logoValue;
923
943
  let appColorsValue = { primaryColor: "#1066BA" };
924
944
  try {
@@ -941,10 +961,6 @@ var CrudifyLogin = ({
941
961
  console.error("Failed to parse colors from cookie, using defaults.", e);
942
962
  }
943
963
  cookieConfig = {
944
- publicApiKey: publicApiKeyFromCookie || void 0,
945
- env: envFromCookie,
946
- appName: decodeURIComponent(appNameFromCookie),
947
- loginActions: loginActionsFromCookie,
948
964
  logo: logoValue,
949
965
  colors: appColorsValue
950
966
  };
@@ -953,12 +969,12 @@ var CrudifyLogin = ({
953
969
  }
954
970
  }
955
971
  return {
956
- publicApiKey: providedConfig?.publicApiKey || cookieConfig.publicApiKey,
957
- env: providedConfig?.env || cookieConfig.env || "prod",
958
- appName: providedConfig?.appName || cookieConfig.appName || "Crudia",
972
+ publicApiKey: providedConfig?.publicApiKey,
973
+ env: providedConfig?.env,
974
+ appName: providedConfig?.appName,
959
975
  logo: providedConfig?.logo || cookieConfig.logo,
960
976
  colors: { ...cookieConfig.colors, ...providedConfig?.colors },
961
- loginActions: providedConfig?.loginActions || cookieConfig.loginActions || []
977
+ loginActions: providedConfig?.loginActions
962
978
  };
963
979
  }, [providedConfig, autoReadFromCookies]);
964
980
  const handleNavigate = (path) => {
package/dist/index.mjs CHANGED
@@ -9,22 +9,52 @@ import { Paper, Box as Box5, Typography as Typography5 } from "@mui/material";
9
9
 
10
10
  // src/components/CrudifyLogin/Forms/LoginForm.tsx
11
11
  import { useTranslation } from "react-i18next";
12
- import { useState, useEffect, useRef } from "react";
12
+ import { useState, useEffect as useEffect2, useRef } from "react";
13
13
  import { Typography, TextField, Button, Box, CircularProgress, Alert, Link } from "@mui/material";
14
14
 
15
15
  // src/components/CrudifyLogin/hooks/useCrudifyLogin.ts
16
- import { useMemo } from "react";
16
+ import { useMemo, useEffect } from "react";
17
17
  import crudify from "@nocios/crudify-browser";
18
+
19
+ // src/components/CrudifyLogin/utils/cookies.ts
20
+ var getCookie = (name) => {
21
+ const match = document.cookie.match(new RegExp("(^|;)\\s*" + name + "=([^;]+)"));
22
+ return match ? match[2] : null;
23
+ };
24
+
25
+ // src/components/CrudifyLogin/hooks/useCrudifyLogin.ts
18
26
  var useCrudifyLogin = (config, _options = {}) => {
27
+ const finalConfig = useMemo(() => {
28
+ const publicApiKey = config.publicApiKey || getCookie("publicApiKey");
29
+ const env = config.env || getCookie("environment") || "prod";
30
+ const appName = config.appName || getCookie("appName") || "Crudia";
31
+ const loginActions = config.loginActions || (getCookie("loginActions") ?? "").split(",").map((action) => action.trim()).filter(Boolean) || [];
32
+ return {
33
+ publicApiKey,
34
+ env,
35
+ appName,
36
+ loginActions
37
+ };
38
+ }, [config]);
39
+ useEffect(() => {
40
+ if (finalConfig.publicApiKey) {
41
+ try {
42
+ crudify.config(finalConfig.env);
43
+ crudify.init(finalConfig.publicApiKey, "none");
44
+ } catch (error) {
45
+ console.error("Error initializing crudify:", error);
46
+ }
47
+ }
48
+ }, [finalConfig]);
19
49
  const crudifyMethods = useMemo(() => {
20
- if (!config.publicApiKey) {
50
+ if (!finalConfig.publicApiKey) {
21
51
  return null;
22
52
  }
23
53
  return {
24
54
  login: crudify.login,
25
55
  transaction: crudify.transaction
26
56
  };
27
- }, [config.publicApiKey, config.env]);
57
+ }, [finalConfig.publicApiKey]);
28
58
  return { crudify: crudifyMethods };
29
59
  };
30
60
 
@@ -152,7 +182,7 @@ var LoginForm = ({ config, onNavigate, onLoginSuccess, onError, redirectUrl = "/
152
182
  showErrorNotifications: false,
153
183
  showSuccessNotifications: false
154
184
  });
155
- useEffect(() => {
185
+ useEffect2(() => {
156
186
  const timer = setTimeout(() => {
157
187
  if (usernameInputRef.current) usernameInputRef.current.focus();
158
188
  }, 100);
@@ -473,7 +503,7 @@ var ForgotPasswordForm_default = ForgotPasswordForm;
473
503
 
474
504
  // src/components/CrudifyLogin/Forms/ResetPasswordForm.tsx
475
505
  import { useTranslation as useTranslation3 } from "react-i18next";
476
- import { useState as useState3, useEffect as useEffect2 } from "react";
506
+ import { useState as useState3, useEffect as useEffect3 } from "react";
477
507
  import { Typography as Typography3, TextField as TextField3, Button as Button3, Box as Box3, CircularProgress as CircularProgress3, Alert as Alert3, Link as Link3 } from "@mui/material";
478
508
  import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
479
509
  var ResetPasswordForm = ({ config, onNavigate, onError, searchParams }) => {
@@ -490,7 +520,7 @@ var ResetPasswordForm = ({ config, onNavigate, onError, searchParams }) => {
490
520
  const [resetSuccess, setResetSuccess] = useState3(false);
491
521
  const { t } = useTranslation3();
492
522
  const { crudify: crudify2 } = useCrudifyLogin(config);
493
- useEffect2(() => {
523
+ useEffect3(() => {
494
524
  const validateCode = async (emailToValidate, codeToValidate) => {
495
525
  if (!crudify2) return;
496
526
  try {
@@ -695,7 +725,7 @@ var ResetPasswordForm_default = ResetPasswordForm;
695
725
 
696
726
  // src/components/CrudifyLogin/Forms/CheckCodeForm.tsx
697
727
  import { useTranslation as useTranslation4 } from "react-i18next";
698
- import { useState as useState4, useEffect as useEffect3 } from "react";
728
+ import { useState as useState4, useEffect as useEffect4 } from "react";
699
729
  import { Typography as Typography4, TextField as TextField4, Button as Button4, Box as Box4, CircularProgress as CircularProgress4, Alert as Alert4, Link as Link4 } from "@mui/material";
700
730
  import { Fragment as Fragment4, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
701
731
  var CheckCodeForm = ({ config, onNavigate, onError }) => {
@@ -707,7 +737,7 @@ var CheckCodeForm = ({ config, onNavigate, onError }) => {
707
737
  const [helperTextCode, setHelperTextCode] = useState4(null);
708
738
  const { t } = useTranslation4();
709
739
  const { crudify: crudify2 } = useCrudifyLogin(config);
710
- useEffect3(() => {
740
+ useEffect4(() => {
711
741
  const timer = setTimeout(() => {
712
742
  const emailInput = document.getElementById("email");
713
743
  if (emailInput) emailInput.focus();
@@ -852,12 +882,6 @@ var CheckCodeForm = ({ config, onNavigate, onError }) => {
852
882
  };
853
883
  var CheckCodeForm_default = CheckCodeForm;
854
884
 
855
- // src/components/CrudifyLogin/utils/cookies.ts
856
- var getCookie = (name) => {
857
- const match = document.cookie.match(new RegExp("(^|;)\\s*" + name + "=([^;]+)"));
858
- return match ? match[2] : null;
859
- };
860
-
861
885
  // src/components/CrudifyLogin/index.tsx
862
886
  import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
863
887
  var CrudifyLogin = ({
@@ -876,10 +900,6 @@ var CrudifyLogin = ({
876
900
  let cookieConfig = {};
877
901
  if (autoReadFromCookies) {
878
902
  try {
879
- const publicApiKeyFromCookie = getCookie("publicApiKey");
880
- const envFromCookie = getCookie("environment") || "prod";
881
- const appNameFromCookie = getCookie("appName") || "Crudia";
882
- const loginActionsFromCookie = (getCookie("loginActions") ?? "").split(",").map((action) => action.trim()).filter(Boolean);
883
903
  let logoValue;
884
904
  let appColorsValue = { primaryColor: "#1066BA" };
885
905
  try {
@@ -902,10 +922,6 @@ var CrudifyLogin = ({
902
922
  console.error("Failed to parse colors from cookie, using defaults.", e);
903
923
  }
904
924
  cookieConfig = {
905
- publicApiKey: publicApiKeyFromCookie || void 0,
906
- env: envFromCookie,
907
- appName: decodeURIComponent(appNameFromCookie),
908
- loginActions: loginActionsFromCookie,
909
925
  logo: logoValue,
910
926
  colors: appColorsValue
911
927
  };
@@ -914,12 +930,12 @@ var CrudifyLogin = ({
914
930
  }
915
931
  }
916
932
  return {
917
- publicApiKey: providedConfig?.publicApiKey || cookieConfig.publicApiKey,
918
- env: providedConfig?.env || cookieConfig.env || "prod",
919
- appName: providedConfig?.appName || cookieConfig.appName || "Crudia",
933
+ publicApiKey: providedConfig?.publicApiKey,
934
+ env: providedConfig?.env,
935
+ appName: providedConfig?.appName,
920
936
  logo: providedConfig?.logo || cookieConfig.logo,
921
937
  colors: { ...cookieConfig.colors, ...providedConfig?.colors },
922
- loginActions: providedConfig?.loginActions || cookieConfig.loginActions || []
938
+ loginActions: providedConfig?.loginActions
923
939
  };
924
940
  }, [providedConfig, autoReadFromCookies]);
925
941
  const handleNavigate = (path) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocios/crudify-ui",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "description": "Biblioteca de componentes UI para Crudify",
5
5
  "author": "Nocios",
6
6
  "license": "MIT",
@@ -25,7 +25,7 @@
25
25
  "@mui/icons-material": "^7.1.0",
26
26
  "@mui/material": "^7.1.0",
27
27
  "@mui/x-data-grid": "^8.5.1",
28
- "@nocios/crudify-browser": "^1.0.84",
28
+ "@nocios/crudify-browser": "^1.0.85",
29
29
  "crypto-js": "^4.2.0",
30
30
  "i18next-browser-languagedetector": "^8.1.0",
31
31
  "i18next-http-backend": "^3.0.2",