@nocios/crudify-ui 2.0.1 → 3.0.1
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 +92 -788
- package/dist/index.d.ts +92 -788
- package/dist/index.js +1555 -3275
- package/dist/index.mjs +291 -741
- package/package.json +1 -1
- package/dist/CrudifyDataProvider-5GXGNQKI.mjs +0 -16
- package/dist/TokenManager-AYUNIXQU.mjs +0 -8
- package/dist/chunk-GY5F6KOF.mjs +0 -701
- package/dist/chunk-M7V4UGCN.mjs +0 -512
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CrudifyDataProvider,
|
|
3
|
-
configurationManager,
|
|
4
|
-
crudifyInitializer,
|
|
5
|
-
getCookie,
|
|
6
|
-
useCrudifyDataContext
|
|
7
|
-
} from "./chunk-GY5F6KOF.mjs";
|
|
8
|
-
import {
|
|
9
|
-
decodeJwtSafely,
|
|
10
|
-
getCurrentUserEmail,
|
|
11
|
-
isTokenExpired,
|
|
12
|
-
secureLocalStorage,
|
|
13
|
-
secureSessionStorage,
|
|
14
|
-
tokenManager
|
|
15
|
-
} from "./chunk-M7V4UGCN.mjs";
|
|
16
|
-
|
|
17
1
|
// src/index.ts
|
|
18
2
|
import { default as default2 } from "@nocios/crudify-browser";
|
|
19
3
|
export * from "@nocios/crudify-browser";
|
|
@@ -177,6 +161,14 @@ var useCrudify = () => {
|
|
|
177
161
|
|
|
178
162
|
// src/components/CrudifyLogin/context/LoginStateProvider.tsx
|
|
179
163
|
import { createContext as createContext3, useContext as useContext3, useReducer, useEffect as useEffect3 } from "react";
|
|
164
|
+
|
|
165
|
+
// src/components/CrudifyLogin/utils/cookies.ts
|
|
166
|
+
var getCookie = (name) => {
|
|
167
|
+
const match = document.cookie.match(new RegExp("(^|;)\\s*" + name + "=([^;]+)"));
|
|
168
|
+
return match ? match[2] : null;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// src/components/CrudifyLogin/context/LoginStateProvider.tsx
|
|
180
172
|
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
181
173
|
var initialState = {
|
|
182
174
|
currentScreen: "login",
|
|
@@ -364,8 +356,8 @@ var LoginStateProvider = ({
|
|
|
364
356
|
dispatch({ type: "SET_SEARCH_PARAMS", payload: paramsObject });
|
|
365
357
|
}
|
|
366
358
|
}, [initialScreen]);
|
|
367
|
-
const setScreen = (
|
|
368
|
-
dispatch({ type: "SET_SCREEN", payload: { screen, params } });
|
|
359
|
+
const setScreen = (screen2, params) => {
|
|
360
|
+
dispatch({ type: "SET_SCREEN", payload: { screen: screen2, params } });
|
|
369
361
|
};
|
|
370
362
|
const updateFormData = (data) => {
|
|
371
363
|
dispatch({ type: "UPDATE_FORM_DATA", payload: data });
|
|
@@ -672,41 +664,11 @@ function handleCrudifyError(error) {
|
|
|
672
664
|
];
|
|
673
665
|
}
|
|
674
666
|
|
|
675
|
-
// src/hooks/useCrudifyAuth.ts
|
|
676
|
-
var useCrudifyAuth = () => {
|
|
677
|
-
const {
|
|
678
|
-
isAuthenticated,
|
|
679
|
-
isInitializing,
|
|
680
|
-
initializationError,
|
|
681
|
-
token,
|
|
682
|
-
user,
|
|
683
|
-
tokenExpiration,
|
|
684
|
-
setToken,
|
|
685
|
-
logout
|
|
686
|
-
} = useCrudifyDataContext();
|
|
687
|
-
return {
|
|
688
|
-
// Estado básico
|
|
689
|
-
isAuthenticated,
|
|
690
|
-
loading: isInitializing,
|
|
691
|
-
error: initializationError,
|
|
692
|
-
// Datos del token
|
|
693
|
-
token,
|
|
694
|
-
user,
|
|
695
|
-
tokenExpiration,
|
|
696
|
-
// Acciones
|
|
697
|
-
setToken,
|
|
698
|
-
logout,
|
|
699
|
-
refreshToken: void 0
|
|
700
|
-
// Will be implemented in future versions
|
|
701
|
-
};
|
|
702
|
-
};
|
|
703
|
-
|
|
704
667
|
// src/components/CrudifyLogin/Forms/LoginForm.tsx
|
|
705
668
|
import { Fragment, jsx as jsx4, jsxs } from "react/jsx-runtime";
|
|
706
669
|
var LoginForm = ({ onScreenChange, onExternalNavigate, onLoginSuccess, onError, redirectUrl = "/" }) => {
|
|
707
|
-
const { crudify:
|
|
670
|
+
const { crudify: crudify7 } = useCrudify();
|
|
708
671
|
const { state, updateFormData, setFieldError, clearErrors, setLoading } = useLoginState();
|
|
709
|
-
const { setToken } = useCrudifyAuth();
|
|
710
672
|
const { t } = useTranslation();
|
|
711
673
|
const usernameInputRef = useRef(null);
|
|
712
674
|
const getRedirectUrl = () => {
|
|
@@ -756,25 +718,17 @@ var LoginForm = ({ onScreenChange, onExternalNavigate, onLoginSuccess, onError,
|
|
|
756
718
|
clearErrors();
|
|
757
719
|
setLoading(true);
|
|
758
720
|
try {
|
|
759
|
-
if (!
|
|
721
|
+
if (!crudify7) {
|
|
760
722
|
throw new Error("Crudify not initialized");
|
|
761
723
|
}
|
|
762
|
-
const response = await
|
|
724
|
+
const response = await crudify7.login(state.formData.username, state.formData.password);
|
|
763
725
|
setLoading(false);
|
|
764
726
|
if (response.success) {
|
|
765
|
-
console.log("\u{1F510} LoginForm - Login successful,
|
|
766
|
-
secureSessionStorage.setToken(response.data.token);
|
|
767
|
-
console.log("\u{1F510} LoginForm - Token set in secureSessionStorage");
|
|
768
|
-
console.log("\u{1F510} LoginForm - Setting token in CrudifyDataProvider via setToken hook");
|
|
769
|
-
setToken(response.data.token);
|
|
770
|
-
console.log("\u{1F510} LoginForm - Token set in CrudifyDataProvider");
|
|
727
|
+
console.log("\u{1F510} LoginForm - Login successful, calling onLoginSuccess");
|
|
771
728
|
const finalRedirectUrl = getRedirectUrl();
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
onLoginSuccess(response.data, finalRedirectUrl);
|
|
776
|
-
}
|
|
777
|
-
}, 100);
|
|
729
|
+
if (onLoginSuccess) {
|
|
730
|
+
onLoginSuccess(response.data, finalRedirectUrl);
|
|
731
|
+
}
|
|
778
732
|
} else {
|
|
779
733
|
handleLoginError(response);
|
|
780
734
|
}
|
|
@@ -922,7 +876,7 @@ import { useState as useState3 } from "react";
|
|
|
922
876
|
import { Typography as Typography2, TextField as TextField2, Button as Button2, Box as Box2, CircularProgress as CircularProgress2, Alert as Alert2, Link as Link2 } from "@mui/material";
|
|
923
877
|
import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
924
878
|
var ForgotPasswordForm = ({ onScreenChange, onError }) => {
|
|
925
|
-
const { crudify:
|
|
879
|
+
const { crudify: crudify7 } = useCrudify();
|
|
926
880
|
const [email, setEmail] = useState3("");
|
|
927
881
|
const [loading, setLoading] = useState3(false);
|
|
928
882
|
const [errors, setErrors] = useState3([]);
|
|
@@ -951,7 +905,7 @@ var ForgotPasswordForm = ({ onScreenChange, onError }) => {
|
|
|
951
905
|
return emailRegex.test(email2);
|
|
952
906
|
};
|
|
953
907
|
const handleSubmit = async () => {
|
|
954
|
-
if (loading || !
|
|
908
|
+
if (loading || !crudify7) return;
|
|
955
909
|
setErrors([]);
|
|
956
910
|
setHelperTextEmail(null);
|
|
957
911
|
if (!email) {
|
|
@@ -965,7 +919,7 @@ var ForgotPasswordForm = ({ onScreenChange, onError }) => {
|
|
|
965
919
|
setLoading(true);
|
|
966
920
|
try {
|
|
967
921
|
const data = [{ operation: "requestPasswordReset", data: { email } }];
|
|
968
|
-
const response = await
|
|
922
|
+
const response = await crudify7.transaction(data);
|
|
969
923
|
if (response.success) {
|
|
970
924
|
if (response.data && response.data.existingCodeValid) {
|
|
971
925
|
setCodeAlreadyExists(true);
|
|
@@ -1068,7 +1022,7 @@ import { useState as useState4, useEffect as useEffect5 } from "react";
|
|
|
1068
1022
|
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";
|
|
1069
1023
|
import { Fragment as Fragment3, jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1070
1024
|
var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess }) => {
|
|
1071
|
-
const { crudify:
|
|
1025
|
+
const { crudify: crudify7 } = useCrudify();
|
|
1072
1026
|
const [newPassword, setNewPassword] = useState4("");
|
|
1073
1027
|
const [confirmPassword, setConfirmPassword] = useState4("");
|
|
1074
1028
|
const [loading, setLoading] = useState4(false);
|
|
@@ -1148,9 +1102,9 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
1148
1102
|
setErrors([t("resetPassword.invalidCode")]);
|
|
1149
1103
|
setValidatingCode(false);
|
|
1150
1104
|
setTimeout(() => onScreenChange?.("forgotPassword"), 3e3);
|
|
1151
|
-
}, [searchParams,
|
|
1105
|
+
}, [searchParams, crudify7, t, onScreenChange]);
|
|
1152
1106
|
useEffect5(() => {
|
|
1153
|
-
if (
|
|
1107
|
+
if (crudify7 && pendingValidation && !isValidating) {
|
|
1154
1108
|
setIsValidating(true);
|
|
1155
1109
|
const validateCode = async (emailToValidate, codeToValidate) => {
|
|
1156
1110
|
try {
|
|
@@ -1160,7 +1114,7 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
1160
1114
|
data: { email: emailToValidate, codePassword: codeToValidate }
|
|
1161
1115
|
}
|
|
1162
1116
|
];
|
|
1163
|
-
const response = await
|
|
1117
|
+
const response = await crudify7.transaction(data);
|
|
1164
1118
|
if (response.data && Array.isArray(response.data)) {
|
|
1165
1119
|
const validationResult = response.data[0];
|
|
1166
1120
|
if (validationResult && validationResult.response && validationResult.response.status === "OK") {
|
|
@@ -1189,7 +1143,7 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
1189
1143
|
};
|
|
1190
1144
|
validateCode(pendingValidation.email, pendingValidation.code);
|
|
1191
1145
|
}
|
|
1192
|
-
}, [
|
|
1146
|
+
}, [crudify7, pendingValidation, t, onScreenChange]);
|
|
1193
1147
|
const validatePassword = (password) => {
|
|
1194
1148
|
if (password.length < 8) {
|
|
1195
1149
|
return t("resetPassword.passwordTooShort");
|
|
@@ -1197,7 +1151,7 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
1197
1151
|
return null;
|
|
1198
1152
|
};
|
|
1199
1153
|
const handleSubmit = async () => {
|
|
1200
|
-
if (loading || !
|
|
1154
|
+
if (loading || !crudify7) return;
|
|
1201
1155
|
setErrors([]);
|
|
1202
1156
|
setHelperTextNewPassword(null);
|
|
1203
1157
|
setHelperTextConfirmPassword(null);
|
|
@@ -1228,7 +1182,7 @@ var ResetPasswordForm = ({ onScreenChange, onError, searchParams, onResetSuccess
|
|
|
1228
1182
|
data: { email, codePassword: code, newPassword }
|
|
1229
1183
|
}
|
|
1230
1184
|
];
|
|
1231
|
-
const response = await
|
|
1185
|
+
const response = await crudify7.transaction(data);
|
|
1232
1186
|
if (response.success) {
|
|
1233
1187
|
setErrors([]);
|
|
1234
1188
|
setTimeout(() => {
|
|
@@ -1339,7 +1293,7 @@ import { useState as useState5, useEffect as useEffect6 } from "react";
|
|
|
1339
1293
|
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";
|
|
1340
1294
|
import { Fragment as Fragment4, jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1341
1295
|
var CheckCodeForm = ({ onScreenChange, onError, searchParams }) => {
|
|
1342
|
-
const { crudify:
|
|
1296
|
+
const { crudify: crudify7 } = useCrudify();
|
|
1343
1297
|
const [code, setCode] = useState5("");
|
|
1344
1298
|
const [loading, setLoading] = useState5(false);
|
|
1345
1299
|
const [errors, setErrors] = useState5([]);
|
|
@@ -1378,7 +1332,7 @@ var CheckCodeForm = ({ onScreenChange, onError, searchParams }) => {
|
|
|
1378
1332
|
}
|
|
1379
1333
|
}, [searchParams, onScreenChange]);
|
|
1380
1334
|
const handleSubmit = async () => {
|
|
1381
|
-
if (loading || !
|
|
1335
|
+
if (loading || !crudify7) return;
|
|
1382
1336
|
setErrors([]);
|
|
1383
1337
|
setHelperTextCode(null);
|
|
1384
1338
|
if (!code) {
|
|
@@ -1397,7 +1351,7 @@ var CheckCodeForm = ({ onScreenChange, onError, searchParams }) => {
|
|
|
1397
1351
|
data: { email, codePassword: code }
|
|
1398
1352
|
}
|
|
1399
1353
|
];
|
|
1400
|
-
const response = await
|
|
1354
|
+
const response = await crudify7.transaction(data);
|
|
1401
1355
|
if (response.success) {
|
|
1402
1356
|
onScreenChange?.("resetPassword", { email, code, fromCodeVerification: "true" });
|
|
1403
1357
|
} else {
|
|
@@ -1522,49 +1476,44 @@ var CrudifyInitializer = ({ children, fallback }) => {
|
|
|
1522
1476
|
|
|
1523
1477
|
// src/components/CrudifyLogin/hooks/useCrudifyLogin.ts
|
|
1524
1478
|
import { useMemo as useMemo2 } from "react";
|
|
1525
|
-
|
|
1526
|
-
// src/hooks/useCrudifyConfig.ts
|
|
1527
|
-
var useCrudifyConfig = () => {
|
|
1528
|
-
const {
|
|
1529
|
-
config,
|
|
1530
|
-
isConfigured,
|
|
1531
|
-
configError,
|
|
1532
|
-
configSource,
|
|
1533
|
-
refreshConfig,
|
|
1534
|
-
getDebugInfo
|
|
1535
|
-
} = useCrudifyDataContext();
|
|
1536
|
-
return {
|
|
1537
|
-
config,
|
|
1538
|
-
isConfigured,
|
|
1539
|
-
configError,
|
|
1540
|
-
configSource,
|
|
1541
|
-
rawConfig: config?.rawConfig || {},
|
|
1542
|
-
refreshConfig,
|
|
1543
|
-
getDebugInfo
|
|
1544
|
-
};
|
|
1545
|
-
};
|
|
1546
|
-
|
|
1547
|
-
// src/components/CrudifyLogin/hooks/useCrudifyLogin.ts
|
|
1479
|
+
import crudify2 from "@nocios/crudify-browser";
|
|
1548
1480
|
var useCrudifyLogin = (config, _options = {}) => {
|
|
1549
|
-
const { config: dataProviderConfig, isConfigured } = useCrudifyConfig();
|
|
1550
1481
|
console.log("\u{1F50D} useCrudifyLogin - Input config:", config);
|
|
1551
|
-
console.log("\u{1F50D} useCrudifyLogin - DataProvider config:", dataProviderConfig);
|
|
1552
|
-
console.log("\u{1F50D} useCrudifyLogin - IsConfigured:", isConfigured);
|
|
1553
1482
|
const finalConfig = useMemo2(() => {
|
|
1554
|
-
|
|
1483
|
+
let crudifyConfig = null;
|
|
1484
|
+
try {
|
|
1485
|
+
console.log("\u{1F50D} useCrudifyLogin - Crudify instance:", crudify2);
|
|
1486
|
+
console.log("\u{1F50D} useCrudifyLogin - Crudify methods:", Object.keys(crudify2 || {}));
|
|
1487
|
+
console.log("\u{1F50D} useCrudifyLogin - Crudify.config:", crudify2?.config);
|
|
1488
|
+
if (crudify2 && crudify2.config) {
|
|
1489
|
+
crudifyConfig = crudify2.config;
|
|
1490
|
+
}
|
|
1491
|
+
if (!crudifyConfig && crudify2 && typeof crudify2.getConfiguration === "function") {
|
|
1492
|
+
crudifyConfig = crudify2.getConfiguration();
|
|
1493
|
+
}
|
|
1494
|
+
if (!crudifyConfig && crudify2 && crudify2.env) {
|
|
1495
|
+
crudifyConfig = {
|
|
1496
|
+
env: crudify2.env,
|
|
1497
|
+
publicApiKey: crudify2.publicApiKey || crudify2.apiKey
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
} catch (error) {
|
|
1501
|
+
console.log("\u{1F50D} useCrudifyLogin - No crudify instance config available:", error);
|
|
1502
|
+
}
|
|
1503
|
+
const publicApiKey = config.publicApiKey || crudifyConfig?.publicApiKey || getCookie("publicApiKey") || null;
|
|
1555
1504
|
console.log("\u{1F50D} useCrudifyLogin - Resolved publicApiKey:", publicApiKey);
|
|
1556
1505
|
console.log(
|
|
1557
1506
|
"\u{1F50D} useCrudifyLogin - Sources - props:",
|
|
1558
1507
|
config.publicApiKey,
|
|
1559
|
-
"
|
|
1560
|
-
|
|
1508
|
+
"crudify:",
|
|
1509
|
+
crudifyConfig?.publicApiKey,
|
|
1561
1510
|
"cookie:",
|
|
1562
1511
|
getCookie("publicApiKey")
|
|
1563
1512
|
);
|
|
1564
|
-
const rawEnv = config.env ||
|
|
1513
|
+
const rawEnv = config.env || crudifyConfig?.env || getCookie("environment") || "prod";
|
|
1565
1514
|
const env = ["dev", "stg", "prod"].includes(rawEnv) ? rawEnv : "prod";
|
|
1566
|
-
const appName = config.appName ||
|
|
1567
|
-
const loginActions = config.loginActions ||
|
|
1515
|
+
const appName = config.appName || crudifyConfig?.appName || getCookie("appName") || "Crudia";
|
|
1516
|
+
const loginActions = config.loginActions || crudifyConfig?.loginActions || (() => {
|
|
1568
1517
|
try {
|
|
1569
1518
|
const cookieValue = getCookie("loginActions");
|
|
1570
1519
|
return cookieValue ? cookieValue.split(",").map((action) => action.trim()).filter(Boolean) : [];
|
|
@@ -1580,7 +1529,7 @@ var useCrudifyLogin = (config, _options = {}) => {
|
|
|
1580
1529
|
};
|
|
1581
1530
|
console.log("\u{1F50D} useCrudifyLogin - Final config result:", finalResult);
|
|
1582
1531
|
return finalResult;
|
|
1583
|
-
}, [config
|
|
1532
|
+
}, [config]);
|
|
1584
1533
|
return { config: finalConfig };
|
|
1585
1534
|
};
|
|
1586
1535
|
|
|
@@ -1595,15 +1544,15 @@ var CrudifyLoginInternal = ({
|
|
|
1595
1544
|
}) => {
|
|
1596
1545
|
const { t } = useTranslation();
|
|
1597
1546
|
const { state, setScreen } = useLoginState();
|
|
1598
|
-
const handleScreenChange = (
|
|
1547
|
+
const handleScreenChange = (screen2, params) => {
|
|
1599
1548
|
let finalParams = params;
|
|
1600
|
-
if (
|
|
1549
|
+
if (screen2 === "login") {
|
|
1601
1550
|
finalParams = {};
|
|
1602
|
-
} else if (
|
|
1551
|
+
} else if (screen2 === "forgotPassword" && !params) {
|
|
1603
1552
|
finalParams = {};
|
|
1604
1553
|
}
|
|
1605
|
-
setScreen(
|
|
1606
|
-
onScreenChange?.(
|
|
1554
|
+
setScreen(screen2, finalParams);
|
|
1555
|
+
onScreenChange?.(screen2, finalParams);
|
|
1607
1556
|
};
|
|
1608
1557
|
const renderCurrentForm = () => {
|
|
1609
1558
|
const commonProps = {
|
|
@@ -1711,7 +1660,67 @@ import {
|
|
|
1711
1660
|
|
|
1712
1661
|
// src/hooks/useUserProfile.ts
|
|
1713
1662
|
import { useState as useState6, useEffect as useEffect7, useCallback, useRef as useRef2 } from "react";
|
|
1714
|
-
import
|
|
1663
|
+
import crudify3 from "@nocios/crudify-browser";
|
|
1664
|
+
|
|
1665
|
+
// src/utils/jwtUtils.ts
|
|
1666
|
+
var decodeJwtSafely = (token) => {
|
|
1667
|
+
try {
|
|
1668
|
+
const parts = token.split(".");
|
|
1669
|
+
if (parts.length !== 3) {
|
|
1670
|
+
console.warn("Invalid JWT format: token must have 3 parts");
|
|
1671
|
+
return null;
|
|
1672
|
+
}
|
|
1673
|
+
const payload = parts[1];
|
|
1674
|
+
const paddedPayload = payload + "=".repeat((4 - payload.length % 4) % 4);
|
|
1675
|
+
const decodedPayload = JSON.parse(atob(paddedPayload));
|
|
1676
|
+
return decodedPayload;
|
|
1677
|
+
} catch (error) {
|
|
1678
|
+
console.warn("Failed to decode JWT token:", error);
|
|
1679
|
+
return null;
|
|
1680
|
+
}
|
|
1681
|
+
};
|
|
1682
|
+
var getCurrentUserEmail = () => {
|
|
1683
|
+
try {
|
|
1684
|
+
let token = null;
|
|
1685
|
+
token = sessionStorage.getItem("authToken");
|
|
1686
|
+
console.log("\u{1F50D} getCurrentUserEmail - authToken:", token ? `${token.substring(0, 20)}...` : null);
|
|
1687
|
+
if (!token) {
|
|
1688
|
+
token = sessionStorage.getItem("token");
|
|
1689
|
+
console.log("\u{1F50D} getCurrentUserEmail - token:", token ? `${token.substring(0, 20)}...` : null);
|
|
1690
|
+
}
|
|
1691
|
+
if (!token) {
|
|
1692
|
+
token = localStorage.getItem("authToken") || localStorage.getItem("token");
|
|
1693
|
+
console.log("\u{1F50D} getCurrentUserEmail - localStorage:", token ? `${token.substring(0, 20)}...` : null);
|
|
1694
|
+
}
|
|
1695
|
+
if (!token) {
|
|
1696
|
+
console.warn("\u{1F50D} getCurrentUserEmail - No token found in any storage");
|
|
1697
|
+
return null;
|
|
1698
|
+
}
|
|
1699
|
+
const payload = decodeJwtSafely(token);
|
|
1700
|
+
if (!payload) {
|
|
1701
|
+
console.warn("\u{1F50D} getCurrentUserEmail - Failed to decode token");
|
|
1702
|
+
return null;
|
|
1703
|
+
}
|
|
1704
|
+
const email = payload.email || payload["cognito:username"] || null;
|
|
1705
|
+
console.log("\u{1F50D} getCurrentUserEmail - Extracted email:", email);
|
|
1706
|
+
return email;
|
|
1707
|
+
} catch (error) {
|
|
1708
|
+
console.warn("Failed to get current user email:", error);
|
|
1709
|
+
return null;
|
|
1710
|
+
}
|
|
1711
|
+
};
|
|
1712
|
+
var isTokenExpired = (token) => {
|
|
1713
|
+
try {
|
|
1714
|
+
const payload = decodeJwtSafely(token);
|
|
1715
|
+
if (!payload || !payload.exp) return true;
|
|
1716
|
+
const currentTime = Math.floor(Date.now() / 1e3);
|
|
1717
|
+
return payload.exp < currentTime;
|
|
1718
|
+
} catch {
|
|
1719
|
+
return true;
|
|
1720
|
+
}
|
|
1721
|
+
};
|
|
1722
|
+
|
|
1723
|
+
// src/hooks/useUserProfile.ts
|
|
1715
1724
|
var useUserProfile = (options = {}) => {
|
|
1716
1725
|
const { autoFetch = true, retryOnError = false, maxRetries = 3 } = options;
|
|
1717
1726
|
const [userProfile, setUserProfile] = useState6(null);
|
|
@@ -1748,7 +1757,7 @@ var useUserProfile = (options = {}) => {
|
|
|
1748
1757
|
setLoading(true);
|
|
1749
1758
|
setError(null);
|
|
1750
1759
|
}
|
|
1751
|
-
const response = await
|
|
1760
|
+
const response = await crudify3.readItems("users", {
|
|
1752
1761
|
filter: { email: userEmail },
|
|
1753
1762
|
pagination: { limit: 1 }
|
|
1754
1763
|
});
|
|
@@ -2639,563 +2648,8 @@ var Policies = ({
|
|
|
2639
2648
|
};
|
|
2640
2649
|
var Policies_default = Policies;
|
|
2641
2650
|
|
|
2642
|
-
// src/hooks/useCrudifyUser.ts
|
|
2643
|
-
import { useState as useState9, useEffect as useEffect9, useCallback as useCallback2, useRef as useRef5 } from "react";
|
|
2644
|
-
import crudify3 from "@nocios/crudify-browser";
|
|
2645
|
-
var useCrudifyUser = (options = {}) => {
|
|
2646
|
-
const { autoFetch = true, retryOnError = false, maxRetries = 3 } = options;
|
|
2647
|
-
const { isAuthenticated, isInitialized, user: jwtUser, token } = useCrudifyDataContext();
|
|
2648
|
-
const [userData, setUserData] = useState9(null);
|
|
2649
|
-
const [loading, setLoading] = useState9(false);
|
|
2650
|
-
const [error, setError] = useState9(null);
|
|
2651
|
-
const abortControllerRef = useRef5(null);
|
|
2652
|
-
const mountedRef = useRef5(true);
|
|
2653
|
-
const requestIdRef = useRef5(0);
|
|
2654
|
-
const retryCountRef = useRef5(0);
|
|
2655
|
-
const getUserEmailFromJWT = useCallback2(() => {
|
|
2656
|
-
if (!jwtUser) return null;
|
|
2657
|
-
return jwtUser.email || jwtUser["cognito:username"] || null;
|
|
2658
|
-
}, [jwtUser]);
|
|
2659
|
-
const clearProfile = useCallback2(() => {
|
|
2660
|
-
setUserData(null);
|
|
2661
|
-
setError(null);
|
|
2662
|
-
setLoading(false);
|
|
2663
|
-
retryCountRef.current = 0;
|
|
2664
|
-
}, []);
|
|
2665
|
-
const refreshProfile = useCallback2(async () => {
|
|
2666
|
-
const userEmail = getUserEmailFromJWT();
|
|
2667
|
-
console.log("\u{1F464} useCrudifyUser - Refreshing profile for:", userEmail);
|
|
2668
|
-
if (!userEmail) {
|
|
2669
|
-
if (mountedRef.current) {
|
|
2670
|
-
setError("No user email available from JWT token");
|
|
2671
|
-
setLoading(false);
|
|
2672
|
-
}
|
|
2673
|
-
return;
|
|
2674
|
-
}
|
|
2675
|
-
if (!isInitialized) {
|
|
2676
|
-
if (mountedRef.current) {
|
|
2677
|
-
setError("Crudify not initialized");
|
|
2678
|
-
setLoading(false);
|
|
2679
|
-
}
|
|
2680
|
-
return;
|
|
2681
|
-
}
|
|
2682
|
-
if (abortControllerRef.current) {
|
|
2683
|
-
abortControllerRef.current.abort();
|
|
2684
|
-
}
|
|
2685
|
-
const abortController = new AbortController();
|
|
2686
|
-
abortControllerRef.current = abortController;
|
|
2687
|
-
const currentRequestId = ++requestIdRef.current;
|
|
2688
|
-
try {
|
|
2689
|
-
if (mountedRef.current) {
|
|
2690
|
-
setLoading(true);
|
|
2691
|
-
setError(null);
|
|
2692
|
-
}
|
|
2693
|
-
console.log("\u{1F464} useCrudifyUser - Fetching profile data from database");
|
|
2694
|
-
const response = await crudify3.readItems("users", {
|
|
2695
|
-
filter: { email: userEmail },
|
|
2696
|
-
pagination: { limit: 1 }
|
|
2697
|
-
});
|
|
2698
|
-
console.log("\u{1F464} useCrudifyUser - Database response:", response);
|
|
2699
|
-
console.log("\u{1F464} useCrudifyUser - response.data:", response.data);
|
|
2700
|
-
console.log("\u{1F464} useCrudifyUser - response.data type:", typeof response.data);
|
|
2701
|
-
if (currentRequestId === requestIdRef.current && mountedRef.current && !abortController.signal.aborted) {
|
|
2702
|
-
let userData2 = null;
|
|
2703
|
-
if (response.success) {
|
|
2704
|
-
console.log("\u{1F464} useCrudifyUser - Processing successful response:", {
|
|
2705
|
-
dataType: typeof response.data,
|
|
2706
|
-
isArray: Array.isArray(response.data),
|
|
2707
|
-
hasResponse: !!response.data?.response,
|
|
2708
|
-
hasResponseData: !!response.data?.response?.data,
|
|
2709
|
-
responseDataType: typeof response.data?.response?.data
|
|
2710
|
-
});
|
|
2711
|
-
if (Array.isArray(response.data) && response.data.length > 0) {
|
|
2712
|
-
console.log("\u{1F464} useCrudifyUser - Found direct array format");
|
|
2713
|
-
userData2 = response.data[0];
|
|
2714
|
-
} else if (response.data?.response?.data) {
|
|
2715
|
-
console.log("\u{1F464} useCrudifyUser - Found nested response.data format");
|
|
2716
|
-
try {
|
|
2717
|
-
const rawData = response.data.response.data;
|
|
2718
|
-
console.log("\u{1F464} useCrudifyUser - Raw nested data:", rawData);
|
|
2719
|
-
console.log("\u{1F464} useCrudifyUser - Raw data type:", typeof rawData);
|
|
2720
|
-
const parsedData = typeof rawData === "string" ? JSON.parse(rawData) : rawData;
|
|
2721
|
-
console.log("\u{1F464} useCrudifyUser - Parsed nested data:", parsedData);
|
|
2722
|
-
if (parsedData && parsedData.items && Array.isArray(parsedData.items) && parsedData.items.length > 0) {
|
|
2723
|
-
userData2 = parsedData.items[0];
|
|
2724
|
-
console.log("\u{1F464} useCrudifyUser - Extracted user from nested items:", userData2);
|
|
2725
|
-
} else {
|
|
2726
|
-
console.log("\u{1F464} useCrudifyUser - No items found in parsed data or items array is empty");
|
|
2727
|
-
}
|
|
2728
|
-
} catch (parseError) {
|
|
2729
|
-
console.error("\u{1F464} useCrudifyUser - Error parsing nested response data:", parseError);
|
|
2730
|
-
}
|
|
2731
|
-
} else if (response.data && typeof response.data === "object") {
|
|
2732
|
-
console.log("\u{1F464} useCrudifyUser - Found object format, checking for items");
|
|
2733
|
-
if (response.data.items && Array.isArray(response.data.items) && response.data.items.length > 0) {
|
|
2734
|
-
console.log("\u{1F464} useCrudifyUser - Found items in object format");
|
|
2735
|
-
userData2 = response.data.items[0];
|
|
2736
|
-
} else {
|
|
2737
|
-
console.log("\u{1F464} useCrudifyUser - No items found in object format");
|
|
2738
|
-
}
|
|
2739
|
-
} else if (response.data?.data?.response?.data) {
|
|
2740
|
-
console.log("\u{1F464} useCrudifyUser - Found double-nested data.data.response.data format");
|
|
2741
|
-
try {
|
|
2742
|
-
const rawData = response.data.data.response.data;
|
|
2743
|
-
console.log("\u{1F464} useCrudifyUser - Raw double-nested data:", rawData);
|
|
2744
|
-
const parsedData = typeof rawData === "string" ? JSON.parse(rawData) : rawData;
|
|
2745
|
-
console.log("\u{1F464} useCrudifyUser - Parsed double-nested data:", parsedData);
|
|
2746
|
-
if (parsedData && parsedData.items && Array.isArray(parsedData.items) && parsedData.items.length > 0) {
|
|
2747
|
-
userData2 = parsedData.items[0];
|
|
2748
|
-
console.log("\u{1F464} useCrudifyUser - Extracted user from double-nested items:", userData2);
|
|
2749
|
-
}
|
|
2750
|
-
} catch (parseError) {
|
|
2751
|
-
console.error("\u{1F464} useCrudifyUser - Error parsing double-nested response data:", parseError);
|
|
2752
|
-
}
|
|
2753
|
-
}
|
|
2754
|
-
}
|
|
2755
|
-
if (userData2) {
|
|
2756
|
-
console.log("\u{1F464} useCrudifyUser - User data found:", userData2);
|
|
2757
|
-
setUserData(userData2);
|
|
2758
|
-
setError(null);
|
|
2759
|
-
retryCountRef.current = 0;
|
|
2760
|
-
console.log("\u{1F464} useCrudifyUser - Profile loaded successfully:", userData2);
|
|
2761
|
-
} else {
|
|
2762
|
-
setError("User profile not found in database");
|
|
2763
|
-
setUserData(null);
|
|
2764
|
-
console.warn("\u{1F464} useCrudifyUser - User not found for email:", userEmail);
|
|
2765
|
-
}
|
|
2766
|
-
}
|
|
2767
|
-
} catch (err) {
|
|
2768
|
-
if (currentRequestId === requestIdRef.current && mountedRef.current) {
|
|
2769
|
-
const error2 = err;
|
|
2770
|
-
console.error("\u{1F464} useCrudifyUser - Error fetching profile:", error2);
|
|
2771
|
-
if (error2.name === "AbortError") {
|
|
2772
|
-
return;
|
|
2773
|
-
}
|
|
2774
|
-
const shouldRetry = retryOnError && retryCountRef.current < maxRetries && (error2.message?.includes("Network Error") || error2.message?.includes("Failed to fetch"));
|
|
2775
|
-
if (shouldRetry) {
|
|
2776
|
-
retryCountRef.current++;
|
|
2777
|
-
console.log(`\u{1F464} useCrudifyUser - Retrying profile fetch (${retryCountRef.current}/${maxRetries})`);
|
|
2778
|
-
setTimeout(() => {
|
|
2779
|
-
if (mountedRef.current) {
|
|
2780
|
-
refreshProfile();
|
|
2781
|
-
}
|
|
2782
|
-
}, 1e3 * retryCountRef.current);
|
|
2783
|
-
} else {
|
|
2784
|
-
setError("Failed to load user profile from database");
|
|
2785
|
-
setUserData(null);
|
|
2786
|
-
}
|
|
2787
|
-
}
|
|
2788
|
-
} finally {
|
|
2789
|
-
if (currentRequestId === requestIdRef.current && mountedRef.current) {
|
|
2790
|
-
setLoading(false);
|
|
2791
|
-
}
|
|
2792
|
-
if (abortControllerRef.current === abortController) {
|
|
2793
|
-
abortControllerRef.current = null;
|
|
2794
|
-
}
|
|
2795
|
-
}
|
|
2796
|
-
}, [isInitialized, getUserEmailFromJWT, retryOnError, maxRetries]);
|
|
2797
|
-
useEffect9(() => {
|
|
2798
|
-
if (autoFetch && isAuthenticated && isInitialized) {
|
|
2799
|
-
refreshProfile();
|
|
2800
|
-
} else if (!isAuthenticated) {
|
|
2801
|
-
clearProfile();
|
|
2802
|
-
}
|
|
2803
|
-
}, [autoFetch, isAuthenticated, isInitialized, refreshProfile, clearProfile]);
|
|
2804
|
-
useEffect9(() => {
|
|
2805
|
-
mountedRef.current = true;
|
|
2806
|
-
return () => {
|
|
2807
|
-
mountedRef.current = false;
|
|
2808
|
-
if (abortControllerRef.current) {
|
|
2809
|
-
abortControllerRef.current.abort();
|
|
2810
|
-
abortControllerRef.current = null;
|
|
2811
|
-
}
|
|
2812
|
-
};
|
|
2813
|
-
}, []);
|
|
2814
|
-
const user = {
|
|
2815
|
-
session: jwtUser,
|
|
2816
|
-
data: userData
|
|
2817
|
-
};
|
|
2818
|
-
return {
|
|
2819
|
-
user,
|
|
2820
|
-
loading,
|
|
2821
|
-
error,
|
|
2822
|
-
refreshProfile,
|
|
2823
|
-
clearProfile
|
|
2824
|
-
};
|
|
2825
|
-
};
|
|
2826
|
-
|
|
2827
|
-
// src/hooks/useCrudifyData.ts
|
|
2828
|
-
import { useCallback as useCallback3 } from "react";
|
|
2829
|
-
import crudify4 from "@nocios/crudify-browser";
|
|
2830
|
-
var useCrudifyData = () => {
|
|
2831
|
-
const {
|
|
2832
|
-
isInitialized,
|
|
2833
|
-
isInitializing,
|
|
2834
|
-
initializationError
|
|
2835
|
-
} = useCrudifyDataContext();
|
|
2836
|
-
const isReady = useCallback3(() => {
|
|
2837
|
-
return isInitialized && !initializationError && !isInitializing;
|
|
2838
|
-
}, [isInitialized, initializationError, isInitializing]);
|
|
2839
|
-
const waitForReady = useCallback3(async () => {
|
|
2840
|
-
if (isReady()) return;
|
|
2841
|
-
if (initializationError) {
|
|
2842
|
-
throw new Error(`Crudify initialization failed: ${initializationError}`);
|
|
2843
|
-
}
|
|
2844
|
-
return new Promise((resolve, reject) => {
|
|
2845
|
-
const maxWaitTime = 1e4;
|
|
2846
|
-
const checkInterval = 100;
|
|
2847
|
-
let elapsed = 0;
|
|
2848
|
-
const check = () => {
|
|
2849
|
-
if (isReady()) {
|
|
2850
|
-
resolve();
|
|
2851
|
-
} else if (initializationError) {
|
|
2852
|
-
reject(new Error(`Crudify initialization failed: ${initializationError}`));
|
|
2853
|
-
} else if (elapsed >= maxWaitTime) {
|
|
2854
|
-
reject(new Error("Timeout waiting for crudify initialization"));
|
|
2855
|
-
} else {
|
|
2856
|
-
elapsed += checkInterval;
|
|
2857
|
-
setTimeout(check, checkInterval);
|
|
2858
|
-
}
|
|
2859
|
-
};
|
|
2860
|
-
check();
|
|
2861
|
-
});
|
|
2862
|
-
}, [isReady, initializationError]);
|
|
2863
|
-
const ensureReady = useCallback3((operationName) => {
|
|
2864
|
-
if (!isReady()) {
|
|
2865
|
-
const error = initializationError ? `Crudify initialization failed: ${initializationError}` : isInitializing ? "Crudify is still initializing. Please wait." : "Crudify is not initialized";
|
|
2866
|
-
throw new Error(`Cannot perform ${operationName}: ${error}`);
|
|
2867
|
-
}
|
|
2868
|
-
}, [isReady, initializationError, isInitializing]);
|
|
2869
|
-
const readItems = useCallback3(async (moduleKey, filter, options) => {
|
|
2870
|
-
ensureReady("readItems");
|
|
2871
|
-
console.log("\u{1F4CA} useCrudifyData - readItems called with:");
|
|
2872
|
-
console.log(" - moduleKey:", moduleKey);
|
|
2873
|
-
console.log(" - filter:", filter);
|
|
2874
|
-
console.log(" - options:", options);
|
|
2875
|
-
if (moduleKey === "__test_connection__") {
|
|
2876
|
-
console.error("\u{1F6A8} FOUND TEST CONNECTION CALL! Stack trace:");
|
|
2877
|
-
console.error(new Error().stack);
|
|
2878
|
-
}
|
|
2879
|
-
try {
|
|
2880
|
-
const response = await crudify4.readItems(moduleKey, filter || {}, options);
|
|
2881
|
-
console.log("\u{1F4CA} useCrudifyData - readItems response:", response);
|
|
2882
|
-
return response;
|
|
2883
|
-
} catch (error) {
|
|
2884
|
-
console.error("\u{1F4CA} useCrudifyData - readItems error:", error);
|
|
2885
|
-
throw error;
|
|
2886
|
-
}
|
|
2887
|
-
}, [ensureReady]);
|
|
2888
|
-
const readItem = useCallback3(async (moduleKey, filter, options) => {
|
|
2889
|
-
ensureReady("readItem");
|
|
2890
|
-
console.log("\u{1F4CA} useCrudifyData - readItem:", { moduleKey, filter, options });
|
|
2891
|
-
try {
|
|
2892
|
-
const response = await crudify4.readItem(moduleKey, filter, options);
|
|
2893
|
-
console.log("\u{1F4CA} useCrudifyData - readItem response:", response);
|
|
2894
|
-
return response;
|
|
2895
|
-
} catch (error) {
|
|
2896
|
-
console.error("\u{1F4CA} useCrudifyData - readItem error:", error);
|
|
2897
|
-
throw error;
|
|
2898
|
-
}
|
|
2899
|
-
}, [ensureReady]);
|
|
2900
|
-
const createItem = useCallback3(async (moduleKey, data, options) => {
|
|
2901
|
-
ensureReady("createItem");
|
|
2902
|
-
console.log("\u{1F4CA} useCrudifyData - createItem:", { moduleKey, data, options });
|
|
2903
|
-
try {
|
|
2904
|
-
const response = await crudify4.createItem(moduleKey, data, options);
|
|
2905
|
-
console.log("\u{1F4CA} useCrudifyData - createItem response:", response);
|
|
2906
|
-
return response;
|
|
2907
|
-
} catch (error) {
|
|
2908
|
-
console.error("\u{1F4CA} useCrudifyData - createItem error:", error);
|
|
2909
|
-
throw error;
|
|
2910
|
-
}
|
|
2911
|
-
}, [ensureReady]);
|
|
2912
|
-
const updateItem = useCallback3(async (moduleKey, data, options) => {
|
|
2913
|
-
ensureReady("updateItem");
|
|
2914
|
-
console.log("\u{1F4CA} useCrudifyData - updateItem:", { moduleKey, data, options });
|
|
2915
|
-
try {
|
|
2916
|
-
const response = await crudify4.updateItem(moduleKey, data, options);
|
|
2917
|
-
console.log("\u{1F4CA} useCrudifyData - updateItem response:", response);
|
|
2918
|
-
return response;
|
|
2919
|
-
} catch (error) {
|
|
2920
|
-
console.error("\u{1F4CA} useCrudifyData - updateItem error:", error);
|
|
2921
|
-
throw error;
|
|
2922
|
-
}
|
|
2923
|
-
}, [ensureReady]);
|
|
2924
|
-
const deleteItem = useCallback3(async (moduleKey, id, options) => {
|
|
2925
|
-
ensureReady("deleteItem");
|
|
2926
|
-
console.log("\u{1F4CA} useCrudifyData - deleteItem:", { moduleKey, id, options });
|
|
2927
|
-
try {
|
|
2928
|
-
const response = await crudify4.deleteItem(moduleKey, id, options);
|
|
2929
|
-
console.log("\u{1F4CA} useCrudifyData - deleteItem response:", response);
|
|
2930
|
-
return response;
|
|
2931
|
-
} catch (error) {
|
|
2932
|
-
console.error("\u{1F4CA} useCrudifyData - deleteItem error:", error);
|
|
2933
|
-
throw error;
|
|
2934
|
-
}
|
|
2935
|
-
}, [ensureReady]);
|
|
2936
|
-
const transaction = useCallback3(async (operations, options) => {
|
|
2937
|
-
ensureReady("transaction");
|
|
2938
|
-
console.log("\u{1F4CA} useCrudifyData - transaction:", { operations, options });
|
|
2939
|
-
try {
|
|
2940
|
-
const response = await crudify4.transaction(operations, options);
|
|
2941
|
-
console.log("\u{1F4CA} useCrudifyData - transaction response:", response);
|
|
2942
|
-
return response;
|
|
2943
|
-
} catch (error) {
|
|
2944
|
-
console.error("\u{1F4CA} useCrudifyData - transaction error:", error);
|
|
2945
|
-
throw error;
|
|
2946
|
-
}
|
|
2947
|
-
}, [ensureReady]);
|
|
2948
|
-
const login = useCallback3(async (email, password) => {
|
|
2949
|
-
ensureReady("login");
|
|
2950
|
-
console.log("\u{1F4CA} useCrudifyData - login:", { email });
|
|
2951
|
-
try {
|
|
2952
|
-
const response = await crudify4.login(email, password);
|
|
2953
|
-
console.log("\u{1F4CA} useCrudifyData - login response:", response);
|
|
2954
|
-
return response;
|
|
2955
|
-
} catch (error) {
|
|
2956
|
-
console.error("\u{1F4CA} useCrudifyData - login error:", error);
|
|
2957
|
-
throw error;
|
|
2958
|
-
}
|
|
2959
|
-
}, [ensureReady]);
|
|
2960
|
-
return {
|
|
2961
|
-
// Operaciones básicas CRUD
|
|
2962
|
-
readItems,
|
|
2963
|
-
readItem,
|
|
2964
|
-
createItem,
|
|
2965
|
-
updateItem,
|
|
2966
|
-
deleteItem,
|
|
2967
|
-
// Operaciones avanzadas
|
|
2968
|
-
transaction,
|
|
2969
|
-
login,
|
|
2970
|
-
// Estado de inicialización
|
|
2971
|
-
isInitialized,
|
|
2972
|
-
isInitializing,
|
|
2973
|
-
initializationError,
|
|
2974
|
-
// Utilidades
|
|
2975
|
-
isReady,
|
|
2976
|
-
waitForReady
|
|
2977
|
-
};
|
|
2978
|
-
};
|
|
2979
|
-
|
|
2980
|
-
// src/hooks/useCrudifyInstance.ts
|
|
2981
|
-
import { useCallback as useCallback4 } from "react";
|
|
2982
|
-
import crudify5 from "@nocios/crudify-browser";
|
|
2983
|
-
var useCrudifyInstance = () => {
|
|
2984
|
-
const {
|
|
2985
|
-
isInitialized,
|
|
2986
|
-
isInitializing,
|
|
2987
|
-
initializationError
|
|
2988
|
-
} = useCrudifyDataContext();
|
|
2989
|
-
const isReady = isInitialized && !initializationError && !isInitializing;
|
|
2990
|
-
const waitForReady = useCallback4(async () => {
|
|
2991
|
-
console.log("\u{1F504} useCrudifyInstance - waitForReady: Starting wait");
|
|
2992
|
-
console.log(" - isReady:", isReady);
|
|
2993
|
-
console.log(" - isInitialized:", isInitialized);
|
|
2994
|
-
console.log(" - isInitializing:", isInitializing);
|
|
2995
|
-
console.log(" - initializationError:", initializationError);
|
|
2996
|
-
if (isReady) {
|
|
2997
|
-
console.log("\u2705 useCrudifyInstance - waitForReady: Already ready, returning immediately");
|
|
2998
|
-
return;
|
|
2999
|
-
}
|
|
3000
|
-
if (initializationError) {
|
|
3001
|
-
throw new Error(`Crudify initialization failed: ${initializationError}`);
|
|
3002
|
-
}
|
|
3003
|
-
try {
|
|
3004
|
-
console.log("\u{1F504} useCrudifyInstance - waitForReady: Using CrudifyInitializer.waitForInitialization()");
|
|
3005
|
-
const { crudifyInitializer: crudifyInitializer2 } = await import("./CrudifyDataProvider-5GXGNQKI.mjs");
|
|
3006
|
-
await crudifyInitializer2.waitForInitialization();
|
|
3007
|
-
console.log("\u2705 useCrudifyInstance - waitForReady: CrudifyInitializer completed");
|
|
3008
|
-
if (!crudifyInitializer2.isReady()) {
|
|
3009
|
-
const error = crudifyInitializer2.getError();
|
|
3010
|
-
throw new Error(`Crudify initialization failed: ${error || "Unknown error"}`);
|
|
3011
|
-
}
|
|
3012
|
-
console.log("\u2705 useCrudifyInstance - waitForReady: Verification successful");
|
|
3013
|
-
} catch (error) {
|
|
3014
|
-
console.error("\u274C useCrudifyInstance - waitForReady: Error during wait:", error);
|
|
3015
|
-
throw error;
|
|
3016
|
-
}
|
|
3017
|
-
}, [isReady, initializationError, isInitialized, isInitializing]);
|
|
3018
|
-
const ensureReady = useCallback4(async (operationName) => {
|
|
3019
|
-
if (!isReady) {
|
|
3020
|
-
console.log(`\u{1F504} useCrudifyInstance - ${operationName}: Waiting for crudify to be ready...`);
|
|
3021
|
-
await waitForReady();
|
|
3022
|
-
console.log(`\u2705 useCrudifyInstance - ${operationName}: Crudify is ready`);
|
|
3023
|
-
}
|
|
3024
|
-
}, [isReady, waitForReady]);
|
|
3025
|
-
const ensureTokenSync = useCallback4(async () => {
|
|
3026
|
-
console.log("\u{1F504} useCrudifyInstance - ensureTokenSync: Starting token sync check");
|
|
3027
|
-
const { tokenManager: tokenManager2 } = await import("./TokenManager-AYUNIXQU.mjs");
|
|
3028
|
-
const tmToken = tokenManager2.getToken();
|
|
3029
|
-
const crudifyToken = crudify5.getToken?.();
|
|
3030
|
-
console.log(" - TokenManager token in sync check:", tmToken ? `${tmToken.substring(0, 20)}...` : "null");
|
|
3031
|
-
console.log(" - crudify token in sync check:", crudifyToken ? `${crudifyToken.substring(0, 20)}...` : "null");
|
|
3032
|
-
if (tmToken && tmToken !== crudifyToken) {
|
|
3033
|
-
console.log("\u{1F504} useCrudifyInstance - Forcing token sync for authenticated operation");
|
|
3034
|
-
crudify5.setToken(tmToken);
|
|
3035
|
-
console.log(" - crudify token after sync:", crudify5.getToken?.() ? `${crudify5.getToken?.()?.substring(0, 20)}...` : "null");
|
|
3036
|
-
} else {
|
|
3037
|
-
console.log("\u{1F504} useCrudifyInstance - No token sync needed, tokens match or no token");
|
|
3038
|
-
}
|
|
3039
|
-
}, []);
|
|
3040
|
-
const getStructure = useCallback4(async (options) => {
|
|
3041
|
-
console.log("\u{1F4E1} useCrudifyInstance - getStructure: Starting");
|
|
3042
|
-
await ensureReady("getStructure");
|
|
3043
|
-
try {
|
|
3044
|
-
const { tokenManager: tokenManager2 } = await import("./TokenManager-AYUNIXQU.mjs");
|
|
3045
|
-
const tmToken = tokenManager2.getToken();
|
|
3046
|
-
const crudifyToken = crudify5.getToken?.();
|
|
3047
|
-
console.log("\u{1F510} useCrudifyInstance - getStructure: Token status check:");
|
|
3048
|
-
console.log(" - TokenManager token:", tmToken ? `${tmToken.substring(0, 20)}...` : "null");
|
|
3049
|
-
console.log(" - crudify.getToken():", crudifyToken ? `${crudifyToken.substring(0, 20)}...` : "null");
|
|
3050
|
-
console.log(" - Tokens match:", tmToken === crudifyToken);
|
|
3051
|
-
await ensureTokenSync();
|
|
3052
|
-
console.log("\u{1F4E1} useCrudifyInstance - getStructure: Calling crudify.getStructure");
|
|
3053
|
-
const response = await crudify5.getStructure(options);
|
|
3054
|
-
console.log("\u{1F4E1} useCrudifyInstance - getStructure: Response received", response);
|
|
3055
|
-
return response;
|
|
3056
|
-
} catch (error) {
|
|
3057
|
-
console.error("\u{1F4E1} useCrudifyInstance - getStructure: Error", error);
|
|
3058
|
-
throw error;
|
|
3059
|
-
}
|
|
3060
|
-
}, [ensureReady, ensureTokenSync]);
|
|
3061
|
-
const getStructurePublic = useCallback4(async (options) => {
|
|
3062
|
-
console.log("\u{1F4E1} useCrudifyInstance - getStructurePublic: Starting");
|
|
3063
|
-
await ensureReady("getStructurePublic");
|
|
3064
|
-
try {
|
|
3065
|
-
console.log("\u{1F4E1} useCrudifyInstance - getStructurePublic: Calling crudify.getStructurePublic");
|
|
3066
|
-
const response = await crudify5.getStructurePublic(options);
|
|
3067
|
-
console.log("\u{1F4E1} useCrudifyInstance - getStructurePublic: Response received", response);
|
|
3068
|
-
return response;
|
|
3069
|
-
} catch (error) {
|
|
3070
|
-
console.error("\u{1F4E1} useCrudifyInstance - getStructurePublic: Error", error);
|
|
3071
|
-
throw error;
|
|
3072
|
-
}
|
|
3073
|
-
}, [ensureReady]);
|
|
3074
|
-
const readItems = useCallback4(async (moduleKey, filter, options) => {
|
|
3075
|
-
await ensureReady("readItems");
|
|
3076
|
-
await ensureTokenSync();
|
|
3077
|
-
if (moduleKey === "__test_connection__") {
|
|
3078
|
-
console.error("\u{1F6A8} FOUND TEST CONNECTION CALL in useCrudifyInstance! Stack trace:");
|
|
3079
|
-
console.error(new Error().stack);
|
|
3080
|
-
}
|
|
3081
|
-
try {
|
|
3082
|
-
const response = await crudify5.readItems(moduleKey, filter || {}, options);
|
|
3083
|
-
return response;
|
|
3084
|
-
} catch (error) {
|
|
3085
|
-
console.error("\u{1F4CA} useCrudifyInstance - readItems error:", error);
|
|
3086
|
-
throw error;
|
|
3087
|
-
}
|
|
3088
|
-
}, [ensureReady, ensureTokenSync]);
|
|
3089
|
-
const readItem = useCallback4(async (moduleKey, filter, options) => {
|
|
3090
|
-
await ensureReady("readItem");
|
|
3091
|
-
try {
|
|
3092
|
-
const response = await crudify5.readItem(moduleKey, filter, options);
|
|
3093
|
-
return response;
|
|
3094
|
-
} catch (error) {
|
|
3095
|
-
console.error("\u{1F4CA} useCrudifyInstance - readItem error:", error);
|
|
3096
|
-
throw error;
|
|
3097
|
-
}
|
|
3098
|
-
}, [ensureReady]);
|
|
3099
|
-
const createItem = useCallback4(async (moduleKey, data, options) => {
|
|
3100
|
-
await ensureReady("createItem");
|
|
3101
|
-
try {
|
|
3102
|
-
const response = await crudify5.createItem(moduleKey, data, options);
|
|
3103
|
-
return response;
|
|
3104
|
-
} catch (error) {
|
|
3105
|
-
console.error("\u{1F4CA} useCrudifyInstance - createItem error:", error);
|
|
3106
|
-
throw error;
|
|
3107
|
-
}
|
|
3108
|
-
}, [ensureReady]);
|
|
3109
|
-
const updateItem = useCallback4(async (moduleKey, data, options) => {
|
|
3110
|
-
await ensureReady("updateItem");
|
|
3111
|
-
try {
|
|
3112
|
-
const response = await crudify5.updateItem(moduleKey, data, options);
|
|
3113
|
-
return response;
|
|
3114
|
-
} catch (error) {
|
|
3115
|
-
console.error("\u{1F4CA} useCrudifyInstance - updateItem error:", error);
|
|
3116
|
-
throw error;
|
|
3117
|
-
}
|
|
3118
|
-
}, [ensureReady]);
|
|
3119
|
-
const deleteItem = useCallback4(async (moduleKey, id, options) => {
|
|
3120
|
-
await ensureReady("deleteItem");
|
|
3121
|
-
try {
|
|
3122
|
-
const response = await crudify5.deleteItem(moduleKey, id, options);
|
|
3123
|
-
return response;
|
|
3124
|
-
} catch (error) {
|
|
3125
|
-
console.error("\u{1F4CA} useCrudifyInstance - deleteItem error:", error);
|
|
3126
|
-
throw error;
|
|
3127
|
-
}
|
|
3128
|
-
}, [ensureReady]);
|
|
3129
|
-
const transaction = useCallback4(async (operations, options) => {
|
|
3130
|
-
await ensureReady("transaction");
|
|
3131
|
-
try {
|
|
3132
|
-
const response = await crudify5.transaction(operations, options);
|
|
3133
|
-
return response;
|
|
3134
|
-
} catch (error) {
|
|
3135
|
-
console.error("\u{1F4CA} useCrudifyInstance - transaction error:", error);
|
|
3136
|
-
throw error;
|
|
3137
|
-
}
|
|
3138
|
-
}, [ensureReady]);
|
|
3139
|
-
const login = useCallback4(async (email, password) => {
|
|
3140
|
-
await ensureReady("login");
|
|
3141
|
-
try {
|
|
3142
|
-
const response = await crudify5.login(email, password);
|
|
3143
|
-
return response;
|
|
3144
|
-
} catch (error) {
|
|
3145
|
-
console.error("\u{1F4CA} useCrudifyInstance - login error:", error);
|
|
3146
|
-
throw error;
|
|
3147
|
-
}
|
|
3148
|
-
}, [ensureReady]);
|
|
3149
|
-
return {
|
|
3150
|
-
// Core operations
|
|
3151
|
-
getStructure,
|
|
3152
|
-
getStructurePublic,
|
|
3153
|
-
readItems,
|
|
3154
|
-
readItem,
|
|
3155
|
-
createItem,
|
|
3156
|
-
updateItem,
|
|
3157
|
-
deleteItem,
|
|
3158
|
-
transaction,
|
|
3159
|
-
login,
|
|
3160
|
-
// State information
|
|
3161
|
-
isReady,
|
|
3162
|
-
isInitialized,
|
|
3163
|
-
isInitializing,
|
|
3164
|
-
initializationError,
|
|
3165
|
-
// Utility methods
|
|
3166
|
-
waitForReady
|
|
3167
|
-
};
|
|
3168
|
-
};
|
|
3169
|
-
var getCrudifyInstanceAsync = async () => {
|
|
3170
|
-
console.log("\u{1F504} getCrudifyInstanceAsync - Starting");
|
|
3171
|
-
const { crudifyInitializer: crudifyInitializer2 } = await import("./CrudifyDataProvider-5GXGNQKI.mjs");
|
|
3172
|
-
console.log("\u{1F504} getCrudifyInstanceAsync - Checking if ready");
|
|
3173
|
-
console.log(" - crudifyInitializer.isReady():", crudifyInitializer2.isReady());
|
|
3174
|
-
console.log(" - crudifyInitializer.getStatus():", crudifyInitializer2.getStatus());
|
|
3175
|
-
if (!crudifyInitializer2.isReady()) {
|
|
3176
|
-
console.log("\u{1F504} getCrudifyInstanceAsync - Waiting for crudify initialization...");
|
|
3177
|
-
await crudifyInitializer2.waitForInitialization();
|
|
3178
|
-
if (!crudifyInitializer2.isReady()) {
|
|
3179
|
-
const error = crudifyInitializer2.getError();
|
|
3180
|
-
throw new Error(`Crudify initialization failed: ${error || "Unknown error after waiting"}`);
|
|
3181
|
-
}
|
|
3182
|
-
console.log("\u2705 getCrudifyInstanceAsync - Crudify is ready after waiting");
|
|
3183
|
-
} else {
|
|
3184
|
-
console.log("\u2705 getCrudifyInstanceAsync - Already ready, no wait needed");
|
|
3185
|
-
}
|
|
3186
|
-
console.log("\u2705 getCrudifyInstanceAsync - Returning crudify instance");
|
|
3187
|
-
return crudify5;
|
|
3188
|
-
};
|
|
3189
|
-
var getCrudifyInstanceSync = async () => {
|
|
3190
|
-
const { crudifyInitializer: crudifyInitializer2 } = await import("./CrudifyDataProvider-5GXGNQKI.mjs");
|
|
3191
|
-
if (!crudifyInitializer2.isReady()) {
|
|
3192
|
-
throw new Error("Crudify not ready. Use getCrudifyInstanceAsync() or call this from within a React component using useCrudifyInstance()");
|
|
3193
|
-
}
|
|
3194
|
-
return crudify5;
|
|
3195
|
-
};
|
|
3196
|
-
|
|
3197
2651
|
// src/core/SessionManager.ts
|
|
3198
|
-
import
|
|
2652
|
+
import crudify4 from "@nocios/crudify-browser";
|
|
3199
2653
|
|
|
3200
2654
|
// src/utils/tokenStorage.ts
|
|
3201
2655
|
import CryptoJS from "crypto-js";
|
|
@@ -3405,7 +2859,7 @@ var SessionManager = class _SessionManager {
|
|
|
3405
2859
|
async login(email, password) {
|
|
3406
2860
|
try {
|
|
3407
2861
|
this.log("Attempting login...");
|
|
3408
|
-
const response = await
|
|
2862
|
+
const response = await crudify4.login(email, password);
|
|
3409
2863
|
if (!response.success) {
|
|
3410
2864
|
this.log("Login failed:", response.errors);
|
|
3411
2865
|
return {
|
|
@@ -3440,7 +2894,7 @@ var SessionManager = class _SessionManager {
|
|
|
3440
2894
|
async logout() {
|
|
3441
2895
|
try {
|
|
3442
2896
|
this.log("Logging out...");
|
|
3443
|
-
await
|
|
2897
|
+
await crudify4.logout();
|
|
3444
2898
|
TokenStorage.clearTokens();
|
|
3445
2899
|
this.log("Logout successful");
|
|
3446
2900
|
this.config.onLogout?.();
|
|
@@ -3460,7 +2914,7 @@ var SessionManager = class _SessionManager {
|
|
|
3460
2914
|
this.log("No valid tokens found in storage");
|
|
3461
2915
|
return false;
|
|
3462
2916
|
}
|
|
3463
|
-
|
|
2917
|
+
crudify4.setTokens({
|
|
3464
2918
|
accessToken: savedTokens.accessToken,
|
|
3465
2919
|
refreshToken: savedTokens.refreshToken,
|
|
3466
2920
|
expiresAt: savedTokens.expiresAt,
|
|
@@ -3479,13 +2933,13 @@ var SessionManager = class _SessionManager {
|
|
|
3479
2933
|
* Verificar si el usuario está autenticado
|
|
3480
2934
|
*/
|
|
3481
2935
|
isAuthenticated() {
|
|
3482
|
-
return
|
|
2936
|
+
return crudify4.isLogin() || TokenStorage.hasValidTokens();
|
|
3483
2937
|
}
|
|
3484
2938
|
/**
|
|
3485
2939
|
* Obtener información de tokens actuales
|
|
3486
2940
|
*/
|
|
3487
2941
|
getTokenInfo() {
|
|
3488
|
-
const crudifyTokens =
|
|
2942
|
+
const crudifyTokens = crudify4.getTokenData();
|
|
3489
2943
|
const storageInfo = TokenStorage.getExpirationInfo();
|
|
3490
2944
|
return {
|
|
3491
2945
|
isLoggedIn: this.isAuthenticated(),
|
|
@@ -3500,7 +2954,7 @@ var SessionManager = class _SessionManager {
|
|
|
3500
2954
|
async refreshTokens() {
|
|
3501
2955
|
try {
|
|
3502
2956
|
this.log("Manually refreshing tokens...");
|
|
3503
|
-
const response = await
|
|
2957
|
+
const response = await crudify4.refreshAccessToken();
|
|
3504
2958
|
if (!response.success) {
|
|
3505
2959
|
this.log("Token refresh failed:", response.errors);
|
|
3506
2960
|
TokenStorage.clearTokens();
|
|
@@ -3527,7 +2981,7 @@ var SessionManager = class _SessionManager {
|
|
|
3527
2981
|
* Configurar interceptor de respuesta para manejo automático de errores
|
|
3528
2982
|
*/
|
|
3529
2983
|
setupResponseInterceptor() {
|
|
3530
|
-
|
|
2984
|
+
crudify4.setResponseInterceptor(async (response) => {
|
|
3531
2985
|
if (response.errors) {
|
|
3532
2986
|
const hasAuthError = response.errors.some(
|
|
3533
2987
|
(error) => error.message?.includes("Unauthorized") || error.message?.includes("Token") || error.extensions?.code === "UNAUTHENTICATED"
|
|
@@ -3550,7 +3004,7 @@ var SessionManager = class _SessionManager {
|
|
|
3550
3004
|
*/
|
|
3551
3005
|
clearSession() {
|
|
3552
3006
|
TokenStorage.clearTokens();
|
|
3553
|
-
|
|
3007
|
+
crudify4.logout();
|
|
3554
3008
|
this.log("Session cleared completely");
|
|
3555
3009
|
}
|
|
3556
3010
|
// Métodos privados
|
|
@@ -3571,9 +3025,9 @@ var SessionManager = class _SessionManager {
|
|
|
3571
3025
|
};
|
|
3572
3026
|
|
|
3573
3027
|
// src/hooks/useSession.ts
|
|
3574
|
-
import { useState as
|
|
3028
|
+
import { useState as useState9, useEffect as useEffect9, useCallback as useCallback2 } from "react";
|
|
3575
3029
|
function useSession(options = {}) {
|
|
3576
|
-
const [state, setState] =
|
|
3030
|
+
const [state, setState] = useState9({
|
|
3577
3031
|
isAuthenticated: false,
|
|
3578
3032
|
isLoading: true,
|
|
3579
3033
|
isInitialized: false,
|
|
@@ -3581,7 +3035,7 @@ function useSession(options = {}) {
|
|
|
3581
3035
|
error: null
|
|
3582
3036
|
});
|
|
3583
3037
|
const sessionManager = SessionManager.getInstance();
|
|
3584
|
-
const initialize =
|
|
3038
|
+
const initialize = useCallback2(async () => {
|
|
3585
3039
|
try {
|
|
3586
3040
|
setState((prev) => ({ ...prev, isLoading: true, error: null }));
|
|
3587
3041
|
const config = {
|
|
@@ -3647,7 +3101,7 @@ function useSession(options = {}) {
|
|
|
3647
3101
|
}));
|
|
3648
3102
|
}
|
|
3649
3103
|
}, [options.autoRestore, options.enableLogging, options.onSessionExpired, options.onSessionRestored]);
|
|
3650
|
-
const login =
|
|
3104
|
+
const login = useCallback2(async (email, password) => {
|
|
3651
3105
|
setState((prev) => ({ ...prev, isLoading: true, error: null }));
|
|
3652
3106
|
try {
|
|
3653
3107
|
const result = await sessionManager.login(email, password);
|
|
@@ -3684,7 +3138,7 @@ function useSession(options = {}) {
|
|
|
3684
3138
|
};
|
|
3685
3139
|
}
|
|
3686
3140
|
}, [sessionManager]);
|
|
3687
|
-
const logout =
|
|
3141
|
+
const logout = useCallback2(async () => {
|
|
3688
3142
|
setState((prev) => ({ ...prev, isLoading: true }));
|
|
3689
3143
|
try {
|
|
3690
3144
|
await sessionManager.logout();
|
|
@@ -3705,7 +3159,7 @@ function useSession(options = {}) {
|
|
|
3705
3159
|
}));
|
|
3706
3160
|
}
|
|
3707
3161
|
}, [sessionManager]);
|
|
3708
|
-
const refreshTokens =
|
|
3162
|
+
const refreshTokens = useCallback2(async () => {
|
|
3709
3163
|
try {
|
|
3710
3164
|
const success = await sessionManager.refreshTokens();
|
|
3711
3165
|
if (success) {
|
|
@@ -3739,13 +3193,13 @@ function useSession(options = {}) {
|
|
|
3739
3193
|
return false;
|
|
3740
3194
|
}
|
|
3741
3195
|
}, [sessionManager]);
|
|
3742
|
-
const clearError =
|
|
3196
|
+
const clearError = useCallback2(() => {
|
|
3743
3197
|
setState((prev) => ({ ...prev, error: null }));
|
|
3744
3198
|
}, []);
|
|
3745
|
-
const getTokenInfo =
|
|
3199
|
+
const getTokenInfo = useCallback2(() => {
|
|
3746
3200
|
return sessionManager.getTokenInfo();
|
|
3747
3201
|
}, [sessionManager]);
|
|
3748
|
-
|
|
3202
|
+
useEffect9(() => {
|
|
3749
3203
|
initialize();
|
|
3750
3204
|
}, [initialize]);
|
|
3751
3205
|
return {
|
|
@@ -3890,13 +3344,13 @@ function SessionDebugInfo() {
|
|
|
3890
3344
|
}
|
|
3891
3345
|
|
|
3892
3346
|
// src/components/LoginComponent.tsx
|
|
3893
|
-
import { useState as
|
|
3347
|
+
import { useState as useState10 } from "react";
|
|
3894
3348
|
import { Button as Button8, TextField as TextField5, Box as Box11, Alert as Alert8, Typography as Typography11, CircularProgress as CircularProgress7 } from "@mui/material";
|
|
3895
3349
|
import { jsx as jsx15, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
3896
3350
|
function LoginComponent() {
|
|
3897
|
-
const [email, setEmail] =
|
|
3898
|
-
const [password, setPassword] =
|
|
3899
|
-
const [showForm, setShowForm] =
|
|
3351
|
+
const [email, setEmail] = useState10("");
|
|
3352
|
+
const [password, setPassword] = useState10("");
|
|
3353
|
+
const [showForm, setShowForm] = useState10(false);
|
|
3900
3354
|
const {
|
|
3901
3355
|
isAuthenticated,
|
|
3902
3356
|
isLoading,
|
|
@@ -4043,29 +3497,29 @@ function SessionStatus() {
|
|
|
4043
3497
|
}
|
|
4044
3498
|
|
|
4045
3499
|
// src/hooks/useUserData.ts
|
|
4046
|
-
import { useState as
|
|
4047
|
-
import
|
|
3500
|
+
import { useState as useState11, useEffect as useEffect10, useCallback as useCallback3, useRef as useRef5 } from "react";
|
|
3501
|
+
import crudify5 from "@nocios/crudify-browser";
|
|
4048
3502
|
var useUserData = (options = {}) => {
|
|
4049
3503
|
const { autoFetch = true, retryOnError = false, maxRetries = 3 } = options;
|
|
4050
3504
|
const { isAuthenticated, isInitialized, sessionData, tokens } = useSessionContext();
|
|
4051
|
-
const [userData, setUserData] =
|
|
4052
|
-
const [loading, setLoading] =
|
|
4053
|
-
const [error, setError] =
|
|
4054
|
-
const abortControllerRef =
|
|
4055
|
-
const mountedRef =
|
|
4056
|
-
const requestIdRef =
|
|
4057
|
-
const retryCountRef =
|
|
4058
|
-
const getUserEmail =
|
|
3505
|
+
const [userData, setUserData] = useState11(null);
|
|
3506
|
+
const [loading, setLoading] = useState11(false);
|
|
3507
|
+
const [error, setError] = useState11(null);
|
|
3508
|
+
const abortControllerRef = useRef5(null);
|
|
3509
|
+
const mountedRef = useRef5(true);
|
|
3510
|
+
const requestIdRef = useRef5(0);
|
|
3511
|
+
const retryCountRef = useRef5(0);
|
|
3512
|
+
const getUserEmail = useCallback3(() => {
|
|
4059
3513
|
if (!sessionData) return null;
|
|
4060
3514
|
return sessionData.email || sessionData["cognito:username"] || null;
|
|
4061
3515
|
}, [sessionData]);
|
|
4062
|
-
const clearProfile =
|
|
3516
|
+
const clearProfile = useCallback3(() => {
|
|
4063
3517
|
setUserData(null);
|
|
4064
3518
|
setError(null);
|
|
4065
3519
|
setLoading(false);
|
|
4066
3520
|
retryCountRef.current = 0;
|
|
4067
3521
|
}, []);
|
|
4068
|
-
const refreshProfile =
|
|
3522
|
+
const refreshProfile = useCallback3(async () => {
|
|
4069
3523
|
const userEmail = getUserEmail();
|
|
4070
3524
|
console.log("\u{1F464} useUserData - Refreshing profile for:", userEmail);
|
|
4071
3525
|
if (!userEmail) {
|
|
@@ -4094,7 +3548,7 @@ var useUserData = (options = {}) => {
|
|
|
4094
3548
|
setError(null);
|
|
4095
3549
|
}
|
|
4096
3550
|
console.log("\u{1F464} useUserData - Fetching profile data from database");
|
|
4097
|
-
const response = await
|
|
3551
|
+
const response = await crudify5.readItems("users", {
|
|
4098
3552
|
filter: { email: userEmail },
|
|
4099
3553
|
pagination: { limit: 1 }
|
|
4100
3554
|
});
|
|
@@ -4197,14 +3651,14 @@ var useUserData = (options = {}) => {
|
|
|
4197
3651
|
}
|
|
4198
3652
|
}
|
|
4199
3653
|
}, [isInitialized, getUserEmail, retryOnError, maxRetries]);
|
|
4200
|
-
|
|
3654
|
+
useEffect10(() => {
|
|
4201
3655
|
if (autoFetch && isAuthenticated && isInitialized) {
|
|
4202
3656
|
refreshProfile();
|
|
4203
3657
|
} else if (!isAuthenticated) {
|
|
4204
3658
|
clearProfile();
|
|
4205
3659
|
}
|
|
4206
3660
|
}, [autoFetch, isAuthenticated, isInitialized, refreshProfile, clearProfile]);
|
|
4207
|
-
|
|
3661
|
+
useEffect10(() => {
|
|
4208
3662
|
mountedRef.current = true;
|
|
4209
3663
|
return () => {
|
|
4210
3664
|
mountedRef.current = false;
|
|
@@ -4230,7 +3684,7 @@ var useUserData = (options = {}) => {
|
|
|
4230
3684
|
};
|
|
4231
3685
|
|
|
4232
3686
|
// src/hooks/useAuth.ts
|
|
4233
|
-
import { useCallback as
|
|
3687
|
+
import { useCallback as useCallback4 } from "react";
|
|
4234
3688
|
var useAuth = () => {
|
|
4235
3689
|
const {
|
|
4236
3690
|
isAuthenticated,
|
|
@@ -4248,7 +3702,7 @@ var useAuth = () => {
|
|
|
4248
3702
|
expiresIn,
|
|
4249
3703
|
refreshExpiresIn
|
|
4250
3704
|
} = useSessionContext();
|
|
4251
|
-
const setToken =
|
|
3705
|
+
const setToken = useCallback4((token) => {
|
|
4252
3706
|
if (token) {
|
|
4253
3707
|
console.warn("useAuth.setToken() is deprecated. Use login() method instead for better security.");
|
|
4254
3708
|
} else {
|
|
@@ -4283,8 +3737,8 @@ var useAuth = () => {
|
|
|
4283
3737
|
};
|
|
4284
3738
|
|
|
4285
3739
|
// src/hooks/useData.ts
|
|
4286
|
-
import { useCallback as
|
|
4287
|
-
import
|
|
3740
|
+
import { useCallback as useCallback5 } from "react";
|
|
3741
|
+
import crudify6 from "@nocios/crudify-browser";
|
|
4288
3742
|
var useData = () => {
|
|
4289
3743
|
const {
|
|
4290
3744
|
isInitialized,
|
|
@@ -4293,10 +3747,10 @@ var useData = () => {
|
|
|
4293
3747
|
isAuthenticated,
|
|
4294
3748
|
login: sessionLogin
|
|
4295
3749
|
} = useSessionContext();
|
|
4296
|
-
const isReady =
|
|
3750
|
+
const isReady = useCallback5(() => {
|
|
4297
3751
|
return isInitialized && !isLoading && !error;
|
|
4298
3752
|
}, [isInitialized, isLoading, error]);
|
|
4299
|
-
const waitForReady =
|
|
3753
|
+
const waitForReady = useCallback5(async () => {
|
|
4300
3754
|
return new Promise((resolve, reject) => {
|
|
4301
3755
|
const checkReady = () => {
|
|
4302
3756
|
if (isReady()) {
|
|
@@ -4310,36 +3764,36 @@ var useData = () => {
|
|
|
4310
3764
|
checkReady();
|
|
4311
3765
|
});
|
|
4312
3766
|
}, [isReady, error]);
|
|
4313
|
-
const ensureReady =
|
|
3767
|
+
const ensureReady = useCallback5(async () => {
|
|
4314
3768
|
if (!isReady()) {
|
|
4315
3769
|
throw new Error("System not ready. Check isInitialized, isLoading, and error states.");
|
|
4316
3770
|
}
|
|
4317
3771
|
}, [isReady]);
|
|
4318
|
-
const readItems =
|
|
3772
|
+
const readItems = useCallback5(async (moduleKey, filter, options) => {
|
|
4319
3773
|
await ensureReady();
|
|
4320
|
-
return await
|
|
3774
|
+
return await crudify6.readItems(moduleKey, filter || {}, options);
|
|
4321
3775
|
}, [ensureReady]);
|
|
4322
|
-
const readItem =
|
|
3776
|
+
const readItem = useCallback5(async (moduleKey, filter, options) => {
|
|
4323
3777
|
await ensureReady();
|
|
4324
|
-
return await
|
|
3778
|
+
return await crudify6.readItem(moduleKey, filter, options);
|
|
4325
3779
|
}, [ensureReady]);
|
|
4326
|
-
const createItem =
|
|
3780
|
+
const createItem = useCallback5(async (moduleKey, data, options) => {
|
|
4327
3781
|
await ensureReady();
|
|
4328
|
-
return await
|
|
3782
|
+
return await crudify6.createItem(moduleKey, data, options);
|
|
4329
3783
|
}, [ensureReady]);
|
|
4330
|
-
const updateItem =
|
|
3784
|
+
const updateItem = useCallback5(async (moduleKey, data, options) => {
|
|
4331
3785
|
await ensureReady();
|
|
4332
|
-
return await
|
|
3786
|
+
return await crudify6.updateItem(moduleKey, data, options);
|
|
4333
3787
|
}, [ensureReady]);
|
|
4334
|
-
const deleteItem =
|
|
3788
|
+
const deleteItem = useCallback5(async (moduleKey, id, options) => {
|
|
4335
3789
|
await ensureReady();
|
|
4336
|
-
return await
|
|
3790
|
+
return await crudify6.deleteItem(moduleKey, id, options);
|
|
4337
3791
|
}, [ensureReady]);
|
|
4338
|
-
const transaction =
|
|
3792
|
+
const transaction = useCallback5(async (operations, options) => {
|
|
4339
3793
|
await ensureReady();
|
|
4340
|
-
return await
|
|
3794
|
+
return await crudify6.transaction(operations, options);
|
|
4341
3795
|
}, [ensureReady]);
|
|
4342
|
-
const login =
|
|
3796
|
+
const login = useCallback5(async (email, password) => {
|
|
4343
3797
|
try {
|
|
4344
3798
|
const result = await sessionLogin(email, password);
|
|
4345
3799
|
if (result.success) {
|
|
@@ -4379,8 +3833,116 @@ var useData = () => {
|
|
|
4379
3833
|
waitForReady
|
|
4380
3834
|
};
|
|
4381
3835
|
};
|
|
3836
|
+
|
|
3837
|
+
// src/components/CrudifyLogin/utils/secureStorage.ts
|
|
3838
|
+
import CryptoJS2 from "crypto-js";
|
|
3839
|
+
var SecureStorage = class {
|
|
3840
|
+
constructor(storageType = "sessionStorage") {
|
|
3841
|
+
this.encryptionKey = this.generateEncryptionKey();
|
|
3842
|
+
this.storage = storageType === "localStorage" ? window.localStorage : window.sessionStorage;
|
|
3843
|
+
}
|
|
3844
|
+
generateEncryptionKey() {
|
|
3845
|
+
const browserFingerprint = [
|
|
3846
|
+
navigator.userAgent,
|
|
3847
|
+
navigator.language,
|
|
3848
|
+
(/* @__PURE__ */ new Date()).getTimezoneOffset(),
|
|
3849
|
+
screen.colorDepth,
|
|
3850
|
+
screen.width,
|
|
3851
|
+
screen.height,
|
|
3852
|
+
"crudify-login"
|
|
3853
|
+
].join("|");
|
|
3854
|
+
return CryptoJS2.SHA256(browserFingerprint).toString();
|
|
3855
|
+
}
|
|
3856
|
+
setItem(key, value, expiryMinutes) {
|
|
3857
|
+
try {
|
|
3858
|
+
const encrypted = CryptoJS2.AES.encrypt(value, this.encryptionKey).toString();
|
|
3859
|
+
this.storage.setItem(key, encrypted);
|
|
3860
|
+
if (expiryMinutes) {
|
|
3861
|
+
const expiryTime = (/* @__PURE__ */ new Date()).getTime() + expiryMinutes * 60 * 1e3;
|
|
3862
|
+
this.storage.setItem(`${key}_expiry`, expiryTime.toString());
|
|
3863
|
+
}
|
|
3864
|
+
} catch (error) {
|
|
3865
|
+
console.error("Failed to encrypt and store data:", error);
|
|
3866
|
+
}
|
|
3867
|
+
}
|
|
3868
|
+
getItem(key) {
|
|
3869
|
+
try {
|
|
3870
|
+
const expiryKey = `${key}_expiry`;
|
|
3871
|
+
const expiry = this.storage.getItem(expiryKey);
|
|
3872
|
+
if (expiry) {
|
|
3873
|
+
const expiryTime = parseInt(expiry, 10);
|
|
3874
|
+
if ((/* @__PURE__ */ new Date()).getTime() > expiryTime) {
|
|
3875
|
+
this.removeItem(key);
|
|
3876
|
+
return null;
|
|
3877
|
+
}
|
|
3878
|
+
}
|
|
3879
|
+
const encrypted = this.storage.getItem(key);
|
|
3880
|
+
if (!encrypted) return null;
|
|
3881
|
+
const decrypted = CryptoJS2.AES.decrypt(encrypted, this.encryptionKey);
|
|
3882
|
+
const result = decrypted.toString(CryptoJS2.enc.Utf8);
|
|
3883
|
+
if (!result) {
|
|
3884
|
+
console.warn("Failed to decrypt stored data - may be corrupted");
|
|
3885
|
+
this.removeItem(key);
|
|
3886
|
+
return null;
|
|
3887
|
+
}
|
|
3888
|
+
return result;
|
|
3889
|
+
} catch (error) {
|
|
3890
|
+
console.error("Failed to decrypt data:", error);
|
|
3891
|
+
this.removeItem(key);
|
|
3892
|
+
return null;
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3895
|
+
removeItem(key) {
|
|
3896
|
+
this.storage.removeItem(key);
|
|
3897
|
+
this.storage.removeItem(`${key}_expiry`);
|
|
3898
|
+
}
|
|
3899
|
+
setToken(token) {
|
|
3900
|
+
try {
|
|
3901
|
+
const parts = token.split(".");
|
|
3902
|
+
if (parts.length === 3) {
|
|
3903
|
+
const payload = JSON.parse(atob(parts[1]));
|
|
3904
|
+
if (payload.exp) {
|
|
3905
|
+
const expiryTime = payload.exp * 1e3;
|
|
3906
|
+
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
3907
|
+
const minutesUntilExpiry = Math.floor((expiryTime - now) / (60 * 1e3));
|
|
3908
|
+
if (minutesUntilExpiry > 0) {
|
|
3909
|
+
this.setItem("authToken", token, minutesUntilExpiry);
|
|
3910
|
+
return;
|
|
3911
|
+
}
|
|
3912
|
+
}
|
|
3913
|
+
}
|
|
3914
|
+
} catch (error) {
|
|
3915
|
+
console.warn("Failed to parse token expiry, using default expiry");
|
|
3916
|
+
}
|
|
3917
|
+
this.setItem("authToken", token, 24 * 60);
|
|
3918
|
+
}
|
|
3919
|
+
getToken() {
|
|
3920
|
+
const token = this.getItem("authToken");
|
|
3921
|
+
if (token) {
|
|
3922
|
+
try {
|
|
3923
|
+
const parts = token.split(".");
|
|
3924
|
+
if (parts.length === 3) {
|
|
3925
|
+
const payload = JSON.parse(atob(parts[1]));
|
|
3926
|
+
if (payload.exp) {
|
|
3927
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
3928
|
+
if (payload.exp < now) {
|
|
3929
|
+
this.removeItem("authToken");
|
|
3930
|
+
return null;
|
|
3931
|
+
}
|
|
3932
|
+
}
|
|
3933
|
+
}
|
|
3934
|
+
} catch (error) {
|
|
3935
|
+
console.warn("Failed to validate token expiry");
|
|
3936
|
+
this.removeItem("authToken");
|
|
3937
|
+
return null;
|
|
3938
|
+
}
|
|
3939
|
+
}
|
|
3940
|
+
return token;
|
|
3941
|
+
}
|
|
3942
|
+
};
|
|
3943
|
+
var secureSessionStorage = new SecureStorage("sessionStorage");
|
|
3944
|
+
var secureLocalStorage = new SecureStorage("localStorage");
|
|
4382
3945
|
export {
|
|
4383
|
-
CrudifyDataProvider,
|
|
4384
3946
|
CrudifyLogin_default as CrudifyLogin,
|
|
4385
3947
|
ERROR_CODES,
|
|
4386
3948
|
ERROR_SEVERITY_MAP,
|
|
@@ -4395,13 +3957,9 @@ export {
|
|
|
4395
3957
|
SessionStatus,
|
|
4396
3958
|
TokenStorage,
|
|
4397
3959
|
UserProfileDisplay_default as UserProfileDisplay,
|
|
4398
|
-
configurationManager,
|
|
4399
3960
|
default2 as crudify,
|
|
4400
|
-
crudifyInitializer,
|
|
4401
3961
|
decodeJwtSafely,
|
|
4402
3962
|
getCookie,
|
|
4403
|
-
getCrudifyInstanceAsync,
|
|
4404
|
-
getCrudifyInstanceSync,
|
|
4405
3963
|
getCurrentUserEmail,
|
|
4406
3964
|
getErrorMessage,
|
|
4407
3965
|
handleCrudifyError,
|
|
@@ -4411,15 +3969,7 @@ export {
|
|
|
4411
3969
|
parseTransactionError,
|
|
4412
3970
|
secureLocalStorage,
|
|
4413
3971
|
secureSessionStorage,
|
|
4414
|
-
tokenManager,
|
|
4415
3972
|
useAuth,
|
|
4416
|
-
useCrudifyAuth,
|
|
4417
|
-
useCrudifyConfig,
|
|
4418
|
-
useCrudifyData,
|
|
4419
|
-
useCrudifyDataContext,
|
|
4420
|
-
useCrudifyInstance,
|
|
4421
|
-
useCrudifyLogin,
|
|
4422
|
-
useCrudifyUser,
|
|
4423
3973
|
useData,
|
|
4424
3974
|
useSession,
|
|
4425
3975
|
useSessionContext,
|