@nocios/crudify-ui 4.1.38 → 4.1.42
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/chunk-2DIHMDQB.js +1 -0
- package/dist/{chunk-IDIHTELG.mjs → chunk-L2T6DEVZ.mjs} +1 -1
- package/dist/chunk-MC5C4A7O.js +1 -0
- package/dist/chunk-TRM4AJLI.mjs +1 -0
- package/dist/{chunk-JJJC7O2V.js → chunk-TWXGR53J.js} +1 -1
- package/dist/chunk-YV42XUB6.mjs +1 -0
- package/dist/components.js +1 -1
- package/dist/components.mjs +1 -1
- package/dist/hooks.d.mts +1 -1
- package/dist/hooks.d.ts +1 -1
- package/dist/hooks.js +1 -1
- package/dist/hooks.mjs +1 -1
- package/dist/{index-Dmy17Y3Q.d.ts → index-DAns9gSM.d.ts} +4 -4
- package/dist/{index-YgjxV8Ji.d.mts → index-DQlyZpa8.d.mts} +4 -4
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
- package/dist/chunk-47LRGZUJ.mjs +0 -1
- package/dist/chunk-CWOL4SNB.js +0 -1
- package/dist/chunk-HAI5IQJT.mjs +0 -1
- package/dist/chunk-YOSJN6AU.js +0 -1
package/dist/components.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkMC5C4A7Ojs = require('./chunk-MC5C4A7O.js');var _chunk2DIHMDQBjs = require('./chunk-2DIHMDQB.js');require('./chunk-YIIUEOXC.js');require('./chunk-AT74WV5W.js');var _react = require('react');var _jsxruntime = require('react/jsx-runtime');function G({showBelowMinutes:d=5,position:f="bottom-right",colorNormal:m="#ed6c02",colorCritical:x="#d32f2f",style:g,className:u}={}){let{isAuthenticated:o,tokens:t}=_chunk2DIHMDQBjs.e.call(void 0, ),[i,h]=_react.useState.call(void 0, 0),[y,S]=_react.useState.call(void 0, 100);if(_react.useEffect.call(void 0, ()=>{if(!o||!t)return;let P=setInterval(()=>{let C=Date.now(),p=t.expiresAt-C,w=900*1e3;h(Math.max(0,p)),S(Math.max(0,p/w*100))},1e3);return()=>clearInterval(P)},[o,t]),!o||i<=0)return null;let e=Math.floor(i/6e4),b=Math.floor(i%6e4/1e3);if(e>=d)return null;let s=e<2,a=s?x:m,v={"top-left":{top:"16px",left:"16px"},"top-right":{top:"16px",right:"16px"},"bottom-left":{bottom:"16px",left:"16px"},"bottom-right":{bottom:"16px",right:"16px"}}[f];return _jsxruntime.jsxs.call(void 0, "div",{className:u,style:{position:"fixed",...v,padding:"12px 16px",backgroundColor:"white",borderRadius:"8px",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)",minWidth:"200px",zIndex:9999,fontFamily:"system-ui, -apple-system, sans-serif",...g},children:[_jsxruntime.jsxs.call(void 0, "div",{style:{marginBottom:"8px"},children:[_jsxruntime.jsx.call(void 0, "div",{style:{fontSize:"12px",fontWeight:600,color:a,marginBottom:"4px"},children:s?"\u26A0\uFE0F Sesi\xF3n expirando":"\u23F0 Sesi\xF3n por expirar"}),_jsxruntime.jsxs.call(void 0, "div",{style:{fontSize:"14px",color:"#333",fontWeight:500},children:[e,":",b.toString().padStart(2,"0")]})]}),_jsxruntime.jsx.call(void 0, "div",{style:{width:"100%",height:"6px",backgroundColor:"#e0e0e0",borderRadius:"3px",overflow:"hidden"},children:_jsxruntime.jsx.call(void 0, "div",{style:{width:`${y}%`,height:"100%",backgroundColor:a,transition:"width 1s linear"}})})]})}exports.CrudifyLogin = _chunkMC5C4A7Ojs.a; exports.GlobalNotificationProvider = _chunk2DIHMDQBjs.f; exports.LoginComponent = _chunkMC5C4A7Ojs.f; exports.Policies = _chunkMC5C4A7Ojs.e; exports.SessionStatus = _chunkMC5C4A7Ojs.g; exports.SessionTimeIndicator = G; exports.UserProfileDisplay = _chunkMC5C4A7Ojs.b; exports.useGlobalNotification = _chunk2DIHMDQBjs.g;
|
package/dist/components.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as T,b as L,e as M,f as R,g as k}from"./chunk-
|
|
1
|
+
import{a as T,b as L,e as M,f as R,g as k}from"./chunk-TRM4AJLI.mjs";import{e as l,f as I,g as N}from"./chunk-YV42XUB6.mjs";import"./chunk-BJ6PIVZR.mjs";import"./chunk-5JKS55SE.mjs";import{useEffect as B,useState as c}from"react";import{jsx as r,jsxs as n}from"react/jsx-runtime";function G({showBelowMinutes:d=5,position:f="bottom-right",colorNormal:m="#ed6c02",colorCritical:x="#d32f2f",style:g,className:u}={}){let{isAuthenticated:o,tokens:t}=l(),[i,h]=c(0),[y,S]=c(100);if(B(()=>{if(!o||!t)return;let P=setInterval(()=>{let C=Date.now(),p=t.expiresAt-C,w=900*1e3;h(Math.max(0,p)),S(Math.max(0,p/w*100))},1e3);return()=>clearInterval(P)},[o,t]),!o||i<=0)return null;let e=Math.floor(i/6e4),b=Math.floor(i%6e4/1e3);if(e>=d)return null;let s=e<2,a=s?x:m,v={"top-left":{top:"16px",left:"16px"},"top-right":{top:"16px",right:"16px"},"bottom-left":{bottom:"16px",left:"16px"},"bottom-right":{bottom:"16px",right:"16px"}}[f];return n("div",{className:u,style:{position:"fixed",...v,padding:"12px 16px",backgroundColor:"white",borderRadius:"8px",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)",minWidth:"200px",zIndex:9999,fontFamily:"system-ui, -apple-system, sans-serif",...g},children:[n("div",{style:{marginBottom:"8px"},children:[r("div",{style:{fontSize:"12px",fontWeight:600,color:a,marginBottom:"4px"},children:s?"\u26A0\uFE0F Sesi\xF3n expirando":"\u23F0 Sesi\xF3n por expirar"}),n("div",{style:{fontSize:"14px",color:"#333",fontWeight:500},children:[e,":",b.toString().padStart(2,"0")]})]}),r("div",{style:{width:"100%",height:"6px",backgroundColor:"#e0e0e0",borderRadius:"3px",overflow:"hidden"},children:r("div",{style:{width:`${y}%`,height:"100%",backgroundColor:a,transition:"width 1s linear"}})})]})}export{T as CrudifyLogin,I as GlobalNotificationProvider,R as LoginComponent,M as Policies,k as SessionStatus,G as SessionTimeIndicator,L as UserProfileDisplay,N as useGlobalNotification};
|
package/dist/hooks.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as SessionState, j as UseAuthReturn, l as UseDataReturn, U as UseSessionOptions, g as UseUserDataOptions, f as UseUserDataReturn, h as UserData, i as useAuth, n as useCrudifyWithNotifications, k as useData, u as useSession, e as useUserData, m as useUserProfile } from './index-
|
|
1
|
+
export { d as SessionState, j as UseAuthReturn, l as UseDataReturn, U as UseSessionOptions, g as UseUserDataOptions, f as UseUserDataReturn, h as UserData, i as useAuth, n as useCrudifyWithNotifications, k as useData, u as useSession, e as useUserData, m as useUserProfile } from './index-DQlyZpa8.mjs';
|
|
2
2
|
import './api-Djqihi4n.mjs';
|
|
3
3
|
import './GlobalNotificationProvider-C3iWgM1z.mjs';
|
|
4
4
|
import 'react';
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as SessionState, j as UseAuthReturn, l as UseDataReturn, U as UseSessionOptions, g as UseUserDataOptions, f as UseUserDataReturn, h as UserData, i as useAuth, n as useCrudifyWithNotifications, k as useData, u as useSession, e as useUserData, m as useUserProfile } from './index-
|
|
1
|
+
export { d as SessionState, j as UseAuthReturn, l as UseDataReturn, U as UseSessionOptions, g as UseUserDataOptions, f as UseUserDataReturn, h as UserData, i as useAuth, n as useCrudifyWithNotifications, k as useData, u as useSession, e as useUserData, m as useUserProfile } from './index-DAns9gSM.js';
|
|
2
2
|
import './api-Djqihi4n.js';
|
|
3
3
|
import './GlobalNotificationProvider-C3iWgM1z.js';
|
|
4
4
|
import 'react';
|
package/dist/hooks.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkTWXGR53Jjs = require('./chunk-TWXGR53J.js');var _chunk2DIHMDQBjs = require('./chunk-2DIHMDQB.js');require('./chunk-AT74WV5W.js');exports.useAuth = _chunkTWXGR53Jjs.b; exports.useCrudifyWithNotifications = _chunkTWXGR53Jjs.d; exports.useData = _chunkTWXGR53Jjs.c; exports.useSession = _chunk2DIHMDQBjs.e; exports.useUserData = _chunkTWXGR53Jjs.a; exports.useUserProfile = _chunk2DIHMDQBjs.k;
|
package/dist/hooks.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as s,b as r,c as o,d as a}from"./chunk-
|
|
1
|
+
import{a as s,b as r,c as o,d as a}from"./chunk-L2T6DEVZ.mjs";import{e,k as t}from"./chunk-YV42XUB6.mjs";import"./chunk-5JKS55SE.mjs";export{r as useAuth,a as useCrudifyWithNotifications,o as useData,e as useSession,s as useUserData,t as useUserProfile};
|
|
@@ -94,6 +94,8 @@ type SessionConfig = {
|
|
|
94
94
|
onLogout?: () => void;
|
|
95
95
|
showNotification?: (message: string, severity?: "error" | "info" | "success" | "warning") => void;
|
|
96
96
|
translateFn?: (key: string) => string;
|
|
97
|
+
apiEndpointAdmin?: string;
|
|
98
|
+
apiKeyEndpointAdmin?: string;
|
|
97
99
|
};
|
|
98
100
|
type LoginResult = {
|
|
99
101
|
success: boolean;
|
|
@@ -157,10 +159,6 @@ declare class SessionManager {
|
|
|
157
159
|
apiEndpointAdmin: string | undefined;
|
|
158
160
|
apiKeyEndpointAdmin: string | undefined;
|
|
159
161
|
};
|
|
160
|
-
/**
|
|
161
|
-
* Fetch permissions and store admin API credentials
|
|
162
|
-
*/
|
|
163
|
-
fetchAndStoreAdminCredentials(): Promise<boolean>;
|
|
164
162
|
/**
|
|
165
163
|
* ✅ FASE 4: Refrescar tokens con protección contra concurrencia
|
|
166
164
|
*/
|
|
@@ -222,6 +220,8 @@ type UseSessionOptions = {
|
|
|
222
220
|
onSessionRestored?: (tokens: TokenData) => void;
|
|
223
221
|
showNotification?: (message: string, severity?: "error" | "info" | "success" | "warning") => void;
|
|
224
222
|
translateFn?: (key: string) => string;
|
|
223
|
+
apiEndpointAdmin?: string;
|
|
224
|
+
apiKeyEndpointAdmin?: string;
|
|
225
225
|
};
|
|
226
226
|
declare function useSession(options?: UseSessionOptions): {
|
|
227
227
|
login: (email: string, password: string) => Promise<LoginResult>;
|
|
@@ -94,6 +94,8 @@ type SessionConfig = {
|
|
|
94
94
|
onLogout?: () => void;
|
|
95
95
|
showNotification?: (message: string, severity?: "error" | "info" | "success" | "warning") => void;
|
|
96
96
|
translateFn?: (key: string) => string;
|
|
97
|
+
apiEndpointAdmin?: string;
|
|
98
|
+
apiKeyEndpointAdmin?: string;
|
|
97
99
|
};
|
|
98
100
|
type LoginResult = {
|
|
99
101
|
success: boolean;
|
|
@@ -157,10 +159,6 @@ declare class SessionManager {
|
|
|
157
159
|
apiEndpointAdmin: string | undefined;
|
|
158
160
|
apiKeyEndpointAdmin: string | undefined;
|
|
159
161
|
};
|
|
160
|
-
/**
|
|
161
|
-
* Fetch permissions and store admin API credentials
|
|
162
|
-
*/
|
|
163
|
-
fetchAndStoreAdminCredentials(): Promise<boolean>;
|
|
164
162
|
/**
|
|
165
163
|
* ✅ FASE 4: Refrescar tokens con protección contra concurrencia
|
|
166
164
|
*/
|
|
@@ -222,6 +220,8 @@ type UseSessionOptions = {
|
|
|
222
220
|
onSessionRestored?: (tokens: TokenData) => void;
|
|
223
221
|
showNotification?: (message: string, severity?: "error" | "info" | "success" | "warning") => void;
|
|
224
222
|
translateFn?: (key: string) => string;
|
|
223
|
+
apiEndpointAdmin?: string;
|
|
224
|
+
apiKeyEndpointAdmin?: string;
|
|
225
225
|
};
|
|
226
226
|
declare function useSession(options?: UseSessionOptions): {
|
|
227
227
|
login: (email: string, password: string) => Promise<LoginResult>;
|
package/dist/index.d.mts
CHANGED
|
@@ -2,8 +2,8 @@ export * from '@nocios/crudify-browser';
|
|
|
2
2
|
export { default as crudify } from '@nocios/crudify-browser';
|
|
3
3
|
export { B as BoxScreenType, C as CrudifyLogin, a as CrudifyLoginConfig, b as CrudifyLoginProps, c as CrudifyLoginTranslations, L as LoginComponent, f as POLICY_ACTIONS, g as PREFERRED_POLICY_ORDER, P as Policies, e as PolicyAction, S as SessionStatus, d as UserLoginData, U as UserProfileDisplay } from './LoginComponent-CSTVsfeV.mjs';
|
|
4
4
|
export { A as ApiError, C as CrudifyApiResponse, a as CrudifyTransactionResponse, F as ForgotPasswordRequest, J as JwtPayload, b as LoginRequest, L as LoginResponse, R as ResetPasswordRequest, T as TransactionResponseData, U as UserProfile, V as ValidateCodeRequest, c as ValidationError } from './api-Djqihi4n.mjs';
|
|
5
|
-
import { U as UseSessionOptions, T as TokenData, L as LoginResult } from './index-
|
|
6
|
-
export { a as SessionConfig, S as SessionManager, d as SessionState, c as StorageType, b as TokenStorage, j as UseAuthReturn, l as UseDataReturn, g as UseUserDataOptions, f as UseUserDataReturn, h as UserData, i as useAuth, n as useCrudifyWithNotifications, k as useData, u as useSession, e as useUserData, m as useUserProfile } from './index-
|
|
5
|
+
import { U as UseSessionOptions, T as TokenData, L as LoginResult } from './index-DQlyZpa8.mjs';
|
|
6
|
+
export { a as SessionConfig, S as SessionManager, d as SessionState, c as StorageType, b as TokenStorage, j as UseAuthReturn, l as UseDataReturn, g as UseUserDataOptions, f as UseUserDataReturn, h as UserData, i as useAuth, n as useCrudifyWithNotifications, k as useData, u as useSession, e as useUserData, m as useUserProfile } from './index-DQlyZpa8.mjs';
|
|
7
7
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
8
8
|
import React, { ReactNode } from 'react';
|
|
9
9
|
import { ThemeOptions } from '@mui/material';
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ export * from '@nocios/crudify-browser';
|
|
|
2
2
|
export { default as crudify } from '@nocios/crudify-browser';
|
|
3
3
|
export { B as BoxScreenType, C as CrudifyLogin, a as CrudifyLoginConfig, b as CrudifyLoginProps, c as CrudifyLoginTranslations, L as LoginComponent, f as POLICY_ACTIONS, g as PREFERRED_POLICY_ORDER, P as Policies, e as PolicyAction, S as SessionStatus, d as UserLoginData, U as UserProfileDisplay } from './LoginComponent-CSTVsfeV.js';
|
|
4
4
|
export { A as ApiError, C as CrudifyApiResponse, a as CrudifyTransactionResponse, F as ForgotPasswordRequest, J as JwtPayload, b as LoginRequest, L as LoginResponse, R as ResetPasswordRequest, T as TransactionResponseData, U as UserProfile, V as ValidateCodeRequest, c as ValidationError } from './api-Djqihi4n.js';
|
|
5
|
-
import { U as UseSessionOptions, T as TokenData, L as LoginResult } from './index-
|
|
6
|
-
export { a as SessionConfig, S as SessionManager, d as SessionState, c as StorageType, b as TokenStorage, j as UseAuthReturn, l as UseDataReturn, g as UseUserDataOptions, f as UseUserDataReturn, h as UserData, i as useAuth, n as useCrudifyWithNotifications, k as useData, u as useSession, e as useUserData, m as useUserProfile } from './index-
|
|
5
|
+
import { U as UseSessionOptions, T as TokenData, L as LoginResult } from './index-DAns9gSM.js';
|
|
6
|
+
export { a as SessionConfig, S as SessionManager, d as SessionState, c as StorageType, b as TokenStorage, j as UseAuthReturn, l as UseDataReturn, g as UseUserDataOptions, f as UseUserDataReturn, h as UserData, i as useAuth, n as useCrudifyWithNotifications, k as useData, u as useSession, e as useUserData, m as useUserProfile } from './index-DAns9gSM.js';
|
|
7
7
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
8
8
|
import React, { ReactNode } from 'react';
|
|
9
9
|
import { ThemeOptions } from '@mui/material';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkMC5C4A7Ojs = require('./chunk-MC5C4A7O.js');var _chunkTWXGR53Jjs = require('./chunk-TWXGR53J.js');var _chunk2DIHMDQBjs = require('./chunk-2DIHMDQB.js');var _chunkNNY4A73Vjs = require('./chunk-NNY4A73V.js');var _chunkYIIUEOXCjs = require('./chunk-YIIUEOXC.js');var _chunkAT74WV5Wjs = require('./chunk-AT74WV5W.js');var _crudifybrowser = require('@nocios/crudify-browser'); var _crudifybrowser2 = _interopRequireDefault(_crudifybrowser); _createStarExport(_crudifybrowser);var _react = require('react');var _material = require('@mui/material');var _jsxruntime = require('react/jsx-runtime');var Me=(o={})=>{try{let e=_chunkAT74WV5Wjs.a.call(void 0, "theme");if(e){let r=JSON.parse(decodeURIComponent(e));return{...o,...r}}}catch(e){console.warn("Error parsing theme from cookie:",e)}return o};function Fe({children:o,defaultTheme:e={},disableCssBaseline:r=!1}){let s=_react.useMemo.call(void 0, ()=>{let t=Me(e);return _material.createTheme.call(void 0, t)},[e]);return _jsxruntime.jsxs.call(void 0, _material.ThemeProvider,{theme:s,children:[!r&&_jsxruntime.jsx.call(void 0, _material.CssBaseline,{}),o]})}var _reactrouterdom = require('react-router-dom');var ze={border:"5px solid rgba(0, 0, 0, 0.1)",borderTopColor:"#3B82F6",borderRadius:"50%",width:"50px",height:"50px",animation:"spin 1s linear infinite"},Ke=()=>_jsxruntime.jsx.call(void 0, "style",{children:`
|
|
2
2
|
@keyframes spin {
|
|
3
3
|
0% { transform: rotate(0deg); }
|
|
4
4
|
100% { transform: rotate(360deg); }
|
|
5
5
|
}
|
|
6
|
-
`});function _({stage:o="loading",message:e}){let s=e||{initializing:"Initializing application...","validating-session":"Validating session...",loading:"Loading..."}[o];return _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment,{children:[_jsxruntime.jsx.call(void 0, Ke,{}),_jsxruntime.jsxs.call(void 0, "div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100vh",width:"100vw",backgroundColor:"#f0f2f5",fontFamily:'"Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',color:"#333",textAlign:"center",boxSizing:"border-box",padding:"20px",background:"#fff"},children:[_jsxruntime.jsx.call(void 0, "div",{style:ze}),_jsxruntime.jsx.call(void 0, "p",{style:{fontSize:"1.25em",fontWeight:"500",marginTop:"24px",color:"#1f2937"},children:s})]})]})}var He=/^[a-zA-Z0-9\-_./\?=&%#]+$/,Ye=[/^https?:\/\//i,/^ftp:\/\//i,/^\/\//,/javascript:/i,/data:/i,/vbscript:/i,/about:/i,/\.\.\//,/\.\.\\/,/%2e%2e%2f/i,/%2e%2e%5c/i,/%2f%2f/i,/%5c%5c/i,/[\x00-\x1f\x7f-\x9f]/,/\\/],b= exports.validateInternalRedirect =(o,e="/")=>{if(!o||typeof o!="string")return e;let r=o.trim();if(!r)return e;if(!r.startsWith("/"))return console.warn("\u{1F6A8} Open redirect blocked (relative path):",o),e;if(!He.test(r))return console.warn("\u{1F6A8} Open redirect blocked (invalid characters):",o),e;let s=r.toLowerCase();for(let n of Ye)if(n.test(s))return console.warn("\u{1F6A8} Open redirect blocked (dangerous pattern):",o),e;let t=r.split("?")[0].split("/").filter(Boolean);if(t.length===0)return r;for(let n of t)if(n===".."||n.includes(":")||n.length>100)return console.warn("\u{1F6A8} Open redirect blocked (suspicious path part):",n),e;return r},x= exports.extractSafeRedirectFromUrl =(o,e="/")=>{try{let s=(typeof o=="string"?new URLSearchParams(o):o).get("redirect");if(!s)return e;let t=decodeURIComponent(s);return b(t,e)}catch(r){return console.warn("\u{1F6A8} Error parsing redirect parameter:",r),e}};function q({children:o,loadingComponent:e,loginPath:r="/login"}){let{isAuthenticated:s,isLoading:t,isInitialized:n,tokens:u,error:a}=_chunkCWOL4SNBjs.g.call(void 0, ),d=_reactrouterdom.useLocation.call(void 0, );if(!n||t)return _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment,{children:e||_jsxruntime.jsx.call(void 0, _,{stage:"validating-session"})});let m=s&&_optionalChain([u, 'optionalAccess', _2 => _2.accessToken])&&u.accessToken.length>0;if(a||!s||!m){u&&(!u.accessToken||u.accessToken.length===0)&&localStorage.removeItem("crudify_tokens");let p=d.pathname+d.search,v=b(p),C=encodeURIComponent(v);return _jsxruntime.jsx.call(void 0, _reactrouterdom.Navigate,{to:`${r}?redirect=${C}`,replace:!0})}return _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment,{children:o})}function K({children:o,redirectTo:e="/"}){let{isAuthenticated:r}=_chunkCWOL4SNBjs.g.call(void 0, ),s=_reactrouterdom.useLocation.call(void 0, );if(r){let t=new URLSearchParams(s.search),n=x(t,e);return _jsxruntime.jsx.call(void 0, _reactrouterdom.Navigate,{to:n,replace:!0})}return _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment,{children:o})}var g={es:{"checkCode.codeLabel":"C\xF3digo de Verificaci\xF3n","checkCode.codePlaceholder":"Ingresa el c\xF3digo de 6 d\xEDgitos","checkCode.codeRequired":"El c\xF3digo es obligatorio","checkCode.emailLabel":"Correo Electr\xF3nico","checkCode.emailPlaceholder":"Ingresa tu correo electr\xF3nico","checkCode.emailRequired":"El correo electr\xF3nico es obligatorio","checkCode.instructions":"Ingresa el c\xF3digo de 6 d\xEDgitos que enviamos a tu correo electr\xF3nico.","checkCode.invalidEmail":"Ingresa un correo electr\xF3nico v\xE1lido","checkCode.resendCodeLink":"Reenviar c\xF3digo","checkCode.title":"Verificar C\xF3digo","checkCode.verifyButton":"Verificar C\xF3digo","common.back":"Volver","common.backToLogin":"Volver","error.app.config":"Error de Configuraci\xF3n: {{message}}","error.app.initialization":"Error durante la inicializaci\xF3n final de la aplicaci\xF3n.","error.transaction":"Error en la operaci\xF3n","error.unknown":"Ocurri\xF3 un error desconocido.","errors.DUPLICATE":"El campo <b>{{field}}</b> debe ser \xFAnico.","errors.FOREIGN_KEY_NOT_FOUND":"El campo <b>{{field}}</b> debe referenciar un \xEDtem existente.","errors.INVALID_EMAIL":"El campo <b>{{field}}</b> debe ser un correo electr\xF3nico v\xE1lido.","errors.INVALID_OBJECT_ID":"El campo <b>{{field}}</b> debe ser un valor v\xE1lido.","errors.IN_USE":"El \xEDtem est\xE1 en uso y no puede ser eliminado.","errors.MAX_LENGTH":"El campo <b>{{field}}</b> no debe exceder los <b>{{length}}</b> caracteres.","errors.MIN_LENGTH":"El campo <b>{{field}}</b> debe tener al menos <b>{{length}}</b> caracteres.","errors.MUST_NOT_BE_EMAIL":"El campo <b>{{field}}</b> no debe ser un correo electr\xF3nico.","errors.NO_PERMISSION":"No tienes permiso para realizar esta acci\xF3n.","errors.NO_SPACES":"El campo <b>{{field}}</b> no debe contener espacios.","errors.ONE_OR_MORE_OPERATIONS_FAILED":"Error en la operaci\xF3n","errors.REQUIRED":"El campo <b>{{field}}</b> es obligatorio.","errors.TOKEN_HAS_EXPIRED":"La sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.","errors.TOO_MANY_REQUESTS":"L\xEDmite de solicitudes alcanzado. Por favor intenta m\xE1s tarde.","errors.UNAUTHORIZED":"No est\xE1s autorizado para realizar esta acci\xF3n.","errors.all_password_fields_required":"Todos los campos de contrase\xF1a son obligatorios","errors.auth.INVALID_API_KEY":"Clave de API inv\xE1lida","errors.auth.INVALID_CREDENTIALS":"Usuario y/o contrase\xF1a incorrectos","errors.auth.NO_PERMISSION":"No tienes permisos suficientes","errors.auth.SESSION_EXPIRED":"Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.","errors.auth.TOO_MANY_REQUESTS":"Demasiados intentos. Por favor espera 15 minutos e intenta nuevamente","errors.auth.UNAUTHORIZED":"No tienes permisos para realizar esta acci\xF3n","errors.auth.USER_NOT_ACTIVE":"Usuario no activo","errors.auth.USER_NOT_FOUND":"Usuario no encontrado","errors.data.BAD_REQUEST":"Solicitud inv\xE1lida","errors.data.FIELD_ERROR":"Error en los datos ingresados","errors.data.IN_USE":"El elemento est\xE1 en uso y no puede ser eliminado","errors.data.ITEM_NOT_FOUND":"El elemento solicitado no fue encontrado","errors.data.NOT_FOUND":"No se encontr\xF3 lo solicitado","errors.internal_error_changing_password":"Error interno al cambiar la contrase\xF1a. Intenta nuevamente","errors.password_min_length":"La contrase\xF1a debe tener al menos 8 caracteres","errors.password_mismatch":"Las contrase\xF1as no coinciden","errors.password_must_be_different":"La nueva contrase\xF1a debe ser diferente a la actual","errors.system.DATABASE_CONNECTION_ERROR":"Error de conexi\xF3n. Verifica tu conexi\xF3n a internet.","errors.system.INTERNAL_SERVER_ERROR":"Error interno del servidor. Intenta nuevamente.","errors.system.INVALID_CONFIGURATION":"Error de configuraci\xF3n del sistema","errors.system.TOO_MANY_REQUESTS":"Demasiadas solicitudes. Por favor espera un momento e intenta nuevamente","errors.system.UNKNOWN_OPERATION":"Operaci\xF3n no reconocida","errors.users_module_not_configured":"M\xF3dulo de usuarios no configurado","footer.copyright":"Nocios S.R.L. Todos los derechos reservados.","footer.version":"Versi\xF3n","forgotPassword.checkEmailInstructions":"Revisa tu bandeja de entrada para el c\xF3digo de verificaci\xF3n","forgotPassword.codeAlreadyExistsMessage":"Ya se envi\xF3 un c\xF3digo y a\xFAn es v\xE1lido","forgotPassword.emailLabel":"Correo Electr\xF3nico","forgotPassword.emailPlaceholder":"Ingresa tu correo electr\xF3nico","forgotPassword.emailRequired":"El correo electr\xF3nico es obligatorio","forgotPassword.emailSentMessage":"C\xF3digo enviado exitosamente","forgotPassword.enterCodeLink":"Ingresar C\xF3digo","forgotPassword.instructions":"Ingresa tu correo electr\xF3nico y te enviaremos un c\xF3digo para restablecer tu contrase\xF1a.","forgotPassword.invalidEmail":"Ingresa un correo electr\xF3nico v\xE1lido","forgotPassword.sendCodeButton":"Enviar C\xF3digo","forgotPassword.title":"Recuperar Contrase\xF1a","loading.app.configInitial":"Cargando configuraci\xF3n inicial...","loading.app.generic":"Cargando...","loading.app.starting":"Iniciando aplicaci\xF3n...","loading.app.themeSetup":"Generando tema...","loading.app.validatingSession":"Validando sesi\xF3n...","login.alreadyHaveCodeLink":"\xBFYa tienes un c\xF3digo?","login.forgotPasswordLink":"\xBFOlvidaste tu contrase\xF1a?","login.initializationError":"Error de inicializaci\xF3n","login.initializing":"Inicializando...","login.loginButton":"Iniciar Sesi\xF3n","login.logoAlt":"Logotipo","login.noAccountPrompt":"\xBFNo tienes una cuenta?","login.notInitialized":"Sistema no inicializado","login.passwordLabel":"Contrase\xF1a","login.passwordPlaceholder":"Ingresa tu contrase\xF1a","login.passwordRequired":"Contrase\xF1a es obligatoria","login.signUpLink":"Reg\xEDstrate","login.usernameOrEmailLabel":"Usuario o Correo Electr\xF3nico","login.usernameOrEmailPlaceholder":"Ingresa tu usuario o correo electr\xF3nico","login.usernameRequired":"Usuario o correo electr\xF3nico es obligatorio","resetPassword.codeExpiredOrInvalid":"El c\xF3digo ha expirado o es inv\xE1lido","resetPassword.confirmPasswordLabel":"Confirmar Contrase\xF1a","resetPassword.confirmPasswordPlaceholder":"Confirma tu nueva contrase\xF1a","resetPassword.confirmPasswordRequired":"Confirma tu contrase\xF1a","resetPassword.goToLoginButton":"Ir al Login","resetPassword.instructions":"Ingresa tu nueva contrase\xF1a.","resetPassword.invalidCode":"El c\xF3digo de verificaci\xF3n es inv\xE1lido. Por favor, verifica el enlace o solicita uno nuevo.","resetPassword.missingParameters":"Faltan par\xE1metros obligatorios","resetPassword.newPasswordLabel":"Nueva Contrase\xF1a","resetPassword.newPasswordPlaceholder":"Ingresa tu nueva contrase\xF1a","resetPassword.newPasswordRequired":"La nueva contrase\xF1a es obligatoria","resetPassword.passwordTooShort":"La contrase\xF1a debe tener al menos 8 caracteres","resetPassword.passwordsDoNotMatch":"Las contrase\xF1as no coinciden","resetPassword.requestNewCodeButton":"Solicitar Nuevo C\xF3digo","resetPassword.resetPasswordButton":"Restablecer Contrase\xF1a","resetPassword.successInstructions":"Ahora puedes iniciar sesi\xF3n con tu nueva contrase\xF1a","resetPassword.successMessage":"Contrase\xF1a restablecida exitosamente","resetPassword.title":"Nueva Contrase\xF1a","resetPassword.validatingCode":"Validando c\xF3digo..."},en:{"checkCode.codeLabel":"Verification Code","checkCode.codePlaceholder":"Enter 6-digit code","checkCode.codeRequired":"Code is required","checkCode.emailLabel":"Email Address","checkCode.emailPlaceholder":"Enter your email address","checkCode.emailRequired":"Email address is required","checkCode.instructions":"Enter the 6-digit code we sent to your email address.","checkCode.invalidEmail":"Enter a valid email address","checkCode.resendCodeLink":"Resend code","checkCode.title":"Verify Code","checkCode.verifyButton":"Verify Code","common.back":"Back","common.backToLogin":"Back to Login","error.app.config":"Configuration Error: {{message}}","error.app.initialization":"Error during final application initialization.","error.transaction":"Operation error","error.unknown":"An unknown error occurred.","errors.DUPLICATE":"The field <b>{{field}}</b> must be unique.","errors.FOREIGN_KEY_NOT_FOUND":"The field <b>{{field}}</b> must reference an existing item.","errors.INVALID_EMAIL":"The field <b>{{field}}</b> must be a valid email address.","errors.INVALID_OBJECT_ID":"The field <b>{{field}}</b> must be a valid value.","errors.IN_USE":"The item is currently in use and cannot be deleted.","errors.MAX_LENGTH":"The field <b>{{field}}</b> must not exceed <b>{{maxLength}}</b> characters.","errors.MIN_LENGTH":"The field <b>{{field}}</b> must have at least <b>{{minLength}}</b> characters.","errors.MUST_NOT_BE_EMAIL":"The field <b>{{field}}</b> must not be an email address.","errors.NO_PERMISSION":"You do not have permission to perform this action.","errors.NO_SPACES":"The field <b>{{field}}</b> must not contain spaces.","errors.ONE_OR_MORE_OPERATIONS_FAILED":"Operation error","errors.REQUIRED":"The field <b>{{field}}</b> is required.","errors.TOKEN_HAS_EXPIRED":"Your session has expired, please log in again.","errors.TOO_MANY_REQUESTS":"Request limit reached. Please try again later.","errors.UNAUTHORIZED":"You are not authorized to perform this action.","errors.all_password_fields_required":"All password fields are required","errors.auth.INVALID_API_KEY":"Invalid API key","errors.auth.INVALID_CREDENTIALS":"Incorrect username and/or password","errors.auth.NO_PERMISSION":"Insufficient permissions","errors.auth.SESSION_EXPIRED":"Your session has expired. Please log in again.","errors.auth.TOO_MANY_REQUESTS":"Too many attempts. Please wait 15 minutes and try again","errors.auth.UNAUTHORIZED":"You don't have permission to perform this action","errors.auth.USER_NOT_ACTIVE":"User account is not active","errors.auth.USER_NOT_FOUND":"User not found","errors.data.BAD_REQUEST":"Invalid request","errors.data.FIELD_ERROR":"Error in the provided data","errors.data.IN_USE":"The item is in use and cannot be deleted","errors.data.ITEM_NOT_FOUND":"The requested item was not found","errors.data.NOT_FOUND":"The requested resource was not found","errors.internal_error_changing_password":"Internal error changing password. Please try again","errors.password_min_length":"Password must be at least 8 characters","errors.password_mismatch":"Passwords do not match","errors.password_must_be_different":"New password must be different from current password","errors.system.DATABASE_CONNECTION_ERROR":"Connection error. Please check your internet connection.","errors.system.INTERNAL_SERVER_ERROR":"Internal server error. Please try again.","errors.system.INVALID_CONFIGURATION":"System configuration error","errors.system.TOO_MANY_REQUESTS":"Too many requests. Please wait a moment and try again","errors.system.UNKNOWN_OPERATION":"Unrecognized operation","errors.users_module_not_configured":"Users module not configured","footer.copyright":"Nocios S.R.L. All Rights Reserved.","footer.version":"Version","forgotPassword.checkEmailInstructions":"Check your inbox for the verification code","forgotPassword.codeAlreadyExistsMessage":"A code was already sent and is still valid","forgotPassword.emailLabel":"Email Address","forgotPassword.emailPlaceholder":"Enter your email address","forgotPassword.emailRequired":"Email address is required","forgotPassword.emailSentMessage":"Code sent successfully","forgotPassword.enterCodeLink":"Enter Code","forgotPassword.instructions":"Enter your email address and we'll send you a code to reset your password.","forgotPassword.invalidEmail":"Enter a valid email address","forgotPassword.sendCodeButton":"Send Code","forgotPassword.title":"Reset Password","loading.app.configInitial":"Loading initial configuration...","loading.app.generic":"Loading...","loading.app.starting":"Starting application...","loading.app.themeSetup":"Generating theme...","loading.app.validatingSession":"Validating session...","login.alreadyHaveCodeLink":"Already have a code?","login.forgotPasswordLink":"Forgot Password?","login.initializationError":"Initialization error","login.initializing":"Initializing...","login.loginButton":"Log In","login.logoAlt":"Logo","login.noAccountPrompt":"Don't have an account?","login.notInitialized":"System not initialized","login.passwordLabel":"Password","login.passwordPlaceholder":"Enter your password","login.passwordRequired":"Password is required","login.signUpLink":"Sign up","login.usernameOrEmailLabel":"Username or Email","login.usernameOrEmailPlaceholder":"Enter your username or email","login.usernameRequired":"Username or email is required","resetPassword.codeExpiredOrInvalid":"Code expired or invalid","resetPassword.confirmPasswordLabel":"Confirm Password","resetPassword.confirmPasswordPlaceholder":"Confirm your new password","resetPassword.confirmPasswordRequired":"Confirm your password","resetPassword.goToLoginButton":"Go to Login","resetPassword.instructions":"Enter your new password.","resetPassword.invalidCode":"The verification code is invalid. Please check the link or request a new one.","resetPassword.missingParameters":"Missing required parameters","resetPassword.newPasswordLabel":"New Password","resetPassword.newPasswordPlaceholder":"Enter your new password","resetPassword.newPasswordRequired":"New password is required","resetPassword.passwordTooShort":"Password must be at least 8 characters","resetPassword.passwordsDoNotMatch":"Passwords do not match","resetPassword.requestNewCodeButton":"Request New Code","resetPassword.resetPasswordButton":"Reset Password","resetPassword.successInstructions":"You can now log in with your new password","resetPassword.successMessage":"Password reset successfully","resetPassword.title":"New Password","resetPassword.validatingCode":"Validating code..."}},Qe= exports.getCriticalLanguages =()=>Object.keys(g),Xe= exports.getCriticalTranslations =o=>g[o]||g.es;var B="crudify_translations_",er=3600*1e3,N= exports.TranslationService =class o{constructor(){this.enableDebug=!1}static getInstance(){return o.instance||(o.instance=new o),o.instance}setDebug(e){this.enableDebug=e}async fetchTranslations(e){let{subscriberKey:r,apiKey:s,sections:t,crudifyEnv:n="stg",urlTranslations:u}=e,a=this.getFromCache(r),d=a?this.isCacheExpired(a):!0;if(a&&!d)return this.enableDebug&&console.log("[TranslationService] Using cached translations"),this.mergeWithUrlTranslations(a.data.translations,u);try{this.enableDebug&&console.log("[TranslationService] Fetching from API via crudify SDK...");let m=await this.fetchFromAPI(t);return this.hasDataChanged(a,m)||!a?(this.enableDebug&&console.log("[TranslationService] Data changed, updating cache"),this.saveToCache(r,m)):(this.enableDebug&&console.log("[TranslationService] Data unchanged, refreshing cache timestamp"),this.refreshCacheTimestamp(r)),this.mergeWithUrlTranslations(m.translations,u)}catch(m){return console.error("[TranslationService] API fetch failed:",m),a?(console.warn("[TranslationService] Using expired cache as fallback"),this.mergeWithUrlTranslations(a.data.translations,u)):(console.warn("[TranslationService] Using critical bundle translations"),this.getCriticalTranslationsOnly())}}async fetchFromAPI(e){let r=await _crudifybrowser2.default.getTranslation(e);if(!r.success)throw new Error(`Crudify API error: ${r.errors?JSON.stringify(r.errors):"Unknown error"}`);if(!r.data)throw new Error("No translation data in response");return r.data}mergeWithUrlTranslations(e,r){if(!r||Object.keys(r).length===0)return e;let s={};return Object.keys(e).forEach(t=>{s[t]={...e[t],...r}}),s}hasDataChanged(e,r){if(!e||e.data.timestamp!==r.timestamp)return!0;let s=this.hashData(r.translations);return e.dataHash!==s}hashData(e){let r=JSON.stringify(e),s=0;for(let t=0;t<r.length;t++){let n=r.charCodeAt(t);s=(s<<5)-s+n,s=s&s}return s.toString(36)}saveToCache(e,r){try{let s=this.getCacheKey(e),t={data:r,cachedAt:Date.now(),dataHash:this.hashData(r.translations)};localStorage.setItem(s,JSON.stringify(t)),this.enableDebug&&console.log("[TranslationService] Saved to cache:",s)}catch(s){console.error("[TranslationService] Failed to save cache:",s)}}getFromCache(e){try{let r=this.getCacheKey(e),s=localStorage.getItem(r);return s?JSON.parse(s):null}catch(r){return console.error("[TranslationService] Failed to read cache:",r),null}}refreshCacheTimestamp(e){try{let r=this.getFromCache(e);if(r){r.cachedAt=Date.now();let s=this.getCacheKey(e);localStorage.setItem(s,JSON.stringify(r))}}catch(r){console.error("[TranslationService] Failed to refresh cache timestamp:",r)}}isCacheExpired(e){return Date.now()-e.cachedAt>er}getCacheKey(e){return`${B}${e}`}getCriticalTranslationsOnly(){return g}invalidateCache(e){let r=this.getCacheKey(e);localStorage.removeItem(r),this.enableDebug&&console.log("[TranslationService] Cache invalidated:",r)}async prefetchTranslations(e){try{await this.fetchTranslations(e),this.enableDebug&&console.log("[TranslationService] Prefetch completed")}catch(r){console.error("[TranslationService] Prefetch failed:",r)}}clearAllCaches(){try{let r=Object.keys(localStorage).filter(s=>s.startsWith(B));r.forEach(s=>localStorage.removeItem(s)),this.enableDebug&&console.log(`[TranslationService] Cleared ${r.length} cache entries`)}catch(e){console.error("[TranslationService] Failed to clear caches:",e)}}},O= exports.translationService =N.getInstance();var G=_react.createContext.call(void 0, null);function H(o,e,r){return{...o,...e,...r||{}}}var ir=({children:o,subscriberKey:e,apiKey:r,crudifyEnv:s="stg",sections:t,language:n="es",devTranslations:u,translationUrl:a,enableDebug:d=!1,skipAutoInit:m=!0})=>{let[p,v]=_react.useState.call(void 0, {}),[C,k]=_react.useState.call(void 0, !0),[$,U]=_react.useState.call(void 0, null),[j,D]=_react.useState.call(void 0, void 0),[M,J]=_react.useState.call(void 0, !1),I=_react.useCallback.call(void 0, async()=>{if(M){d&&console.log("[TranslationsProvider] Skipping reload - using fallback translations");return}k(!0),U(null);let i;if(a)try{d&&console.log(`[TranslationsProvider] Fetching translations from URL: ${a}`);let l=await fetch(a);if(!l.ok)throw new Error(`Failed to fetch translations: ${l.statusText}`);i=await l.json(),D(i),d&&console.log("[TranslationsProvider] URL translations loaded:",{keysCount:i?Object.keys(i).length:0})}catch(l){console.error("[TranslationsProvider] Failed to load URL translations:",l),i=void 0,D(void 0)}try{O.setDebug(d);let l=await O.fetchTranslations({subscriberKey:e,apiKey:r,crudifyEnv:s,sections:t,urlTranslations:i}),h={};Object.keys(l).forEach(c=>{let T=g[c]||{},P=l[c]||{};h[c]=H(T,P,u)}),v(h),d&&console.log("[TranslationsProvider] Loaded translations:",{languages:Object.keys(h),keysCount:Object.keys(h[n]||{}).length})}catch(l){console.error("[TranslationsProvider] Failed to load:",l),U(l.message),J(!0);let h={};Object.keys(g).forEach(c=>{let T=g[c],P=i||j||{};h[c]=H(T,P,u)}),v(h),d&&console.log("[TranslationsProvider] Using fallback translations (critical + URL)")}finally{k(!1)}},[e,r,s,t,a,u,d,n,M]);_react.useEffect.call(void 0, ()=>{I();let i=setInterval(I,3600*1e3);return()=>clearInterval(i)},[I]);let Q={t:_react.useMemo.call(void 0, ()=>(i,l)=>{let c=(p[n]||{})[i];if(!c){let T=Object.keys(p);for(let P of T)if(p[P][i]){c=p[P][i];break}}return c||(d&&console.warn(`[TranslationsProvider] Missing translation: "${i}"`),c=i),l&&typeof c=="string"&&Object.entries(l).forEach(([T,P])=>{let X=new RegExp(`{{${T}}}`,"g");c=c.replace(X,String(P))}),c},[p,n,d]),language:n,availableLanguages:Object.keys(p),translations:p,isLoading:C,error:$,refreshTranslations:I};if(C){let i=_optionalChain([g, 'access', _3 => _3[n], 'optionalAccess', _4 => _4.loading])||"Loading...";return _jsxruntime.jsx.call(void 0, "div",{children:i})}return _jsxruntime.jsx.call(void 0, G.Provider,{value:Q,children:o})},ar= exports.useTranslations =()=>{let o=_react.useContext.call(void 0, G);if(!o)throw new Error("useTranslations must be used within TranslationsProvider");return o};var _crudifyadmin = require('@nocios/crudify-admin'); var _crudifyadmin2 = _interopRequireDefault(_crudifyadmin);var W=!1;function cr(){if(!W){let o=_chunkCWOL4SNBjs.b.getInstance(),e=o.getTokenInfo(),r=_optionalChain([e, 'optionalAccess', _5 => _5.apiEndpointAdmin]),s=_optionalChain([e, 'optionalAccess', _6 => _6.apiKeyEndpointAdmin]);if(r===void 0||s===void 0)throw new Error("crudifyAdmin: API URL or API Key for admin endpoint are not defined.");_optionalChain([e, 'optionalAccess', _7 => _7.apiEndpointAdmin])&&_optionalChain([e, 'optionalAccess', _8 => _8.apiKeyEndpointAdmin])?console.log("\u{1F527} crudifyAdmin: Initializing with dynamic credentials from getPermissions"):console.warn("\u26A0\uFE0F crudifyAdmin: Using fallback credentials (admin credentials not yet loaded from getPermissions)"),_crudifyadmin2.default.init({url:r,apiKey:s,getAdditionalHeaders:()=>{let t=o.getTokenInfo();return _optionalChain([t, 'optionalAccess', _9 => _9.crudifyTokens, 'optionalAccess', _10 => _10.accessToken])?{Authorization:`Bearer ${t.crudifyTokens.accessToken}`}:{}}}),W=!0}}async function R(o){try{cr();let e=await o();return!e.success&&_optionalChain([e, 'access', _11 => _11.errors, 'optionalAccess', _12 => _12.includes, 'call', _13 => _13("401")])?await _chunkCWOL4SNBjs.b.getInstance().refreshTokens()?await o():(console.error("Token refresh failed in crudifyAdmin"),typeof window<"u"&&(window.location.href="/login"),e):e}catch(e){return console.error("Error in crudifyAdmin operation:",e),{success:!1,errors:e instanceof Error?e.message:"Unknown error"}}}var dr={listModules:()=>R(()=>_crudifyadmin2.default.listModules()),getModule:o=>R(()=>_crudifyadmin2.default.getModule(o)),createModule:o=>R(()=>_crudifyadmin2.default.createModule(o)),editModule:(o,e)=>R(()=>_crudifyadmin2.default.editModule(o,e)),deleteModule:o=>R(()=>_crudifyadmin2.default.deleteModule(o)),activateModule:o=>R(()=>_crudifyadmin2.default.activateModule(o)),deactivateModule:o=>R(()=>_crudifyadmin2.default.deactivateModule(o)),getModuleVersions:o=>R(()=>_crudifyadmin2.default.getModuleVersions(o))};exports.AuthRoute = K; exports.CRITICAL_TRANSLATIONS = g; exports.CrudifyLogin = _chunkYOSJN6AUjs.a; exports.CrudifyThemeProvider = Fe; exports.ERROR_CODES = _chunkYIIUEOXCjs.a; exports.ERROR_SEVERITY_MAP = _chunkYIIUEOXCjs.b; exports.GlobalNotificationProvider = _chunkCWOL4SNBjs.d; exports.LoginComponent = _chunkYOSJN6AUjs.f; exports.POLICY_ACTIONS = _chunkYOSJN6AUjs.c; exports.PREFERRED_POLICY_ORDER = _chunkYOSJN6AUjs.d; exports.Policies = _chunkYOSJN6AUjs.e; exports.ProtectedRoute = q; exports.SessionDebugInfo = _chunkCWOL4SNBjs.h; exports.SessionLoadingScreen = _; exports.SessionManager = _chunkCWOL4SNBjs.b; exports.SessionProvider = _chunkCWOL4SNBjs.f; exports.SessionStatus = _chunkYOSJN6AUjs.g; exports.TokenStorage = _chunkCWOL4SNBjs.a; exports.TranslationService = N; exports.TranslationsProvider = ir; exports.UserProfileDisplay = _chunkYOSJN6AUjs.b; exports.createErrorTranslator = _chunkAT74WV5Wjs.e; exports.crudify = _crudifybrowser2.default; exports.crudifyAdmin = dr; exports.decodeJwtSafely = _chunkAT74WV5Wjs.h; exports.extractSafeRedirectFromUrl = x; exports.getCookie = _chunkAT74WV5Wjs.a; exports.getCriticalLanguages = Qe; exports.getCriticalTranslations = Xe; exports.getCurrentUserEmail = _chunkAT74WV5Wjs.i; exports.getErrorMessage = _chunkYIIUEOXCjs.e; exports.handleCrudifyError = _chunkYIIUEOXCjs.g; exports.isTokenExpired = _chunkAT74WV5Wjs.j; exports.parseApiError = _chunkYIIUEOXCjs.c; exports.parseJavaScriptError = _chunkYIIUEOXCjs.f; exports.parseTransactionError = _chunkYIIUEOXCjs.d; exports.secureLocalStorage = _chunkNNY4A73Vjs.b; exports.secureSessionStorage = _chunkNNY4A73Vjs.a; exports.translateError = _chunkAT74WV5Wjs.d; exports.translateErrorCode = _chunkAT74WV5Wjs.b; exports.translateErrorCodes = _chunkAT74WV5Wjs.c; exports.translationService = O; exports.useAuth = _chunkJJJC7O2Vjs.b; exports.useCrudifyWithNotifications = _chunkJJJC7O2Vjs.d; exports.useData = _chunkJJJC7O2Vjs.c; exports.useGlobalNotification = _chunkCWOL4SNBjs.e; exports.useSession = _chunkCWOL4SNBjs.c; exports.useSessionContext = _chunkCWOL4SNBjs.g; exports.useTranslations = ar; exports.useUserData = _chunkJJJC7O2Vjs.a; exports.useUserProfile = _chunkCWOL4SNBjs.i; exports.validateInternalRedirect = b;
|
|
6
|
+
`});function _({stage:o="loading",message:e}){let s=e||{initializing:"Initializing application...","validating-session":"Validating session...",loading:"Loading..."}[o];return _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment,{children:[_jsxruntime.jsx.call(void 0, Ke,{}),_jsxruntime.jsxs.call(void 0, "div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100vh",width:"100vw",backgroundColor:"#f0f2f5",fontFamily:'"Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',color:"#333",textAlign:"center",boxSizing:"border-box",padding:"20px",background:"#fff"},children:[_jsxruntime.jsx.call(void 0, "div",{style:ze}),_jsxruntime.jsx.call(void 0, "p",{style:{fontSize:"1.25em",fontWeight:"500",marginTop:"24px",color:"#1f2937"},children:s})]})]})}var He=/^[a-zA-Z0-9\-_./\?=&%#]+$/,Ye=[/^https?:\/\//i,/^ftp:\/\//i,/^\/\//,/javascript:/i,/data:/i,/vbscript:/i,/about:/i,/\.\.\//,/\.\.\\/,/%2e%2e%2f/i,/%2e%2e%5c/i,/%2f%2f/i,/%5c%5c/i,/[\x00-\x1f\x7f-\x9f]/,/\\/],A= exports.validateInternalRedirect =(o,e="/")=>{if(!o||typeof o!="string")return e;let r=o.trim();if(!r)return e;if(!r.startsWith("/"))return console.warn("\u{1F6A8} Open redirect blocked (relative path):",o),e;if(!He.test(r))return console.warn("\u{1F6A8} Open redirect blocked (invalid characters):",o),e;let s=r.toLowerCase();for(let n of Ye)if(n.test(s))return console.warn("\u{1F6A8} Open redirect blocked (dangerous pattern):",o),e;let t=r.split("?")[0].split("/").filter(Boolean);if(t.length===0)return r;for(let n of t)if(n===".."||n.includes(":")||n.length>100)return console.warn("\u{1F6A8} Open redirect blocked (suspicious path part):",n),e;return r},x= exports.extractSafeRedirectFromUrl =(o,e="/")=>{try{let s=(typeof o=="string"?new URLSearchParams(o):o).get("redirect");if(!s)return e;let t=decodeURIComponent(s);return A(t,e)}catch(r){return console.warn("\u{1F6A8} Error parsing redirect parameter:",r),e}};function q({children:o,loadingComponent:e,loginPath:r="/login"}){let{isAuthenticated:s,isLoading:t,isInitialized:n,tokens:u,error:a}=_chunk2DIHMDQBjs.i.call(void 0, ),d=_reactrouterdom.useLocation.call(void 0, );if(!n||t)return _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment,{children:e||_jsxruntime.jsx.call(void 0, _,{stage:"validating-session"})});let m=s&&_optionalChain([u, 'optionalAccess', _2 => _2.accessToken])&&u.accessToken.length>0;if(a||!s||!m){u&&(!u.accessToken||u.accessToken.length===0)&&localStorage.removeItem("crudify_tokens");let p=d.pathname+d.search,v=A(p),C=encodeURIComponent(v);return _jsxruntime.jsx.call(void 0, _reactrouterdom.Navigate,{to:`${r}?redirect=${C}`,replace:!0})}return _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment,{children:o})}function K({children:o,redirectTo:e="/"}){let{isAuthenticated:r}=_chunk2DIHMDQBjs.i.call(void 0, ),s=_reactrouterdom.useLocation.call(void 0, );if(r){let t=new URLSearchParams(s.search),n=x(t,e);return _jsxruntime.jsx.call(void 0, _reactrouterdom.Navigate,{to:n,replace:!0})}return _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment,{children:o})}var g={es:{"checkCode.codeLabel":"C\xF3digo de Verificaci\xF3n","checkCode.codePlaceholder":"Ingresa el c\xF3digo de 6 d\xEDgitos","checkCode.codeRequired":"El c\xF3digo es obligatorio","checkCode.emailLabel":"Correo Electr\xF3nico","checkCode.emailPlaceholder":"Ingresa tu correo electr\xF3nico","checkCode.emailRequired":"El correo electr\xF3nico es obligatorio","checkCode.instructions":"Ingresa el c\xF3digo de 6 d\xEDgitos que enviamos a tu correo electr\xF3nico.","checkCode.invalidEmail":"Ingresa un correo electr\xF3nico v\xE1lido","checkCode.resendCodeLink":"Reenviar c\xF3digo","checkCode.title":"Verificar C\xF3digo","checkCode.verifyButton":"Verificar C\xF3digo","common.back":"Volver","common.backToLogin":"Volver","error.app.config":"Error de Configuraci\xF3n: {{message}}","error.app.initialization":"Error durante la inicializaci\xF3n final de la aplicaci\xF3n.","error.transaction":"Error en la operaci\xF3n","error.unknown":"Ocurri\xF3 un error desconocido.","errors.DUPLICATE":"El campo <b>{{field}}</b> debe ser \xFAnico.","errors.FOREIGN_KEY_NOT_FOUND":"El campo <b>{{field}}</b> debe referenciar un \xEDtem existente.","errors.INVALID_EMAIL":"El campo <b>{{field}}</b> debe ser un correo electr\xF3nico v\xE1lido.","errors.INVALID_OBJECT_ID":"El campo <b>{{field}}</b> debe ser un valor v\xE1lido.","errors.IN_USE":"El \xEDtem est\xE1 en uso y no puede ser eliminado.","errors.MAX_LENGTH":"El campo <b>{{field}}</b> no debe exceder los <b>{{length}}</b> caracteres.","errors.MIN_LENGTH":"El campo <b>{{field}}</b> debe tener al menos <b>{{length}}</b> caracteres.","errors.MUST_NOT_BE_EMAIL":"El campo <b>{{field}}</b> no debe ser un correo electr\xF3nico.","errors.NO_PERMISSION":"No tienes permiso para realizar esta acci\xF3n.","errors.NO_SPACES":"El campo <b>{{field}}</b> no debe contener espacios.","errors.ONE_OR_MORE_OPERATIONS_FAILED":"Error en la operaci\xF3n","errors.REQUIRED":"El campo <b>{{field}}</b> es obligatorio.","errors.TOKEN_HAS_EXPIRED":"La sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.","errors.TOO_MANY_REQUESTS":"L\xEDmite de solicitudes alcanzado. Por favor intenta m\xE1s tarde.","errors.UNAUTHORIZED":"No est\xE1s autorizado para realizar esta acci\xF3n.","errors.all_password_fields_required":"Todos los campos de contrase\xF1a son obligatorios","errors.auth.INVALID_API_KEY":"Clave de API inv\xE1lida","errors.auth.INVALID_CREDENTIALS":"Usuario y/o contrase\xF1a incorrectos","errors.auth.NO_PERMISSION":"No tienes permisos suficientes","errors.auth.SESSION_EXPIRED":"Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.","errors.auth.TOO_MANY_REQUESTS":"Demasiados intentos. Por favor espera 15 minutos e intenta nuevamente","errors.auth.UNAUTHORIZED":"No tienes permisos para realizar esta acci\xF3n","errors.auth.USER_NOT_ACTIVE":"Usuario no activo","errors.auth.USER_NOT_FOUND":"Usuario no encontrado","errors.data.BAD_REQUEST":"Solicitud inv\xE1lida","errors.data.FIELD_ERROR":"Error en los datos ingresados","errors.data.IN_USE":"El elemento est\xE1 en uso y no puede ser eliminado","errors.data.ITEM_NOT_FOUND":"El elemento solicitado no fue encontrado","errors.data.NOT_FOUND":"No se encontr\xF3 lo solicitado","errors.internal_error_changing_password":"Error interno al cambiar la contrase\xF1a. Intenta nuevamente","errors.password_min_length":"La contrase\xF1a debe tener al menos 8 caracteres","errors.password_mismatch":"Las contrase\xF1as no coinciden","errors.password_must_be_different":"La nueva contrase\xF1a debe ser diferente a la actual","errors.system.DATABASE_CONNECTION_ERROR":"Error de conexi\xF3n. Verifica tu conexi\xF3n a internet.","errors.system.INTERNAL_SERVER_ERROR":"Error interno del servidor. Intenta nuevamente.","errors.system.INVALID_CONFIGURATION":"Error de configuraci\xF3n del sistema","errors.system.TOO_MANY_REQUESTS":"Demasiadas solicitudes. Por favor espera un momento e intenta nuevamente","errors.system.UNKNOWN_OPERATION":"Operaci\xF3n no reconocida","errors.users_module_not_configured":"M\xF3dulo de usuarios no configurado","footer.copyright":"Nocios S.R.L. Todos los derechos reservados.","footer.version":"Versi\xF3n","forgotPassword.checkEmailInstructions":"Revisa tu bandeja de entrada para el c\xF3digo de verificaci\xF3n","forgotPassword.codeAlreadyExistsMessage":"Ya se envi\xF3 un c\xF3digo y a\xFAn es v\xE1lido","forgotPassword.emailLabel":"Correo Electr\xF3nico","forgotPassword.emailPlaceholder":"Ingresa tu correo electr\xF3nico","forgotPassword.emailRequired":"El correo electr\xF3nico es obligatorio","forgotPassword.emailSentMessage":"C\xF3digo enviado exitosamente","forgotPassword.enterCodeLink":"Ingresar C\xF3digo","forgotPassword.instructions":"Ingresa tu correo electr\xF3nico y te enviaremos un c\xF3digo para restablecer tu contrase\xF1a.","forgotPassword.invalidEmail":"Ingresa un correo electr\xF3nico v\xE1lido","forgotPassword.sendCodeButton":"Enviar C\xF3digo","forgotPassword.title":"Recuperar Contrase\xF1a","loading.app.configInitial":"Cargando configuraci\xF3n inicial...","loading.app.generic":"Cargando...","loading.app.starting":"Iniciando aplicaci\xF3n...","loading.app.themeSetup":"Generando tema...","loading.app.validatingSession":"Validando sesi\xF3n...","login.alreadyHaveCodeLink":"\xBFYa tienes un c\xF3digo?","login.forgotPasswordLink":"\xBFOlvidaste tu contrase\xF1a?","login.initializationError":"Error de inicializaci\xF3n","login.initializing":"Inicializando...","login.loginButton":"Iniciar Sesi\xF3n","login.logoAlt":"Logotipo","login.noAccountPrompt":"\xBFNo tienes una cuenta?","login.notInitialized":"Sistema no inicializado","login.passwordLabel":"Contrase\xF1a","login.passwordPlaceholder":"Ingresa tu contrase\xF1a","login.passwordRequired":"Contrase\xF1a es obligatoria","login.signUpLink":"Reg\xEDstrate","login.usernameOrEmailLabel":"Usuario o Correo Electr\xF3nico","login.usernameOrEmailPlaceholder":"Ingresa tu usuario o correo electr\xF3nico","login.usernameRequired":"Usuario o correo electr\xF3nico es obligatorio","resetPassword.codeExpiredOrInvalid":"El c\xF3digo ha expirado o es inv\xE1lido","resetPassword.confirmPasswordLabel":"Confirmar Contrase\xF1a","resetPassword.confirmPasswordPlaceholder":"Confirma tu nueva contrase\xF1a","resetPassword.confirmPasswordRequired":"Confirma tu contrase\xF1a","resetPassword.goToLoginButton":"Ir al Login","resetPassword.instructions":"Ingresa tu nueva contrase\xF1a.","resetPassword.invalidCode":"El c\xF3digo de verificaci\xF3n es inv\xE1lido. Por favor, verifica el enlace o solicita uno nuevo.","resetPassword.missingParameters":"Faltan par\xE1metros obligatorios","resetPassword.newPasswordLabel":"Nueva Contrase\xF1a","resetPassword.newPasswordPlaceholder":"Ingresa tu nueva contrase\xF1a","resetPassword.newPasswordRequired":"La nueva contrase\xF1a es obligatoria","resetPassword.passwordTooShort":"La contrase\xF1a debe tener al menos 8 caracteres","resetPassword.passwordsDoNotMatch":"Las contrase\xF1as no coinciden","resetPassword.requestNewCodeButton":"Solicitar Nuevo C\xF3digo","resetPassword.resetPasswordButton":"Restablecer Contrase\xF1a","resetPassword.successInstructions":"Ahora puedes iniciar sesi\xF3n con tu nueva contrase\xF1a","resetPassword.successMessage":"Contrase\xF1a restablecida exitosamente","resetPassword.title":"Nueva Contrase\xF1a","resetPassword.validatingCode":"Validando c\xF3digo..."},en:{"checkCode.codeLabel":"Verification Code","checkCode.codePlaceholder":"Enter 6-digit code","checkCode.codeRequired":"Code is required","checkCode.emailLabel":"Email Address","checkCode.emailPlaceholder":"Enter your email address","checkCode.emailRequired":"Email address is required","checkCode.instructions":"Enter the 6-digit code we sent to your email address.","checkCode.invalidEmail":"Enter a valid email address","checkCode.resendCodeLink":"Resend code","checkCode.title":"Verify Code","checkCode.verifyButton":"Verify Code","common.back":"Back","common.backToLogin":"Back to Login","error.app.config":"Configuration Error: {{message}}","error.app.initialization":"Error during final application initialization.","error.transaction":"Operation error","error.unknown":"An unknown error occurred.","errors.DUPLICATE":"The field <b>{{field}}</b> must be unique.","errors.FOREIGN_KEY_NOT_FOUND":"The field <b>{{field}}</b> must reference an existing item.","errors.INVALID_EMAIL":"The field <b>{{field}}</b> must be a valid email address.","errors.INVALID_OBJECT_ID":"The field <b>{{field}}</b> must be a valid value.","errors.IN_USE":"The item is currently in use and cannot be deleted.","errors.MAX_LENGTH":"The field <b>{{field}}</b> must not exceed <b>{{maxLength}}</b> characters.","errors.MIN_LENGTH":"The field <b>{{field}}</b> must have at least <b>{{minLength}}</b> characters.","errors.MUST_NOT_BE_EMAIL":"The field <b>{{field}}</b> must not be an email address.","errors.NO_PERMISSION":"You do not have permission to perform this action.","errors.NO_SPACES":"The field <b>{{field}}</b> must not contain spaces.","errors.ONE_OR_MORE_OPERATIONS_FAILED":"Operation error","errors.REQUIRED":"The field <b>{{field}}</b> is required.","errors.TOKEN_HAS_EXPIRED":"Your session has expired, please log in again.","errors.TOO_MANY_REQUESTS":"Request limit reached. Please try again later.","errors.UNAUTHORIZED":"You are not authorized to perform this action.","errors.all_password_fields_required":"All password fields are required","errors.auth.INVALID_API_KEY":"Invalid API key","errors.auth.INVALID_CREDENTIALS":"Incorrect username and/or password","errors.auth.NO_PERMISSION":"Insufficient permissions","errors.auth.SESSION_EXPIRED":"Your session has expired. Please log in again.","errors.auth.TOO_MANY_REQUESTS":"Too many attempts. Please wait 15 minutes and try again","errors.auth.UNAUTHORIZED":"You don't have permission to perform this action","errors.auth.USER_NOT_ACTIVE":"User account is not active","errors.auth.USER_NOT_FOUND":"User not found","errors.data.BAD_REQUEST":"Invalid request","errors.data.FIELD_ERROR":"Error in the provided data","errors.data.IN_USE":"The item is in use and cannot be deleted","errors.data.ITEM_NOT_FOUND":"The requested item was not found","errors.data.NOT_FOUND":"The requested resource was not found","errors.internal_error_changing_password":"Internal error changing password. Please try again","errors.password_min_length":"Password must be at least 8 characters","errors.password_mismatch":"Passwords do not match","errors.password_must_be_different":"New password must be different from current password","errors.system.DATABASE_CONNECTION_ERROR":"Connection error. Please check your internet connection.","errors.system.INTERNAL_SERVER_ERROR":"Internal server error. Please try again.","errors.system.INVALID_CONFIGURATION":"System configuration error","errors.system.TOO_MANY_REQUESTS":"Too many requests. Please wait a moment and try again","errors.system.UNKNOWN_OPERATION":"Unrecognized operation","errors.users_module_not_configured":"Users module not configured","footer.copyright":"Nocios S.R.L. All Rights Reserved.","footer.version":"Version","forgotPassword.checkEmailInstructions":"Check your inbox for the verification code","forgotPassword.codeAlreadyExistsMessage":"A code was already sent and is still valid","forgotPassword.emailLabel":"Email Address","forgotPassword.emailPlaceholder":"Enter your email address","forgotPassword.emailRequired":"Email address is required","forgotPassword.emailSentMessage":"Code sent successfully","forgotPassword.enterCodeLink":"Enter Code","forgotPassword.instructions":"Enter your email address and we'll send you a code to reset your password.","forgotPassword.invalidEmail":"Enter a valid email address","forgotPassword.sendCodeButton":"Send Code","forgotPassword.title":"Reset Password","loading.app.configInitial":"Loading initial configuration...","loading.app.generic":"Loading...","loading.app.starting":"Starting application...","loading.app.themeSetup":"Generating theme...","loading.app.validatingSession":"Validating session...","login.alreadyHaveCodeLink":"Already have a code?","login.forgotPasswordLink":"Forgot Password?","login.initializationError":"Initialization error","login.initializing":"Initializing...","login.loginButton":"Log In","login.logoAlt":"Logo","login.noAccountPrompt":"Don't have an account?","login.notInitialized":"System not initialized","login.passwordLabel":"Password","login.passwordPlaceholder":"Enter your password","login.passwordRequired":"Password is required","login.signUpLink":"Sign up","login.usernameOrEmailLabel":"Username or Email","login.usernameOrEmailPlaceholder":"Enter your username or email","login.usernameRequired":"Username or email is required","resetPassword.codeExpiredOrInvalid":"Code expired or invalid","resetPassword.confirmPasswordLabel":"Confirm Password","resetPassword.confirmPasswordPlaceholder":"Confirm your new password","resetPassword.confirmPasswordRequired":"Confirm your password","resetPassword.goToLoginButton":"Go to Login","resetPassword.instructions":"Enter your new password.","resetPassword.invalidCode":"The verification code is invalid. Please check the link or request a new one.","resetPassword.missingParameters":"Missing required parameters","resetPassword.newPasswordLabel":"New Password","resetPassword.newPasswordPlaceholder":"Enter your new password","resetPassword.newPasswordRequired":"New password is required","resetPassword.passwordTooShort":"Password must be at least 8 characters","resetPassword.passwordsDoNotMatch":"Passwords do not match","resetPassword.requestNewCodeButton":"Request New Code","resetPassword.resetPasswordButton":"Reset Password","resetPassword.successInstructions":"You can now log in with your new password","resetPassword.successMessage":"Password reset successfully","resetPassword.title":"New Password","resetPassword.validatingCode":"Validating code..."}},Qe= exports.getCriticalLanguages =()=>Object.keys(g),Xe= exports.getCriticalTranslations =o=>g[o]||g.es;var B="crudify_translations_",er=3600*1e3,N= exports.TranslationService =class o{constructor(){this.enableDebug=!1}static getInstance(){return o.instance||(o.instance=new o),o.instance}setDebug(e){this.enableDebug=e}async fetchTranslations(e){let{subscriberKey:r,apiKey:s,sections:t,crudifyEnv:n="stg",urlTranslations:u}=e,a=this.getFromCache(r),d=a?this.isCacheExpired(a):!0;if(a&&!d)return this.enableDebug&&console.log("[TranslationService] Using cached translations"),this.mergeWithUrlTranslations(a.data.translations,u);try{this.enableDebug&&console.log("[TranslationService] Fetching from API via crudify SDK...");let m=await this.fetchFromAPI(t);return this.hasDataChanged(a,m)||!a?(this.enableDebug&&console.log("[TranslationService] Data changed, updating cache"),this.saveToCache(r,m)):(this.enableDebug&&console.log("[TranslationService] Data unchanged, refreshing cache timestamp"),this.refreshCacheTimestamp(r)),this.mergeWithUrlTranslations(m.translations,u)}catch(m){return console.error("[TranslationService] API fetch failed:",m),a?(console.warn("[TranslationService] Using expired cache as fallback"),this.mergeWithUrlTranslations(a.data.translations,u)):(console.warn("[TranslationService] Using critical bundle translations"),this.getCriticalTranslationsOnly())}}async fetchFromAPI(e){let r=await _crudifybrowser2.default.getTranslation(e);if(!r.success)throw new Error(`Crudify API error: ${r.errors?JSON.stringify(r.errors):"Unknown error"}`);if(!r.data)throw new Error("No translation data in response");return r.data}mergeWithUrlTranslations(e,r){if(!r||Object.keys(r).length===0)return e;let s={};return Object.keys(e).forEach(t=>{s[t]={...e[t],...r}}),s}hasDataChanged(e,r){if(!e||e.data.timestamp!==r.timestamp)return!0;let s=this.hashData(r.translations);return e.dataHash!==s}hashData(e){let r=JSON.stringify(e),s=0;for(let t=0;t<r.length;t++){let n=r.charCodeAt(t);s=(s<<5)-s+n,s=s&s}return s.toString(36)}saveToCache(e,r){try{let s=this.getCacheKey(e),t={data:r,cachedAt:Date.now(),dataHash:this.hashData(r.translations)};localStorage.setItem(s,JSON.stringify(t)),this.enableDebug&&console.log("[TranslationService] Saved to cache:",s)}catch(s){console.error("[TranslationService] Failed to save cache:",s)}}getFromCache(e){try{let r=this.getCacheKey(e),s=localStorage.getItem(r);return s?JSON.parse(s):null}catch(r){return console.error("[TranslationService] Failed to read cache:",r),null}}refreshCacheTimestamp(e){try{let r=this.getFromCache(e);if(r){r.cachedAt=Date.now();let s=this.getCacheKey(e);localStorage.setItem(s,JSON.stringify(r))}}catch(r){console.error("[TranslationService] Failed to refresh cache timestamp:",r)}}isCacheExpired(e){return Date.now()-e.cachedAt>er}getCacheKey(e){return`${B}${e}`}getCriticalTranslationsOnly(){return g}invalidateCache(e){let r=this.getCacheKey(e);localStorage.removeItem(r),this.enableDebug&&console.log("[TranslationService] Cache invalidated:",r)}async prefetchTranslations(e){try{await this.fetchTranslations(e),this.enableDebug&&console.log("[TranslationService] Prefetch completed")}catch(r){console.error("[TranslationService] Prefetch failed:",r)}}clearAllCaches(){try{let r=Object.keys(localStorage).filter(s=>s.startsWith(B));r.forEach(s=>localStorage.removeItem(s)),this.enableDebug&&console.log(`[TranslationService] Cleared ${r.length} cache entries`)}catch(e){console.error("[TranslationService] Failed to clear caches:",e)}}},O= exports.translationService =N.getInstance();var G=_react.createContext.call(void 0, null);function H(o,e,r){return{...o,...e,...r||{}}}var ir=({children:o,subscriberKey:e,apiKey:r,crudifyEnv:s="stg",sections:t,language:n="es",devTranslations:u,translationUrl:a,enableDebug:d=!1,skipAutoInit:m=!0})=>{let[p,v]=_react.useState.call(void 0, {}),[C,k]=_react.useState.call(void 0, !0),[$,U]=_react.useState.call(void 0, null),[j,D]=_react.useState.call(void 0, void 0),[M,J]=_react.useState.call(void 0, !1),I=_react.useCallback.call(void 0, async()=>{if(M){d&&console.log("[TranslationsProvider] Skipping reload - using fallback translations");return}k(!0),U(null);let i;if(a)try{d&&console.log(`[TranslationsProvider] Fetching translations from URL: ${a}`);let l=await fetch(a);if(!l.ok)throw new Error(`Failed to fetch translations: ${l.statusText}`);i=await l.json(),D(i),d&&console.log("[TranslationsProvider] URL translations loaded:",{keysCount:i?Object.keys(i).length:0})}catch(l){console.error("[TranslationsProvider] Failed to load URL translations:",l),i=void 0,D(void 0)}try{O.setDebug(d);let l=await O.fetchTranslations({subscriberKey:e,apiKey:r,crudifyEnv:s,sections:t,urlTranslations:i}),h={};Object.keys(l).forEach(c=>{let T=g[c]||{},P=l[c]||{};h[c]=H(T,P,u)}),v(h),d&&console.log("[TranslationsProvider] Loaded translations:",{languages:Object.keys(h),keysCount:Object.keys(h[n]||{}).length})}catch(l){console.error("[TranslationsProvider] Failed to load:",l),U(l.message),J(!0);let h={};Object.keys(g).forEach(c=>{let T=g[c],P=i||j||{};h[c]=H(T,P,u)}),v(h),d&&console.log("[TranslationsProvider] Using fallback translations (critical + URL)")}finally{k(!1)}},[e,r,s,t,a,u,d,n,M]);_react.useEffect.call(void 0, ()=>{I();let i=setInterval(I,3600*1e3);return()=>clearInterval(i)},[I]);let Q={t:_react.useMemo.call(void 0, ()=>(i,l)=>{let c=(p[n]||{})[i];if(!c){let T=Object.keys(p);for(let P of T)if(p[P][i]){c=p[P][i];break}}return c||(d&&console.warn(`[TranslationsProvider] Missing translation: "${i}"`),c=i),l&&typeof c=="string"&&Object.entries(l).forEach(([T,P])=>{let X=new RegExp(`{{${T}}}`,"g");c=c.replace(X,String(P))}),c},[p,n,d]),language:n,availableLanguages:Object.keys(p),translations:p,isLoading:C,error:$,refreshTranslations:I};if(C){let i=_optionalChain([g, 'access', _3 => _3[n], 'optionalAccess', _4 => _4.loading])||"Loading...";return _jsxruntime.jsx.call(void 0, "div",{children:i})}return _jsxruntime.jsx.call(void 0, G.Provider,{value:Q,children:o})},ar= exports.useTranslations =()=>{let o=_react.useContext.call(void 0, G);if(!o)throw new Error("useTranslations must be used within TranslationsProvider");return o};var _crudifyadmin = require('@nocios/crudify-admin'); var _crudifyadmin2 = _interopRequireDefault(_crudifyadmin);var W=!1;function cr(){if(!W){let o=_chunk2DIHMDQBjs.d.getInstance(),e=o.getTokenInfo();console.log("\u{1F50D} crudifyAdminWrapper - tokenInfo:",e);let r=_optionalChain([e, 'optionalAccess', _5 => _5.apiEndpointAdmin]),s=_optionalChain([e, 'optionalAccess', _6 => _6.apiKeyEndpointAdmin]);if(console.log("\u{1F50D} crudifyAdminWrapper - apiUrl:",r),console.log("\u{1F50D} crudifyAdminWrapper - apiKey:",s),r===void 0||s===void 0)throw console.error("\u274C crudifyAdminWrapper - Missing credentials!",{apiUrl:r,apiKey:s,tokenInfo:e}),new Error("crudifyAdmin: API URL or API Key for admin endpoint are not defined.");_optionalChain([e, 'optionalAccess', _7 => _7.apiEndpointAdmin])&&_optionalChain([e, 'optionalAccess', _8 => _8.apiKeyEndpointAdmin])?console.log("\u{1F527} crudifyAdmin: Initializing with dynamic credentials from getPermissions"):console.warn("\u26A0\uFE0F crudifyAdmin: Using fallback credentials (admin credentials not yet loaded from getPermissions)"),_crudifyadmin2.default.init({url:r,apiKey:s,getAdditionalHeaders:()=>{let t=o.getTokenInfo();return _optionalChain([t, 'optionalAccess', _9 => _9.crudifyTokens, 'optionalAccess', _10 => _10.accessToken])?{Authorization:`Bearer ${t.crudifyTokens.accessToken}`}:{}}}),W=!0}}async function R(o){try{cr();let e=await o();return!e.success&&_optionalChain([e, 'access', _11 => _11.errors, 'optionalAccess', _12 => _12.includes, 'call', _13 => _13("401")])?await _chunk2DIHMDQBjs.d.getInstance().refreshTokens()?await o():(console.error("Token refresh failed in crudifyAdmin"),typeof window<"u"&&(window.location.href="/login"),e):e}catch(e){return console.error("Error in crudifyAdmin operation:",e),{success:!1,errors:e instanceof Error?e.message:"Unknown error"}}}var dr={listModules:()=>R(()=>_crudifyadmin2.default.listModules()),getModule:o=>R(()=>_crudifyadmin2.default.getModule(o)),createModule:o=>R(()=>_crudifyadmin2.default.createModule(o)),editModule:(o,e)=>R(()=>_crudifyadmin2.default.editModule(o,e)),deleteModule:o=>R(()=>_crudifyadmin2.default.deleteModule(o)),activateModule:o=>R(()=>_crudifyadmin2.default.activateModule(o)),deactivateModule:o=>R(()=>_crudifyadmin2.default.deactivateModule(o)),getModuleVersions:o=>R(()=>_crudifyadmin2.default.getModuleVersions(o))};exports.AuthRoute = K; exports.CRITICAL_TRANSLATIONS = g; exports.CrudifyLogin = _chunkMC5C4A7Ojs.a; exports.CrudifyThemeProvider = Fe; exports.ERROR_CODES = _chunkYIIUEOXCjs.a; exports.ERROR_SEVERITY_MAP = _chunkYIIUEOXCjs.b; exports.GlobalNotificationProvider = _chunk2DIHMDQBjs.f; exports.LoginComponent = _chunkMC5C4A7Ojs.f; exports.POLICY_ACTIONS = _chunkMC5C4A7Ojs.c; exports.PREFERRED_POLICY_ORDER = _chunkMC5C4A7Ojs.d; exports.Policies = _chunkMC5C4A7Ojs.e; exports.ProtectedRoute = q; exports.SessionDebugInfo = _chunk2DIHMDQBjs.j; exports.SessionLoadingScreen = _; exports.SessionManager = _chunk2DIHMDQBjs.d; exports.SessionProvider = _chunk2DIHMDQBjs.h; exports.SessionStatus = _chunkMC5C4A7Ojs.g; exports.TokenStorage = _chunk2DIHMDQBjs.c; exports.TranslationService = N; exports.TranslationsProvider = ir; exports.UserProfileDisplay = _chunkMC5C4A7Ojs.b; exports.createErrorTranslator = _chunkAT74WV5Wjs.e; exports.crudify = _crudifybrowser2.default; exports.crudifyAdmin = dr; exports.decodeJwtSafely = _chunkAT74WV5Wjs.h; exports.extractSafeRedirectFromUrl = x; exports.getCookie = _chunkAT74WV5Wjs.a; exports.getCriticalLanguages = Qe; exports.getCriticalTranslations = Xe; exports.getCurrentUserEmail = _chunkAT74WV5Wjs.i; exports.getErrorMessage = _chunkYIIUEOXCjs.e; exports.handleCrudifyError = _chunkYIIUEOXCjs.g; exports.isTokenExpired = _chunkAT74WV5Wjs.j; exports.parseApiError = _chunkYIIUEOXCjs.c; exports.parseJavaScriptError = _chunkYIIUEOXCjs.f; exports.parseTransactionError = _chunkYIIUEOXCjs.d; exports.secureLocalStorage = _chunkNNY4A73Vjs.b; exports.secureSessionStorage = _chunkNNY4A73Vjs.a; exports.translateError = _chunkAT74WV5Wjs.d; exports.translateErrorCode = _chunkAT74WV5Wjs.b; exports.translateErrorCodes = _chunkAT74WV5Wjs.c; exports.translationService = O; exports.useAuth = _chunkTWXGR53Jjs.b; exports.useCrudifyWithNotifications = _chunkTWXGR53Jjs.d; exports.useData = _chunkTWXGR53Jjs.c; exports.useGlobalNotification = _chunk2DIHMDQBjs.g; exports.useSession = _chunk2DIHMDQBjs.e; exports.useSessionContext = _chunk2DIHMDQBjs.i; exports.useTranslations = ar; exports.useUserData = _chunkTWXGR53Jjs.a; exports.useUserProfile = _chunk2DIHMDQBjs.k; exports.validateInternalRedirect = A;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{a as Te,b as ye,c as ve,d as Ce,e as Ie,f as we,g as Se}from"./chunk-
|
|
1
|
+
import{a as Te,b as ye,c as ve,d as Ce,e as Ie,f as we,g as Se}from"./chunk-TRM4AJLI.mjs";import{a as Ae,b as be,c as Ne,d as _e}from"./chunk-L2T6DEVZ.mjs";import{c as Z,d as w,e as te,f as ce,g as de,h as le,i as E,j as ue,k as Ee}from"./chunk-YV42XUB6.mjs";import{a as Oe,b as Le}from"./chunk-T2CPA46I.mjs";import{a as ge,b as pe,c as fe,d as me,e as he,f as Pe,g as Re}from"./chunk-BJ6PIVZR.mjs";import{a as L,b as ee,c as re,d as oe,e as se,h as ne,i as ie,j as ae}from"./chunk-5JKS55SE.mjs";import{default as Qr}from"@nocios/crudify-browser";export*from"@nocios/crudify-browser";import{useMemo as xe}from"react";import{ThemeProvider as ke,createTheme as Ue,CssBaseline as De}from"@mui/material";import{jsx as Ve,jsxs as qe}from"react/jsx-runtime";var Me=(o={})=>{try{let e=L("theme");if(e){let r=JSON.parse(decodeURIComponent(e));return{...o,...r}}}catch(e){console.warn("Error parsing theme from cookie:",e)}return o};function Fe({children:o,defaultTheme:e={},disableCssBaseline:r=!1}){let s=xe(()=>{let t=Me(e);return Ue(t)},[e]);return qe(ke,{theme:s,children:[!r&&Ve(De,{}),o]})}import{Navigate as Ge,useLocation as We}from"react-router-dom";import{Fragment as Be,jsx as S,jsxs as F}from"react/jsx-runtime";var ze={border:"5px solid rgba(0, 0, 0, 0.1)",borderTopColor:"#3B82F6",borderRadius:"50%",width:"50px",height:"50px",animation:"spin 1s linear infinite"},Ke=()=>S("style",{children:`
|
|
2
2
|
@keyframes spin {
|
|
3
3
|
0% { transform: rotate(0deg); }
|
|
4
4
|
100% { transform: rotate(360deg); }
|
|
5
5
|
}
|
|
6
|
-
`});function _({stage:o="loading",message:e}){let s=e||{initializing:"Initializing application...","validating-session":"Validating session...",loading:"Loading..."}[o];return F(Be,{children:[S(Ke,{}),F("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100vh",width:"100vw",backgroundColor:"#f0f2f5",fontFamily:'"Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',color:"#333",textAlign:"center",boxSizing:"border-box",padding:"20px",background:"#fff"},children:[S("div",{style:ze}),S("p",{style:{fontSize:"1.25em",fontWeight:"500",marginTop:"24px",color:"#1f2937"},children:s})]})]})}var He=/^[a-zA-Z0-9\-_./\?=&%#]+$/,Ye=[/^https?:\/\//i,/^ftp:\/\//i,/^\/\//,/javascript:/i,/data:/i,/vbscript:/i,/about:/i,/\.\.\//,/\.\.\\/,/%2e%2e%2f/i,/%2e%2e%5c/i,/%2f%2f/i,/%5c%5c/i,/[\x00-\x1f\x7f-\x9f]/,/\\/],b=(o,e="/")=>{if(!o||typeof o!="string")return e;let r=o.trim();if(!r)return e;if(!r.startsWith("/"))return console.warn("\u{1F6A8} Open redirect blocked (relative path):",o),e;if(!He.test(r))return console.warn("\u{1F6A8} Open redirect blocked (invalid characters):",o),e;let s=r.toLowerCase();for(let n of Ye)if(n.test(s))return console.warn("\u{1F6A8} Open redirect blocked (dangerous pattern):",o),e;let t=r.split("?")[0].split("/").filter(Boolean);if(t.length===0)return r;for(let n of t)if(n===".."||n.includes(":")||n.length>100)return console.warn("\u{1F6A8} Open redirect blocked (suspicious path part):",n),e;return r},x=(o,e="/")=>{try{let s=(typeof o=="string"?new URLSearchParams(o):o).get("redirect");if(!s)return e;let t=decodeURIComponent(s);return b(t,e)}catch(r){return console.warn("\u{1F6A8} Error parsing redirect parameter:",r),e}};import{Fragment as V,jsx as A}from"react/jsx-runtime";function q({children:o,loadingComponent:e,loginPath:r="/login"}){let{isAuthenticated:s,isLoading:t,isInitialized:n,tokens:u,error:a}=E(),d=We();if(!n||t)return A(V,{children:e||A(_,{stage:"validating-session"})});let m=s&&u?.accessToken&&u.accessToken.length>0;if(a||!s||!m){u&&(!u.accessToken||u.accessToken.length===0)&&localStorage.removeItem("crudify_tokens");let p=d.pathname+d.search,v=b(p),C=encodeURIComponent(v);return A(Ge,{to:`${r}?redirect=${C}`,replace:!0})}return A(V,{children:o})}import{Navigate as $e,useLocation as je}from"react-router-dom";import{Fragment as Je,jsx as z}from"react/jsx-runtime";function K({children:o,redirectTo:e="/"}){let{isAuthenticated:r}=E(),s=je();if(r){let t=new URLSearchParams(s.search),n=x(t,e);return z($e,{to:n,replace:!0})}return z(Je,{children:o})}import{createContext as rr,useContext as or,useEffect as sr,useState as y,useMemo as tr,useCallback as nr}from"react";import Ze from"@nocios/crudify-browser";var g={es:{"checkCode.codeLabel":"C\xF3digo de Verificaci\xF3n","checkCode.codePlaceholder":"Ingresa el c\xF3digo de 6 d\xEDgitos","checkCode.codeRequired":"El c\xF3digo es obligatorio","checkCode.emailLabel":"Correo Electr\xF3nico","checkCode.emailPlaceholder":"Ingresa tu correo electr\xF3nico","checkCode.emailRequired":"El correo electr\xF3nico es obligatorio","checkCode.instructions":"Ingresa el c\xF3digo de 6 d\xEDgitos que enviamos a tu correo electr\xF3nico.","checkCode.invalidEmail":"Ingresa un correo electr\xF3nico v\xE1lido","checkCode.resendCodeLink":"Reenviar c\xF3digo","checkCode.title":"Verificar C\xF3digo","checkCode.verifyButton":"Verificar C\xF3digo","common.back":"Volver","common.backToLogin":"Volver","error.app.config":"Error de Configuraci\xF3n: {{message}}","error.app.initialization":"Error durante la inicializaci\xF3n final de la aplicaci\xF3n.","error.transaction":"Error en la operaci\xF3n","error.unknown":"Ocurri\xF3 un error desconocido.","errors.DUPLICATE":"El campo <b>{{field}}</b> debe ser \xFAnico.","errors.FOREIGN_KEY_NOT_FOUND":"El campo <b>{{field}}</b> debe referenciar un \xEDtem existente.","errors.INVALID_EMAIL":"El campo <b>{{field}}</b> debe ser un correo electr\xF3nico v\xE1lido.","errors.INVALID_OBJECT_ID":"El campo <b>{{field}}</b> debe ser un valor v\xE1lido.","errors.IN_USE":"El \xEDtem est\xE1 en uso y no puede ser eliminado.","errors.MAX_LENGTH":"El campo <b>{{field}}</b> no debe exceder los <b>{{length}}</b> caracteres.","errors.MIN_LENGTH":"El campo <b>{{field}}</b> debe tener al menos <b>{{length}}</b> caracteres.","errors.MUST_NOT_BE_EMAIL":"El campo <b>{{field}}</b> no debe ser un correo electr\xF3nico.","errors.NO_PERMISSION":"No tienes permiso para realizar esta acci\xF3n.","errors.NO_SPACES":"El campo <b>{{field}}</b> no debe contener espacios.","errors.ONE_OR_MORE_OPERATIONS_FAILED":"Error en la operaci\xF3n","errors.REQUIRED":"El campo <b>{{field}}</b> es obligatorio.","errors.TOKEN_HAS_EXPIRED":"La sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.","errors.TOO_MANY_REQUESTS":"L\xEDmite de solicitudes alcanzado. Por favor intenta m\xE1s tarde.","errors.UNAUTHORIZED":"No est\xE1s autorizado para realizar esta acci\xF3n.","errors.all_password_fields_required":"Todos los campos de contrase\xF1a son obligatorios","errors.auth.INVALID_API_KEY":"Clave de API inv\xE1lida","errors.auth.INVALID_CREDENTIALS":"Usuario y/o contrase\xF1a incorrectos","errors.auth.NO_PERMISSION":"No tienes permisos suficientes","errors.auth.SESSION_EXPIRED":"Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.","errors.auth.TOO_MANY_REQUESTS":"Demasiados intentos. Por favor espera 15 minutos e intenta nuevamente","errors.auth.UNAUTHORIZED":"No tienes permisos para realizar esta acci\xF3n","errors.auth.USER_NOT_ACTIVE":"Usuario no activo","errors.auth.USER_NOT_FOUND":"Usuario no encontrado","errors.data.BAD_REQUEST":"Solicitud inv\xE1lida","errors.data.FIELD_ERROR":"Error en los datos ingresados","errors.data.IN_USE":"El elemento est\xE1 en uso y no puede ser eliminado","errors.data.ITEM_NOT_FOUND":"El elemento solicitado no fue encontrado","errors.data.NOT_FOUND":"No se encontr\xF3 lo solicitado","errors.internal_error_changing_password":"Error interno al cambiar la contrase\xF1a. Intenta nuevamente","errors.password_min_length":"La contrase\xF1a debe tener al menos 8 caracteres","errors.password_mismatch":"Las contrase\xF1as no coinciden","errors.password_must_be_different":"La nueva contrase\xF1a debe ser diferente a la actual","errors.system.DATABASE_CONNECTION_ERROR":"Error de conexi\xF3n. Verifica tu conexi\xF3n a internet.","errors.system.INTERNAL_SERVER_ERROR":"Error interno del servidor. Intenta nuevamente.","errors.system.INVALID_CONFIGURATION":"Error de configuraci\xF3n del sistema","errors.system.TOO_MANY_REQUESTS":"Demasiadas solicitudes. Por favor espera un momento e intenta nuevamente","errors.system.UNKNOWN_OPERATION":"Operaci\xF3n no reconocida","errors.users_module_not_configured":"M\xF3dulo de usuarios no configurado","footer.copyright":"Nocios S.R.L. Todos los derechos reservados.","footer.version":"Versi\xF3n","forgotPassword.checkEmailInstructions":"Revisa tu bandeja de entrada para el c\xF3digo de verificaci\xF3n","forgotPassword.codeAlreadyExistsMessage":"Ya se envi\xF3 un c\xF3digo y a\xFAn es v\xE1lido","forgotPassword.emailLabel":"Correo Electr\xF3nico","forgotPassword.emailPlaceholder":"Ingresa tu correo electr\xF3nico","forgotPassword.emailRequired":"El correo electr\xF3nico es obligatorio","forgotPassword.emailSentMessage":"C\xF3digo enviado exitosamente","forgotPassword.enterCodeLink":"Ingresar C\xF3digo","forgotPassword.instructions":"Ingresa tu correo electr\xF3nico y te enviaremos un c\xF3digo para restablecer tu contrase\xF1a.","forgotPassword.invalidEmail":"Ingresa un correo electr\xF3nico v\xE1lido","forgotPassword.sendCodeButton":"Enviar C\xF3digo","forgotPassword.title":"Recuperar Contrase\xF1a","loading.app.configInitial":"Cargando configuraci\xF3n inicial...","loading.app.generic":"Cargando...","loading.app.starting":"Iniciando aplicaci\xF3n...","loading.app.themeSetup":"Generando tema...","loading.app.validatingSession":"Validando sesi\xF3n...","login.alreadyHaveCodeLink":"\xBFYa tienes un c\xF3digo?","login.forgotPasswordLink":"\xBFOlvidaste tu contrase\xF1a?","login.initializationError":"Error de inicializaci\xF3n","login.initializing":"Inicializando...","login.loginButton":"Iniciar Sesi\xF3n","login.logoAlt":"Logotipo","login.noAccountPrompt":"\xBFNo tienes una cuenta?","login.notInitialized":"Sistema no inicializado","login.passwordLabel":"Contrase\xF1a","login.passwordPlaceholder":"Ingresa tu contrase\xF1a","login.passwordRequired":"Contrase\xF1a es obligatoria","login.signUpLink":"Reg\xEDstrate","login.usernameOrEmailLabel":"Usuario o Correo Electr\xF3nico","login.usernameOrEmailPlaceholder":"Ingresa tu usuario o correo electr\xF3nico","login.usernameRequired":"Usuario o correo electr\xF3nico es obligatorio","resetPassword.codeExpiredOrInvalid":"El c\xF3digo ha expirado o es inv\xE1lido","resetPassword.confirmPasswordLabel":"Confirmar Contrase\xF1a","resetPassword.confirmPasswordPlaceholder":"Confirma tu nueva contrase\xF1a","resetPassword.confirmPasswordRequired":"Confirma tu contrase\xF1a","resetPassword.goToLoginButton":"Ir al Login","resetPassword.instructions":"Ingresa tu nueva contrase\xF1a.","resetPassword.invalidCode":"El c\xF3digo de verificaci\xF3n es inv\xE1lido. Por favor, verifica el enlace o solicita uno nuevo.","resetPassword.missingParameters":"Faltan par\xE1metros obligatorios","resetPassword.newPasswordLabel":"Nueva Contrase\xF1a","resetPassword.newPasswordPlaceholder":"Ingresa tu nueva contrase\xF1a","resetPassword.newPasswordRequired":"La nueva contrase\xF1a es obligatoria","resetPassword.passwordTooShort":"La contrase\xF1a debe tener al menos 8 caracteres","resetPassword.passwordsDoNotMatch":"Las contrase\xF1as no coinciden","resetPassword.requestNewCodeButton":"Solicitar Nuevo C\xF3digo","resetPassword.resetPasswordButton":"Restablecer Contrase\xF1a","resetPassword.successInstructions":"Ahora puedes iniciar sesi\xF3n con tu nueva contrase\xF1a","resetPassword.successMessage":"Contrase\xF1a restablecida exitosamente","resetPassword.title":"Nueva Contrase\xF1a","resetPassword.validatingCode":"Validando c\xF3digo..."},en:{"checkCode.codeLabel":"Verification Code","checkCode.codePlaceholder":"Enter 6-digit code","checkCode.codeRequired":"Code is required","checkCode.emailLabel":"Email Address","checkCode.emailPlaceholder":"Enter your email address","checkCode.emailRequired":"Email address is required","checkCode.instructions":"Enter the 6-digit code we sent to your email address.","checkCode.invalidEmail":"Enter a valid email address","checkCode.resendCodeLink":"Resend code","checkCode.title":"Verify Code","checkCode.verifyButton":"Verify Code","common.back":"Back","common.backToLogin":"Back to Login","error.app.config":"Configuration Error: {{message}}","error.app.initialization":"Error during final application initialization.","error.transaction":"Operation error","error.unknown":"An unknown error occurred.","errors.DUPLICATE":"The field <b>{{field}}</b> must be unique.","errors.FOREIGN_KEY_NOT_FOUND":"The field <b>{{field}}</b> must reference an existing item.","errors.INVALID_EMAIL":"The field <b>{{field}}</b> must be a valid email address.","errors.INVALID_OBJECT_ID":"The field <b>{{field}}</b> must be a valid value.","errors.IN_USE":"The item is currently in use and cannot be deleted.","errors.MAX_LENGTH":"The field <b>{{field}}</b> must not exceed <b>{{maxLength}}</b> characters.","errors.MIN_LENGTH":"The field <b>{{field}}</b> must have at least <b>{{minLength}}</b> characters.","errors.MUST_NOT_BE_EMAIL":"The field <b>{{field}}</b> must not be an email address.","errors.NO_PERMISSION":"You do not have permission to perform this action.","errors.NO_SPACES":"The field <b>{{field}}</b> must not contain spaces.","errors.ONE_OR_MORE_OPERATIONS_FAILED":"Operation error","errors.REQUIRED":"The field <b>{{field}}</b> is required.","errors.TOKEN_HAS_EXPIRED":"Your session has expired, please log in again.","errors.TOO_MANY_REQUESTS":"Request limit reached. Please try again later.","errors.UNAUTHORIZED":"You are not authorized to perform this action.","errors.all_password_fields_required":"All password fields are required","errors.auth.INVALID_API_KEY":"Invalid API key","errors.auth.INVALID_CREDENTIALS":"Incorrect username and/or password","errors.auth.NO_PERMISSION":"Insufficient permissions","errors.auth.SESSION_EXPIRED":"Your session has expired. Please log in again.","errors.auth.TOO_MANY_REQUESTS":"Too many attempts. Please wait 15 minutes and try again","errors.auth.UNAUTHORIZED":"You don't have permission to perform this action","errors.auth.USER_NOT_ACTIVE":"User account is not active","errors.auth.USER_NOT_FOUND":"User not found","errors.data.BAD_REQUEST":"Invalid request","errors.data.FIELD_ERROR":"Error in the provided data","errors.data.IN_USE":"The item is in use and cannot be deleted","errors.data.ITEM_NOT_FOUND":"The requested item was not found","errors.data.NOT_FOUND":"The requested resource was not found","errors.internal_error_changing_password":"Internal error changing password. Please try again","errors.password_min_length":"Password must be at least 8 characters","errors.password_mismatch":"Passwords do not match","errors.password_must_be_different":"New password must be different from current password","errors.system.DATABASE_CONNECTION_ERROR":"Connection error. Please check your internet connection.","errors.system.INTERNAL_SERVER_ERROR":"Internal server error. Please try again.","errors.system.INVALID_CONFIGURATION":"System configuration error","errors.system.TOO_MANY_REQUESTS":"Too many requests. Please wait a moment and try again","errors.system.UNKNOWN_OPERATION":"Unrecognized operation","errors.users_module_not_configured":"Users module not configured","footer.copyright":"Nocios S.R.L. All Rights Reserved.","footer.version":"Version","forgotPassword.checkEmailInstructions":"Check your inbox for the verification code","forgotPassword.codeAlreadyExistsMessage":"A code was already sent and is still valid","forgotPassword.emailLabel":"Email Address","forgotPassword.emailPlaceholder":"Enter your email address","forgotPassword.emailRequired":"Email address is required","forgotPassword.emailSentMessage":"Code sent successfully","forgotPassword.enterCodeLink":"Enter Code","forgotPassword.instructions":"Enter your email address and we'll send you a code to reset your password.","forgotPassword.invalidEmail":"Enter a valid email address","forgotPassword.sendCodeButton":"Send Code","forgotPassword.title":"Reset Password","loading.app.configInitial":"Loading initial configuration...","loading.app.generic":"Loading...","loading.app.starting":"Starting application...","loading.app.themeSetup":"Generating theme...","loading.app.validatingSession":"Validating session...","login.alreadyHaveCodeLink":"Already have a code?","login.forgotPasswordLink":"Forgot Password?","login.initializationError":"Initialization error","login.initializing":"Initializing...","login.loginButton":"Log In","login.logoAlt":"Logo","login.noAccountPrompt":"Don't have an account?","login.notInitialized":"System not initialized","login.passwordLabel":"Password","login.passwordPlaceholder":"Enter your password","login.passwordRequired":"Password is required","login.signUpLink":"Sign up","login.usernameOrEmailLabel":"Username or Email","login.usernameOrEmailPlaceholder":"Enter your username or email","login.usernameRequired":"Username or email is required","resetPassword.codeExpiredOrInvalid":"Code expired or invalid","resetPassword.confirmPasswordLabel":"Confirm Password","resetPassword.confirmPasswordPlaceholder":"Confirm your new password","resetPassword.confirmPasswordRequired":"Confirm your password","resetPassword.goToLoginButton":"Go to Login","resetPassword.instructions":"Enter your new password.","resetPassword.invalidCode":"The verification code is invalid. Please check the link or request a new one.","resetPassword.missingParameters":"Missing required parameters","resetPassword.newPasswordLabel":"New Password","resetPassword.newPasswordPlaceholder":"Enter your new password","resetPassword.newPasswordRequired":"New password is required","resetPassword.passwordTooShort":"Password must be at least 8 characters","resetPassword.passwordsDoNotMatch":"Passwords do not match","resetPassword.requestNewCodeButton":"Request New Code","resetPassword.resetPasswordButton":"Reset Password","resetPassword.successInstructions":"You can now log in with your new password","resetPassword.successMessage":"Password reset successfully","resetPassword.title":"New Password","resetPassword.validatingCode":"Validating code..."}},Qe=()=>Object.keys(g),Xe=o=>g[o]||g.es;var B="crudify_translations_",er=3600*1e3,N=class o{constructor(){this.enableDebug=!1}static getInstance(){return o.instance||(o.instance=new o),o.instance}setDebug(e){this.enableDebug=e}async fetchTranslations(e){let{subscriberKey:r,apiKey:s,sections:t,crudifyEnv:n="stg",urlTranslations:u}=e,a=this.getFromCache(r),d=a?this.isCacheExpired(a):!0;if(a&&!d)return this.enableDebug&&console.log("[TranslationService] Using cached translations"),this.mergeWithUrlTranslations(a.data.translations,u);try{this.enableDebug&&console.log("[TranslationService] Fetching from API via crudify SDK...");let m=await this.fetchFromAPI(t);return this.hasDataChanged(a,m)||!a?(this.enableDebug&&console.log("[TranslationService] Data changed, updating cache"),this.saveToCache(r,m)):(this.enableDebug&&console.log("[TranslationService] Data unchanged, refreshing cache timestamp"),this.refreshCacheTimestamp(r)),this.mergeWithUrlTranslations(m.translations,u)}catch(m){return console.error("[TranslationService] API fetch failed:",m),a?(console.warn("[TranslationService] Using expired cache as fallback"),this.mergeWithUrlTranslations(a.data.translations,u)):(console.warn("[TranslationService] Using critical bundle translations"),this.getCriticalTranslationsOnly())}}async fetchFromAPI(e){let r=await Ze.getTranslation(e);if(!r.success)throw new Error(`Crudify API error: ${r.errors?JSON.stringify(r.errors):"Unknown error"}`);if(!r.data)throw new Error("No translation data in response");return r.data}mergeWithUrlTranslations(e,r){if(!r||Object.keys(r).length===0)return e;let s={};return Object.keys(e).forEach(t=>{s[t]={...e[t],...r}}),s}hasDataChanged(e,r){if(!e||e.data.timestamp!==r.timestamp)return!0;let s=this.hashData(r.translations);return e.dataHash!==s}hashData(e){let r=JSON.stringify(e),s=0;for(let t=0;t<r.length;t++){let n=r.charCodeAt(t);s=(s<<5)-s+n,s=s&s}return s.toString(36)}saveToCache(e,r){try{let s=this.getCacheKey(e),t={data:r,cachedAt:Date.now(),dataHash:this.hashData(r.translations)};localStorage.setItem(s,JSON.stringify(t)),this.enableDebug&&console.log("[TranslationService] Saved to cache:",s)}catch(s){console.error("[TranslationService] Failed to save cache:",s)}}getFromCache(e){try{let r=this.getCacheKey(e),s=localStorage.getItem(r);return s?JSON.parse(s):null}catch(r){return console.error("[TranslationService] Failed to read cache:",r),null}}refreshCacheTimestamp(e){try{let r=this.getFromCache(e);if(r){r.cachedAt=Date.now();let s=this.getCacheKey(e);localStorage.setItem(s,JSON.stringify(r))}}catch(r){console.error("[TranslationService] Failed to refresh cache timestamp:",r)}}isCacheExpired(e){return Date.now()-e.cachedAt>er}getCacheKey(e){return`${B}${e}`}getCriticalTranslationsOnly(){return g}invalidateCache(e){let r=this.getCacheKey(e);localStorage.removeItem(r),this.enableDebug&&console.log("[TranslationService] Cache invalidated:",r)}async prefetchTranslations(e){try{await this.fetchTranslations(e),this.enableDebug&&console.log("[TranslationService] Prefetch completed")}catch(r){console.error("[TranslationService] Prefetch failed:",r)}}clearAllCaches(){try{let r=Object.keys(localStorage).filter(s=>s.startsWith(B));r.forEach(s=>localStorage.removeItem(s)),this.enableDebug&&console.log(`[TranslationService] Cleared ${r.length} cache entries`)}catch(e){console.error("[TranslationService] Failed to clear caches:",e)}}},O=N.getInstance();import{jsx as Y}from"react/jsx-runtime";var G=rr(null);function H(o,e,r){return{...o,...e,...r||{}}}var ir=({children:o,subscriberKey:e,apiKey:r,crudifyEnv:s="stg",sections:t,language:n="es",devTranslations:u,translationUrl:a,enableDebug:d=!1,skipAutoInit:m=!0})=>{let[p,v]=y({}),[C,k]=y(!0),[$,U]=y(null),[j,D]=y(void 0),[M,J]=y(!1),I=nr(async()=>{if(M){d&&console.log("[TranslationsProvider] Skipping reload - using fallback translations");return}k(!0),U(null);let i;if(a)try{d&&console.log(`[TranslationsProvider] Fetching translations from URL: ${a}`);let l=await fetch(a);if(!l.ok)throw new Error(`Failed to fetch translations: ${l.statusText}`);i=await l.json(),D(i),d&&console.log("[TranslationsProvider] URL translations loaded:",{keysCount:i?Object.keys(i).length:0})}catch(l){console.error("[TranslationsProvider] Failed to load URL translations:",l),i=void 0,D(void 0)}try{O.setDebug(d);let l=await O.fetchTranslations({subscriberKey:e,apiKey:r,crudifyEnv:s,sections:t,urlTranslations:i}),h={};Object.keys(l).forEach(c=>{let T=g[c]||{},P=l[c]||{};h[c]=H(T,P,u)}),v(h),d&&console.log("[TranslationsProvider] Loaded translations:",{languages:Object.keys(h),keysCount:Object.keys(h[n]||{}).length})}catch(l){console.error("[TranslationsProvider] Failed to load:",l),U(l.message),J(!0);let h={};Object.keys(g).forEach(c=>{let T=g[c],P=i||j||{};h[c]=H(T,P,u)}),v(h),d&&console.log("[TranslationsProvider] Using fallback translations (critical + URL)")}finally{k(!1)}},[e,r,s,t,a,u,d,n,M]);sr(()=>{I();let i=setInterval(I,3600*1e3);return()=>clearInterval(i)},[I]);let Q={t:tr(()=>(i,l)=>{let c=(p[n]||{})[i];if(!c){let T=Object.keys(p);for(let P of T)if(p[P][i]){c=p[P][i];break}}return c||(d&&console.warn(`[TranslationsProvider] Missing translation: "${i}"`),c=i),l&&typeof c=="string"&&Object.entries(l).forEach(([T,P])=>{let X=new RegExp(`{{${T}}}`,"g");c=c.replace(X,String(P))}),c},[p,n,d]),language:n,availableLanguages:Object.keys(p),translations:p,isLoading:C,error:$,refreshTranslations:I};if(C){let i=g[n]?.loading||"Loading...";return Y("div",{children:i})}return Y(G.Provider,{value:Q,children:o})},ar=()=>{let o=or(G);if(!o)throw new Error("useTranslations must be used within TranslationsProvider");return o};import f from"@nocios/crudify-admin";var W=!1;function cr(){if(!W){let o=w.getInstance(),e=o.getTokenInfo(),r=e?.apiEndpointAdmin,s=e?.apiKeyEndpointAdmin;if(r===void 0||s===void 0)throw new Error("crudifyAdmin: API URL or API Key for admin endpoint are not defined.");e?.apiEndpointAdmin&&e?.apiKeyEndpointAdmin?console.log("\u{1F527} crudifyAdmin: Initializing with dynamic credentials from getPermissions"):console.warn("\u26A0\uFE0F crudifyAdmin: Using fallback credentials (admin credentials not yet loaded from getPermissions)"),f.init({url:r,apiKey:s,getAdditionalHeaders:()=>{let t=o.getTokenInfo();return t?.crudifyTokens?.accessToken?{Authorization:`Bearer ${t.crudifyTokens.accessToken}`}:{}}}),W=!0}}async function R(o){try{cr();let e=await o();return!e.success&&e.errors?.includes("401")?await w.getInstance().refreshTokens()?await o():(console.error("Token refresh failed in crudifyAdmin"),typeof window<"u"&&(window.location.href="/login"),e):e}catch(e){return console.error("Error in crudifyAdmin operation:",e),{success:!1,errors:e instanceof Error?e.message:"Unknown error"}}}var dr={listModules:()=>R(()=>f.listModules()),getModule:o=>R(()=>f.getModule(o)),createModule:o=>R(()=>f.createModule(o)),editModule:(o,e)=>R(()=>f.editModule(o,e)),deleteModule:o=>R(()=>f.deleteModule(o)),activateModule:o=>R(()=>f.activateModule(o)),deactivateModule:o=>R(()=>f.deactivateModule(o)),getModuleVersions:o=>R(()=>f.getModuleVersions(o))};export{K as AuthRoute,g as CRITICAL_TRANSLATIONS,Te as CrudifyLogin,Fe as CrudifyThemeProvider,ge as ERROR_CODES,pe as ERROR_SEVERITY_MAP,ce as GlobalNotificationProvider,we as LoginComponent,ve as POLICY_ACTIONS,Ce as PREFERRED_POLICY_ORDER,Ie as Policies,q as ProtectedRoute,ue as SessionDebugInfo,_ as SessionLoadingScreen,w as SessionManager,le as SessionProvider,Se as SessionStatus,Z as TokenStorage,N as TranslationService,ir as TranslationsProvider,ye as UserProfileDisplay,se as createErrorTranslator,Qr as crudify,dr as crudifyAdmin,ne as decodeJwtSafely,x as extractSafeRedirectFromUrl,L as getCookie,Qe as getCriticalLanguages,Xe as getCriticalTranslations,ie as getCurrentUserEmail,he as getErrorMessage,Re as handleCrudifyError,ae as isTokenExpired,fe as parseApiError,Pe as parseJavaScriptError,me as parseTransactionError,Le as secureLocalStorage,Oe as secureSessionStorage,oe as translateError,ee as translateErrorCode,re as translateErrorCodes,O as translationService,Ae as useAuth,_e as useCrudifyWithNotifications,Ne as useData,de as useGlobalNotification,te as useSession,E as useSessionContext,ar as useTranslations,be as useUserData,Ee as useUserProfile,b as validateInternalRedirect};
|
|
6
|
+
`});function _({stage:o="loading",message:e}){let s=e||{initializing:"Initializing application...","validating-session":"Validating session...",loading:"Loading..."}[o];return F(Be,{children:[S(Ke,{}),F("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100vh",width:"100vw",backgroundColor:"#f0f2f5",fontFamily:'"Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',color:"#333",textAlign:"center",boxSizing:"border-box",padding:"20px",background:"#fff"},children:[S("div",{style:ze}),S("p",{style:{fontSize:"1.25em",fontWeight:"500",marginTop:"24px",color:"#1f2937"},children:s})]})]})}var He=/^[a-zA-Z0-9\-_./\?=&%#]+$/,Ye=[/^https?:\/\//i,/^ftp:\/\//i,/^\/\//,/javascript:/i,/data:/i,/vbscript:/i,/about:/i,/\.\.\//,/\.\.\\/,/%2e%2e%2f/i,/%2e%2e%5c/i,/%2f%2f/i,/%5c%5c/i,/[\x00-\x1f\x7f-\x9f]/,/\\/],A=(o,e="/")=>{if(!o||typeof o!="string")return e;let r=o.trim();if(!r)return e;if(!r.startsWith("/"))return console.warn("\u{1F6A8} Open redirect blocked (relative path):",o),e;if(!He.test(r))return console.warn("\u{1F6A8} Open redirect blocked (invalid characters):",o),e;let s=r.toLowerCase();for(let n of Ye)if(n.test(s))return console.warn("\u{1F6A8} Open redirect blocked (dangerous pattern):",o),e;let t=r.split("?")[0].split("/").filter(Boolean);if(t.length===0)return r;for(let n of t)if(n===".."||n.includes(":")||n.length>100)return console.warn("\u{1F6A8} Open redirect blocked (suspicious path part):",n),e;return r},x=(o,e="/")=>{try{let s=(typeof o=="string"?new URLSearchParams(o):o).get("redirect");if(!s)return e;let t=decodeURIComponent(s);return A(t,e)}catch(r){return console.warn("\u{1F6A8} Error parsing redirect parameter:",r),e}};import{Fragment as V,jsx as b}from"react/jsx-runtime";function q({children:o,loadingComponent:e,loginPath:r="/login"}){let{isAuthenticated:s,isLoading:t,isInitialized:n,tokens:u,error:a}=E(),d=We();if(!n||t)return b(V,{children:e||b(_,{stage:"validating-session"})});let m=s&&u?.accessToken&&u.accessToken.length>0;if(a||!s||!m){u&&(!u.accessToken||u.accessToken.length===0)&&localStorage.removeItem("crudify_tokens");let p=d.pathname+d.search,v=A(p),C=encodeURIComponent(v);return b(Ge,{to:`${r}?redirect=${C}`,replace:!0})}return b(V,{children:o})}import{Navigate as $e,useLocation as je}from"react-router-dom";import{Fragment as Je,jsx as z}from"react/jsx-runtime";function K({children:o,redirectTo:e="/"}){let{isAuthenticated:r}=E(),s=je();if(r){let t=new URLSearchParams(s.search),n=x(t,e);return z($e,{to:n,replace:!0})}return z(Je,{children:o})}import{createContext as rr,useContext as or,useEffect as sr,useState as y,useMemo as tr,useCallback as nr}from"react";import Ze from"@nocios/crudify-browser";var g={es:{"checkCode.codeLabel":"C\xF3digo de Verificaci\xF3n","checkCode.codePlaceholder":"Ingresa el c\xF3digo de 6 d\xEDgitos","checkCode.codeRequired":"El c\xF3digo es obligatorio","checkCode.emailLabel":"Correo Electr\xF3nico","checkCode.emailPlaceholder":"Ingresa tu correo electr\xF3nico","checkCode.emailRequired":"El correo electr\xF3nico es obligatorio","checkCode.instructions":"Ingresa el c\xF3digo de 6 d\xEDgitos que enviamos a tu correo electr\xF3nico.","checkCode.invalidEmail":"Ingresa un correo electr\xF3nico v\xE1lido","checkCode.resendCodeLink":"Reenviar c\xF3digo","checkCode.title":"Verificar C\xF3digo","checkCode.verifyButton":"Verificar C\xF3digo","common.back":"Volver","common.backToLogin":"Volver","error.app.config":"Error de Configuraci\xF3n: {{message}}","error.app.initialization":"Error durante la inicializaci\xF3n final de la aplicaci\xF3n.","error.transaction":"Error en la operaci\xF3n","error.unknown":"Ocurri\xF3 un error desconocido.","errors.DUPLICATE":"El campo <b>{{field}}</b> debe ser \xFAnico.","errors.FOREIGN_KEY_NOT_FOUND":"El campo <b>{{field}}</b> debe referenciar un \xEDtem existente.","errors.INVALID_EMAIL":"El campo <b>{{field}}</b> debe ser un correo electr\xF3nico v\xE1lido.","errors.INVALID_OBJECT_ID":"El campo <b>{{field}}</b> debe ser un valor v\xE1lido.","errors.IN_USE":"El \xEDtem est\xE1 en uso y no puede ser eliminado.","errors.MAX_LENGTH":"El campo <b>{{field}}</b> no debe exceder los <b>{{length}}</b> caracteres.","errors.MIN_LENGTH":"El campo <b>{{field}}</b> debe tener al menos <b>{{length}}</b> caracteres.","errors.MUST_NOT_BE_EMAIL":"El campo <b>{{field}}</b> no debe ser un correo electr\xF3nico.","errors.NO_PERMISSION":"No tienes permiso para realizar esta acci\xF3n.","errors.NO_SPACES":"El campo <b>{{field}}</b> no debe contener espacios.","errors.ONE_OR_MORE_OPERATIONS_FAILED":"Error en la operaci\xF3n","errors.REQUIRED":"El campo <b>{{field}}</b> es obligatorio.","errors.TOKEN_HAS_EXPIRED":"La sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.","errors.TOO_MANY_REQUESTS":"L\xEDmite de solicitudes alcanzado. Por favor intenta m\xE1s tarde.","errors.UNAUTHORIZED":"No est\xE1s autorizado para realizar esta acci\xF3n.","errors.all_password_fields_required":"Todos los campos de contrase\xF1a son obligatorios","errors.auth.INVALID_API_KEY":"Clave de API inv\xE1lida","errors.auth.INVALID_CREDENTIALS":"Usuario y/o contrase\xF1a incorrectos","errors.auth.NO_PERMISSION":"No tienes permisos suficientes","errors.auth.SESSION_EXPIRED":"Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.","errors.auth.TOO_MANY_REQUESTS":"Demasiados intentos. Por favor espera 15 minutos e intenta nuevamente","errors.auth.UNAUTHORIZED":"No tienes permisos para realizar esta acci\xF3n","errors.auth.USER_NOT_ACTIVE":"Usuario no activo","errors.auth.USER_NOT_FOUND":"Usuario no encontrado","errors.data.BAD_REQUEST":"Solicitud inv\xE1lida","errors.data.FIELD_ERROR":"Error en los datos ingresados","errors.data.IN_USE":"El elemento est\xE1 en uso y no puede ser eliminado","errors.data.ITEM_NOT_FOUND":"El elemento solicitado no fue encontrado","errors.data.NOT_FOUND":"No se encontr\xF3 lo solicitado","errors.internal_error_changing_password":"Error interno al cambiar la contrase\xF1a. Intenta nuevamente","errors.password_min_length":"La contrase\xF1a debe tener al menos 8 caracteres","errors.password_mismatch":"Las contrase\xF1as no coinciden","errors.password_must_be_different":"La nueva contrase\xF1a debe ser diferente a la actual","errors.system.DATABASE_CONNECTION_ERROR":"Error de conexi\xF3n. Verifica tu conexi\xF3n a internet.","errors.system.INTERNAL_SERVER_ERROR":"Error interno del servidor. Intenta nuevamente.","errors.system.INVALID_CONFIGURATION":"Error de configuraci\xF3n del sistema","errors.system.TOO_MANY_REQUESTS":"Demasiadas solicitudes. Por favor espera un momento e intenta nuevamente","errors.system.UNKNOWN_OPERATION":"Operaci\xF3n no reconocida","errors.users_module_not_configured":"M\xF3dulo de usuarios no configurado","footer.copyright":"Nocios S.R.L. Todos los derechos reservados.","footer.version":"Versi\xF3n","forgotPassword.checkEmailInstructions":"Revisa tu bandeja de entrada para el c\xF3digo de verificaci\xF3n","forgotPassword.codeAlreadyExistsMessage":"Ya se envi\xF3 un c\xF3digo y a\xFAn es v\xE1lido","forgotPassword.emailLabel":"Correo Electr\xF3nico","forgotPassword.emailPlaceholder":"Ingresa tu correo electr\xF3nico","forgotPassword.emailRequired":"El correo electr\xF3nico es obligatorio","forgotPassword.emailSentMessage":"C\xF3digo enviado exitosamente","forgotPassword.enterCodeLink":"Ingresar C\xF3digo","forgotPassword.instructions":"Ingresa tu correo electr\xF3nico y te enviaremos un c\xF3digo para restablecer tu contrase\xF1a.","forgotPassword.invalidEmail":"Ingresa un correo electr\xF3nico v\xE1lido","forgotPassword.sendCodeButton":"Enviar C\xF3digo","forgotPassword.title":"Recuperar Contrase\xF1a","loading.app.configInitial":"Cargando configuraci\xF3n inicial...","loading.app.generic":"Cargando...","loading.app.starting":"Iniciando aplicaci\xF3n...","loading.app.themeSetup":"Generando tema...","loading.app.validatingSession":"Validando sesi\xF3n...","login.alreadyHaveCodeLink":"\xBFYa tienes un c\xF3digo?","login.forgotPasswordLink":"\xBFOlvidaste tu contrase\xF1a?","login.initializationError":"Error de inicializaci\xF3n","login.initializing":"Inicializando...","login.loginButton":"Iniciar Sesi\xF3n","login.logoAlt":"Logotipo","login.noAccountPrompt":"\xBFNo tienes una cuenta?","login.notInitialized":"Sistema no inicializado","login.passwordLabel":"Contrase\xF1a","login.passwordPlaceholder":"Ingresa tu contrase\xF1a","login.passwordRequired":"Contrase\xF1a es obligatoria","login.signUpLink":"Reg\xEDstrate","login.usernameOrEmailLabel":"Usuario o Correo Electr\xF3nico","login.usernameOrEmailPlaceholder":"Ingresa tu usuario o correo electr\xF3nico","login.usernameRequired":"Usuario o correo electr\xF3nico es obligatorio","resetPassword.codeExpiredOrInvalid":"El c\xF3digo ha expirado o es inv\xE1lido","resetPassword.confirmPasswordLabel":"Confirmar Contrase\xF1a","resetPassword.confirmPasswordPlaceholder":"Confirma tu nueva contrase\xF1a","resetPassword.confirmPasswordRequired":"Confirma tu contrase\xF1a","resetPassword.goToLoginButton":"Ir al Login","resetPassword.instructions":"Ingresa tu nueva contrase\xF1a.","resetPassword.invalidCode":"El c\xF3digo de verificaci\xF3n es inv\xE1lido. Por favor, verifica el enlace o solicita uno nuevo.","resetPassword.missingParameters":"Faltan par\xE1metros obligatorios","resetPassword.newPasswordLabel":"Nueva Contrase\xF1a","resetPassword.newPasswordPlaceholder":"Ingresa tu nueva contrase\xF1a","resetPassword.newPasswordRequired":"La nueva contrase\xF1a es obligatoria","resetPassword.passwordTooShort":"La contrase\xF1a debe tener al menos 8 caracteres","resetPassword.passwordsDoNotMatch":"Las contrase\xF1as no coinciden","resetPassword.requestNewCodeButton":"Solicitar Nuevo C\xF3digo","resetPassword.resetPasswordButton":"Restablecer Contrase\xF1a","resetPassword.successInstructions":"Ahora puedes iniciar sesi\xF3n con tu nueva contrase\xF1a","resetPassword.successMessage":"Contrase\xF1a restablecida exitosamente","resetPassword.title":"Nueva Contrase\xF1a","resetPassword.validatingCode":"Validando c\xF3digo..."},en:{"checkCode.codeLabel":"Verification Code","checkCode.codePlaceholder":"Enter 6-digit code","checkCode.codeRequired":"Code is required","checkCode.emailLabel":"Email Address","checkCode.emailPlaceholder":"Enter your email address","checkCode.emailRequired":"Email address is required","checkCode.instructions":"Enter the 6-digit code we sent to your email address.","checkCode.invalidEmail":"Enter a valid email address","checkCode.resendCodeLink":"Resend code","checkCode.title":"Verify Code","checkCode.verifyButton":"Verify Code","common.back":"Back","common.backToLogin":"Back to Login","error.app.config":"Configuration Error: {{message}}","error.app.initialization":"Error during final application initialization.","error.transaction":"Operation error","error.unknown":"An unknown error occurred.","errors.DUPLICATE":"The field <b>{{field}}</b> must be unique.","errors.FOREIGN_KEY_NOT_FOUND":"The field <b>{{field}}</b> must reference an existing item.","errors.INVALID_EMAIL":"The field <b>{{field}}</b> must be a valid email address.","errors.INVALID_OBJECT_ID":"The field <b>{{field}}</b> must be a valid value.","errors.IN_USE":"The item is currently in use and cannot be deleted.","errors.MAX_LENGTH":"The field <b>{{field}}</b> must not exceed <b>{{maxLength}}</b> characters.","errors.MIN_LENGTH":"The field <b>{{field}}</b> must have at least <b>{{minLength}}</b> characters.","errors.MUST_NOT_BE_EMAIL":"The field <b>{{field}}</b> must not be an email address.","errors.NO_PERMISSION":"You do not have permission to perform this action.","errors.NO_SPACES":"The field <b>{{field}}</b> must not contain spaces.","errors.ONE_OR_MORE_OPERATIONS_FAILED":"Operation error","errors.REQUIRED":"The field <b>{{field}}</b> is required.","errors.TOKEN_HAS_EXPIRED":"Your session has expired, please log in again.","errors.TOO_MANY_REQUESTS":"Request limit reached. Please try again later.","errors.UNAUTHORIZED":"You are not authorized to perform this action.","errors.all_password_fields_required":"All password fields are required","errors.auth.INVALID_API_KEY":"Invalid API key","errors.auth.INVALID_CREDENTIALS":"Incorrect username and/or password","errors.auth.NO_PERMISSION":"Insufficient permissions","errors.auth.SESSION_EXPIRED":"Your session has expired. Please log in again.","errors.auth.TOO_MANY_REQUESTS":"Too many attempts. Please wait 15 minutes and try again","errors.auth.UNAUTHORIZED":"You don't have permission to perform this action","errors.auth.USER_NOT_ACTIVE":"User account is not active","errors.auth.USER_NOT_FOUND":"User not found","errors.data.BAD_REQUEST":"Invalid request","errors.data.FIELD_ERROR":"Error in the provided data","errors.data.IN_USE":"The item is in use and cannot be deleted","errors.data.ITEM_NOT_FOUND":"The requested item was not found","errors.data.NOT_FOUND":"The requested resource was not found","errors.internal_error_changing_password":"Internal error changing password. Please try again","errors.password_min_length":"Password must be at least 8 characters","errors.password_mismatch":"Passwords do not match","errors.password_must_be_different":"New password must be different from current password","errors.system.DATABASE_CONNECTION_ERROR":"Connection error. Please check your internet connection.","errors.system.INTERNAL_SERVER_ERROR":"Internal server error. Please try again.","errors.system.INVALID_CONFIGURATION":"System configuration error","errors.system.TOO_MANY_REQUESTS":"Too many requests. Please wait a moment and try again","errors.system.UNKNOWN_OPERATION":"Unrecognized operation","errors.users_module_not_configured":"Users module not configured","footer.copyright":"Nocios S.R.L. All Rights Reserved.","footer.version":"Version","forgotPassword.checkEmailInstructions":"Check your inbox for the verification code","forgotPassword.codeAlreadyExistsMessage":"A code was already sent and is still valid","forgotPassword.emailLabel":"Email Address","forgotPassword.emailPlaceholder":"Enter your email address","forgotPassword.emailRequired":"Email address is required","forgotPassword.emailSentMessage":"Code sent successfully","forgotPassword.enterCodeLink":"Enter Code","forgotPassword.instructions":"Enter your email address and we'll send you a code to reset your password.","forgotPassword.invalidEmail":"Enter a valid email address","forgotPassword.sendCodeButton":"Send Code","forgotPassword.title":"Reset Password","loading.app.configInitial":"Loading initial configuration...","loading.app.generic":"Loading...","loading.app.starting":"Starting application...","loading.app.themeSetup":"Generating theme...","loading.app.validatingSession":"Validating session...","login.alreadyHaveCodeLink":"Already have a code?","login.forgotPasswordLink":"Forgot Password?","login.initializationError":"Initialization error","login.initializing":"Initializing...","login.loginButton":"Log In","login.logoAlt":"Logo","login.noAccountPrompt":"Don't have an account?","login.notInitialized":"System not initialized","login.passwordLabel":"Password","login.passwordPlaceholder":"Enter your password","login.passwordRequired":"Password is required","login.signUpLink":"Sign up","login.usernameOrEmailLabel":"Username or Email","login.usernameOrEmailPlaceholder":"Enter your username or email","login.usernameRequired":"Username or email is required","resetPassword.codeExpiredOrInvalid":"Code expired or invalid","resetPassword.confirmPasswordLabel":"Confirm Password","resetPassword.confirmPasswordPlaceholder":"Confirm your new password","resetPassword.confirmPasswordRequired":"Confirm your password","resetPassword.goToLoginButton":"Go to Login","resetPassword.instructions":"Enter your new password.","resetPassword.invalidCode":"The verification code is invalid. Please check the link or request a new one.","resetPassword.missingParameters":"Missing required parameters","resetPassword.newPasswordLabel":"New Password","resetPassword.newPasswordPlaceholder":"Enter your new password","resetPassword.newPasswordRequired":"New password is required","resetPassword.passwordTooShort":"Password must be at least 8 characters","resetPassword.passwordsDoNotMatch":"Passwords do not match","resetPassword.requestNewCodeButton":"Request New Code","resetPassword.resetPasswordButton":"Reset Password","resetPassword.successInstructions":"You can now log in with your new password","resetPassword.successMessage":"Password reset successfully","resetPassword.title":"New Password","resetPassword.validatingCode":"Validating code..."}},Qe=()=>Object.keys(g),Xe=o=>g[o]||g.es;var B="crudify_translations_",er=3600*1e3,N=class o{constructor(){this.enableDebug=!1}static getInstance(){return o.instance||(o.instance=new o),o.instance}setDebug(e){this.enableDebug=e}async fetchTranslations(e){let{subscriberKey:r,apiKey:s,sections:t,crudifyEnv:n="stg",urlTranslations:u}=e,a=this.getFromCache(r),d=a?this.isCacheExpired(a):!0;if(a&&!d)return this.enableDebug&&console.log("[TranslationService] Using cached translations"),this.mergeWithUrlTranslations(a.data.translations,u);try{this.enableDebug&&console.log("[TranslationService] Fetching from API via crudify SDK...");let m=await this.fetchFromAPI(t);return this.hasDataChanged(a,m)||!a?(this.enableDebug&&console.log("[TranslationService] Data changed, updating cache"),this.saveToCache(r,m)):(this.enableDebug&&console.log("[TranslationService] Data unchanged, refreshing cache timestamp"),this.refreshCacheTimestamp(r)),this.mergeWithUrlTranslations(m.translations,u)}catch(m){return console.error("[TranslationService] API fetch failed:",m),a?(console.warn("[TranslationService] Using expired cache as fallback"),this.mergeWithUrlTranslations(a.data.translations,u)):(console.warn("[TranslationService] Using critical bundle translations"),this.getCriticalTranslationsOnly())}}async fetchFromAPI(e){let r=await Ze.getTranslation(e);if(!r.success)throw new Error(`Crudify API error: ${r.errors?JSON.stringify(r.errors):"Unknown error"}`);if(!r.data)throw new Error("No translation data in response");return r.data}mergeWithUrlTranslations(e,r){if(!r||Object.keys(r).length===0)return e;let s={};return Object.keys(e).forEach(t=>{s[t]={...e[t],...r}}),s}hasDataChanged(e,r){if(!e||e.data.timestamp!==r.timestamp)return!0;let s=this.hashData(r.translations);return e.dataHash!==s}hashData(e){let r=JSON.stringify(e),s=0;for(let t=0;t<r.length;t++){let n=r.charCodeAt(t);s=(s<<5)-s+n,s=s&s}return s.toString(36)}saveToCache(e,r){try{let s=this.getCacheKey(e),t={data:r,cachedAt:Date.now(),dataHash:this.hashData(r.translations)};localStorage.setItem(s,JSON.stringify(t)),this.enableDebug&&console.log("[TranslationService] Saved to cache:",s)}catch(s){console.error("[TranslationService] Failed to save cache:",s)}}getFromCache(e){try{let r=this.getCacheKey(e),s=localStorage.getItem(r);return s?JSON.parse(s):null}catch(r){return console.error("[TranslationService] Failed to read cache:",r),null}}refreshCacheTimestamp(e){try{let r=this.getFromCache(e);if(r){r.cachedAt=Date.now();let s=this.getCacheKey(e);localStorage.setItem(s,JSON.stringify(r))}}catch(r){console.error("[TranslationService] Failed to refresh cache timestamp:",r)}}isCacheExpired(e){return Date.now()-e.cachedAt>er}getCacheKey(e){return`${B}${e}`}getCriticalTranslationsOnly(){return g}invalidateCache(e){let r=this.getCacheKey(e);localStorage.removeItem(r),this.enableDebug&&console.log("[TranslationService] Cache invalidated:",r)}async prefetchTranslations(e){try{await this.fetchTranslations(e),this.enableDebug&&console.log("[TranslationService] Prefetch completed")}catch(r){console.error("[TranslationService] Prefetch failed:",r)}}clearAllCaches(){try{let r=Object.keys(localStorage).filter(s=>s.startsWith(B));r.forEach(s=>localStorage.removeItem(s)),this.enableDebug&&console.log(`[TranslationService] Cleared ${r.length} cache entries`)}catch(e){console.error("[TranslationService] Failed to clear caches:",e)}}},O=N.getInstance();import{jsx as Y}from"react/jsx-runtime";var G=rr(null);function H(o,e,r){return{...o,...e,...r||{}}}var ir=({children:o,subscriberKey:e,apiKey:r,crudifyEnv:s="stg",sections:t,language:n="es",devTranslations:u,translationUrl:a,enableDebug:d=!1,skipAutoInit:m=!0})=>{let[p,v]=y({}),[C,k]=y(!0),[$,U]=y(null),[j,D]=y(void 0),[M,J]=y(!1),I=nr(async()=>{if(M){d&&console.log("[TranslationsProvider] Skipping reload - using fallback translations");return}k(!0),U(null);let i;if(a)try{d&&console.log(`[TranslationsProvider] Fetching translations from URL: ${a}`);let l=await fetch(a);if(!l.ok)throw new Error(`Failed to fetch translations: ${l.statusText}`);i=await l.json(),D(i),d&&console.log("[TranslationsProvider] URL translations loaded:",{keysCount:i?Object.keys(i).length:0})}catch(l){console.error("[TranslationsProvider] Failed to load URL translations:",l),i=void 0,D(void 0)}try{O.setDebug(d);let l=await O.fetchTranslations({subscriberKey:e,apiKey:r,crudifyEnv:s,sections:t,urlTranslations:i}),h={};Object.keys(l).forEach(c=>{let T=g[c]||{},P=l[c]||{};h[c]=H(T,P,u)}),v(h),d&&console.log("[TranslationsProvider] Loaded translations:",{languages:Object.keys(h),keysCount:Object.keys(h[n]||{}).length})}catch(l){console.error("[TranslationsProvider] Failed to load:",l),U(l.message),J(!0);let h={};Object.keys(g).forEach(c=>{let T=g[c],P=i||j||{};h[c]=H(T,P,u)}),v(h),d&&console.log("[TranslationsProvider] Using fallback translations (critical + URL)")}finally{k(!1)}},[e,r,s,t,a,u,d,n,M]);sr(()=>{I();let i=setInterval(I,3600*1e3);return()=>clearInterval(i)},[I]);let Q={t:tr(()=>(i,l)=>{let c=(p[n]||{})[i];if(!c){let T=Object.keys(p);for(let P of T)if(p[P][i]){c=p[P][i];break}}return c||(d&&console.warn(`[TranslationsProvider] Missing translation: "${i}"`),c=i),l&&typeof c=="string"&&Object.entries(l).forEach(([T,P])=>{let X=new RegExp(`{{${T}}}`,"g");c=c.replace(X,String(P))}),c},[p,n,d]),language:n,availableLanguages:Object.keys(p),translations:p,isLoading:C,error:$,refreshTranslations:I};if(C){let i=g[n]?.loading||"Loading...";return Y("div",{children:i})}return Y(G.Provider,{value:Q,children:o})},ar=()=>{let o=or(G);if(!o)throw new Error("useTranslations must be used within TranslationsProvider");return o};import f from"@nocios/crudify-admin";var W=!1;function cr(){if(!W){let o=w.getInstance(),e=o.getTokenInfo();console.log("\u{1F50D} crudifyAdminWrapper - tokenInfo:",e);let r=e?.apiEndpointAdmin,s=e?.apiKeyEndpointAdmin;if(console.log("\u{1F50D} crudifyAdminWrapper - apiUrl:",r),console.log("\u{1F50D} crudifyAdminWrapper - apiKey:",s),r===void 0||s===void 0)throw console.error("\u274C crudifyAdminWrapper - Missing credentials!",{apiUrl:r,apiKey:s,tokenInfo:e}),new Error("crudifyAdmin: API URL or API Key for admin endpoint are not defined.");e?.apiEndpointAdmin&&e?.apiKeyEndpointAdmin?console.log("\u{1F527} crudifyAdmin: Initializing with dynamic credentials from getPermissions"):console.warn("\u26A0\uFE0F crudifyAdmin: Using fallback credentials (admin credentials not yet loaded from getPermissions)"),f.init({url:r,apiKey:s,getAdditionalHeaders:()=>{let t=o.getTokenInfo();return t?.crudifyTokens?.accessToken?{Authorization:`Bearer ${t.crudifyTokens.accessToken}`}:{}}}),W=!0}}async function R(o){try{cr();let e=await o();return!e.success&&e.errors?.includes("401")?await w.getInstance().refreshTokens()?await o():(console.error("Token refresh failed in crudifyAdmin"),typeof window<"u"&&(window.location.href="/login"),e):e}catch(e){return console.error("Error in crudifyAdmin operation:",e),{success:!1,errors:e instanceof Error?e.message:"Unknown error"}}}var dr={listModules:()=>R(()=>f.listModules()),getModule:o=>R(()=>f.getModule(o)),createModule:o=>R(()=>f.createModule(o)),editModule:(o,e)=>R(()=>f.editModule(o,e)),deleteModule:o=>R(()=>f.deleteModule(o)),activateModule:o=>R(()=>f.activateModule(o)),deactivateModule:o=>R(()=>f.deactivateModule(o)),getModuleVersions:o=>R(()=>f.getModuleVersions(o))};export{K as AuthRoute,g as CRITICAL_TRANSLATIONS,Te as CrudifyLogin,Fe as CrudifyThemeProvider,ge as ERROR_CODES,pe as ERROR_SEVERITY_MAP,ce as GlobalNotificationProvider,we as LoginComponent,ve as POLICY_ACTIONS,Ce as PREFERRED_POLICY_ORDER,Ie as Policies,q as ProtectedRoute,ue as SessionDebugInfo,_ as SessionLoadingScreen,w as SessionManager,le as SessionProvider,Se as SessionStatus,Z as TokenStorage,N as TranslationService,ir as TranslationsProvider,ye as UserProfileDisplay,se as createErrorTranslator,Qr as crudify,dr as crudifyAdmin,ne as decodeJwtSafely,x as extractSafeRedirectFromUrl,L as getCookie,Qe as getCriticalLanguages,Xe as getCriticalTranslations,ie as getCurrentUserEmail,he as getErrorMessage,Re as handleCrudifyError,ae as isTokenExpired,fe as parseApiError,Pe as parseJavaScriptError,me as parseTransactionError,Le as secureLocalStorage,Oe as secureSessionStorage,oe as translateError,ee as translateErrorCode,re as translateErrorCodes,O as translationService,be as useAuth,_e as useCrudifyWithNotifications,Ne as useData,de as useGlobalNotification,te as useSession,E as useSessionContext,ar as useTranslations,Ae as useUserData,Ee as useUserProfile,A as validateInternalRedirect};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocios/crudify-ui",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.42",
|
|
4
4
|
"description": "Biblioteca de componentes UI para Crudify",
|
|
5
5
|
"author": "Nocios",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@nocios/crudify-admin": "^2.0.2",
|
|
43
|
-
"@nocios/crudify-browser": "^4.0.
|
|
43
|
+
"@nocios/crudify-browser": "^4.0.90",
|
|
44
44
|
"crypto-js": "^4.2.0",
|
|
45
45
|
"dompurify": "^3.2.7",
|
|
46
46
|
"uuid": "^13.0.0"
|
package/dist/chunk-47LRGZUJ.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as w,b as _,f as v,g as G,h as X,i as V}from"./chunk-5JKS55SE.mjs";import C from"crypto-js";var l=class l{static setStorageType(t){l.storageType=t}static generateEncryptionKey(){let t=[navigator.userAgent,navigator.language,navigator.platform,screen.width,screen.height,Date.now().toString(),Math.random().toString(36)].join("|");return C.SHA256(t).toString()}static getEncryptionKey(){if(l.encryptionKey)return l.encryptionKey;let t=window.localStorage;if(!t)return l.encryptionKey=l.generateEncryptionKey(),l.encryptionKey;try{let e=t.getItem(l.ENCRYPTION_KEY_STORAGE);return(!e||e.length<32)&&(e=l.generateEncryptionKey(),t.setItem(l.ENCRYPTION_KEY_STORAGE,e)),l.encryptionKey=e,e}catch{return console.warn("Crudify: Cannot persist encryption key, using temporary key"),l.encryptionKey=l.generateEncryptionKey(),l.encryptionKey}}static isStorageAvailable(t){try{let e=window[t],r="__storage_test__";return e.setItem(r,"test"),e.removeItem(r),!0}catch{return!1}}static getStorage(){return l.storageType==="none"?null:l.isStorageAvailable(l.storageType)?window[l.storageType]:(console.warn(`Crudify: ${l.storageType} not available, tokens won't persist`),null)}static encrypt(t){try{let e=l.getEncryptionKey();return C.AES.encrypt(t,e).toString()}catch(e){return console.error("Crudify: Encryption failed",e),t}}static decrypt(t){try{let e=l.getEncryptionKey();return C.AES.decrypt(t,e).toString(C.enc.Utf8)||t}catch(e){return console.error("Crudify: Decryption failed",e),t}}static saveTokens(t){let e=l.getStorage();if(e)try{let r={accessToken:t.accessToken,refreshToken:t.refreshToken,expiresAt:t.expiresAt,refreshExpiresAt:t.refreshExpiresAt,savedAt:Date.now()},i=l.encrypt(JSON.stringify(r));e.setItem(l.TOKEN_KEY,i),console.debug("Crudify: Tokens saved successfully")}catch(r){console.error("Crudify: Failed to save tokens",r)}}static getTokens(){let t=l.getStorage();if(!t)return null;try{let e=t.getItem(l.TOKEN_KEY);if(!e)return null;let r=l.decrypt(e),i=JSON.parse(r);return!i.accessToken||!i.refreshToken||!i.expiresAt||!i.refreshExpiresAt?(console.warn("Crudify: Incomplete token data found, clearing storage"),l.clearTokens(),null):Date.now()>=i.refreshExpiresAt?(console.info("Crudify: Refresh token expired, clearing storage"),l.clearTokens(),null):{accessToken:i.accessToken,refreshToken:i.refreshToken,expiresAt:i.expiresAt,refreshExpiresAt:i.refreshExpiresAt}}catch(e){return console.error("Crudify: Failed to retrieve tokens",e),l.clearTokens(),null}}static clearTokens(){let t=l.getStorage();if(t)try{t.removeItem(l.TOKEN_KEY),console.debug("Crudify: Tokens cleared from storage")}catch(e){console.error("Crudify: Failed to clear tokens",e)}}static rotateEncryptionKey(){try{l.clearTokens(),l.encryptionKey=null;let t=window.localStorage;t&&t.removeItem(l.ENCRYPTION_KEY_STORAGE),console.info("Crudify: Encryption key rotated successfully")}catch(t){console.error("Crudify: Failed to rotate encryption key",t)}}static hasValidTokens(){return l.getTokens()!==null}static getExpirationInfo(){let t=l.getTokens();if(!t)return null;let e=Date.now();return{accessExpired:e>=t.expiresAt,refreshExpired:e>=t.refreshExpiresAt,accessExpiresIn:Math.max(0,t.expiresAt-e),refreshExpiresIn:Math.max(0,t.refreshExpiresAt-e)}}static updateAccessToken(t,e){let r=l.getTokens();if(!r){console.warn("Crudify: Cannot update access token, no existing tokens found");return}l.saveTokens({...r,accessToken:t,expiresAt:e})}static subscribeToChanges(t){let e=r=>{if(r.key===l.TOKEN_KEY){if(r.newValue===null){console.debug("Crudify: Tokens removed in another tab"),t(null);return}if(r.newValue){console.debug("Crudify: Tokens updated in another tab");let i=l.getTokens();t(i)}}};return window.addEventListener("storage",e),()=>{window.removeEventListener("storage",e)}}};l.TOKEN_KEY="crudify_tokens",l.ENCRYPTION_KEY_STORAGE="crudify_enc_key",l.encryptionKey=null,l.storageType="localStorage";var f=l;import T from"@nocios/crudify-browser";var O=class o{constructor(){this.config={};this.initialized=!1;this.lastActivityTime=0;this.isRefreshingLocally=!1;this.refreshPromise=null}static getInstance(){return o.instance||(o.instance=new o),o.instance}async initialize(t={}){if(this.initialized){console.warn("SessionManager: Already initialized");return}this.config={storageType:"localStorage",autoRestore:!0,enableLogging:!1,...t},f.setStorageType(this.config.storageType||"localStorage"),this.config.enableLogging,T.setTokenInvalidationCallback(()=>{this.log("\u{1F514} Tokens invalidated by crudify-core"),v.emit("SESSION_EXPIRED",{message:"Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.",source:"crudify-core.clearTokensAndRefreshState"})}),this.config.autoRestore&&await this.restoreSession(),this.initialized=!0,this.log("SessionManager initialized successfully")}async login(t,e){try{this.log("Attempting login...");let r=await T.login(t,e);if(!r.success)return this.log("Login failed:",r.errors),{success:!1,error:this.formatError(r.errors),rawResponse:r};let i={accessToken:r.data.token,refreshToken:r.data.refreshToken,expiresAt:r.data.expiresAt,refreshExpiresAt:r.data.refreshExpiresAt};return f.saveTokens(i),this.lastActivityTime=Date.now(),this.log("Login successful, tokens saved"),await this.fetchAndStoreAdminCredentials(),this.config.onLoginSuccess?.(i),{success:!0,tokens:i,data:r.data}}catch(r){return this.log("Login error:",r),{success:!1,error:r instanceof Error?r.message:"Unknown error"}}}async logout(){try{this.log("Logging out..."),await T.logout(),f.clearTokens(),this.log("Logout successful"),this.config.onLogout?.()}catch(t){this.log("Logout error:",t),f.clearTokens()}}async restoreSession(){try{this.log("Attempting to restore session...");let t=f.getTokens();if(!t)return this.log("No valid tokens found in storage"),!1;if(Date.now()>=t.refreshExpiresAt)return this.log("Refresh token expired, clearing storage"),f.clearTokens(),!1;if(T.setTokens({accessToken:t.accessToken,refreshToken:t.refreshToken,expiresAt:t.expiresAt,refreshExpiresAt:t.refreshExpiresAt}),T.getTokenData().isValid===!1){if(this.log("Restored access token is invalid or expired"),Date.now()<t.refreshExpiresAt&&(this.log("Access token expired but refresh is valid, attempting refresh..."),await this.refreshTokens())){this.log("Session restored successfully via token refresh");let i=f.getTokens();return i&&this.config.onSessionRestored?.(i),!0}return f.clearTokens(),await T.logout(),!1}return this.log("Session restored successfully"),this.lastActivityTime=Date.now(),(!t.apiEndpointAdmin||!t.apiKeyEndpointAdmin)&&(this.log("Admin credentials missing, fetching from permissions..."),await this.fetchAndStoreAdminCredentials()),this.config.onSessionRestored?.(t),!0}catch(t){return this.log("Session restore error:",t),f.clearTokens(),await T.logout(),!1}}isAuthenticated(){return T.isLogin()||f.hasValidTokens()}getTokenInfo(){let t=T.getTokenData(),e=f.getExpirationInfo(),r=f.getTokens();return{isLoggedIn:this.isAuthenticated(),crudifyTokens:t,storageInfo:e,hasValidTokens:f.hasValidTokens(),apiEndpointAdmin:r?.apiEndpointAdmin,apiKeyEndpointAdmin:r?.apiKeyEndpointAdmin}}async fetchAndStoreAdminCredentials(){try{this.log("Fetching permissions to get admin API credentials...");let t=await T.getPermissions();if(!t.success)return this.log("Failed to fetch permissions:",t.errors),!1;let{apiEndpointAdmin:e,apiKeyEndpointAdmin:r}=t.data||{};if(e&&r){let i=f.getTokens();if(i)return f.saveTokens({...i,apiEndpointAdmin:e,apiKeyEndpointAdmin:r}),this.log("Admin API credentials stored successfully"),!0}else this.log("Admin credentials not found in permissions response");return!1}catch(t){return this.log("Error fetching admin credentials:",t),!1}}async refreshTokens(){if(this.isRefreshingLocally&&this.refreshPromise)return this.log("Refresh already in progress, waiting for existing promise..."),this.refreshPromise;this.isRefreshingLocally=!0,this.refreshPromise=this._performRefresh();try{return await this.refreshPromise}finally{this.isRefreshingLocally=!1,this.refreshPromise=null}}async _performRefresh(){try{this.log("Starting token refresh...");let t=await T.refreshAccessToken();if(!t.success)return this.log("Token refresh failed:",t.errors),f.clearTokens(),this.config.showNotification?.(this.getSessionExpiredMessage(),"warning"),this.config.onSessionExpired?.(),!1;let e={accessToken:t.data.token,refreshToken:t.data.refreshToken,expiresAt:t.data.expiresAt,refreshExpiresAt:t.data.refreshExpiresAt};return f.saveTokens(e),this.log("Tokens refreshed and saved successfully"),this.lastActivityTime=Date.now(),!0}catch(t){return this.log("Token refresh error:",t),f.clearTokens(),this.config.showNotification?.(this.getSessionExpiredMessage(),"warning"),this.config.onSessionExpired?.(),!1}}isRefreshing(){return this.isRefreshingLocally}setupResponseInterceptor(){T.setResponseInterceptor(async t=>{this.updateLastActivity();let e=this.detectAuthorizationError(t);if(e.isAuthError){if(this.log("\u{1F6A8} Authorization error detected:",{errorType:e.errorType,shouldLogout:e.shouldTriggerLogout}),e.isRefreshTokenInvalid||e.isTokenRefreshFailed)return this.log("Refresh token invalid, emitting TOKEN_REFRESH_FAILED event"),v.emit("TOKEN_REFRESH_FAILED",{message:e.userFriendlyMessage,error:e.errorDetails,source:"SessionManager.setupResponseInterceptor"}),t;e.shouldTriggerLogout&&(f.hasValidTokens()&&!e.isIrrecoverable?(this.log("Access token expired, emitting TOKEN_EXPIRED event"),v.emit("TOKEN_EXPIRED",{message:"Access token expired, refresh needed",error:e.errorDetails,source:"SessionManager.setupResponseInterceptor"})):(this.log("No valid tokens or irrecoverable error, emitting SESSION_EXPIRED event"),v.emit("SESSION_EXPIRED",{message:e.userFriendlyMessage,error:e.errorDetails,source:"SessionManager.setupResponseInterceptor"})))}return t}),this.log("Response interceptor configured (non-blocking mode)")}detectAuthorizationError(t){let e={isAuthError:!1,isRefreshTokenInvalid:!1,isTokenRefreshFailed:!1,isTokenExpired:!1,isUnauthorized:!1,isIrrecoverable:!1,shouldTriggerLogout:!1,errorType:"",errorDetails:null,userFriendlyMessage:""};if(t.errors&&Array.isArray(t.errors)){let r=t.errors.find(i=>i.errorType==="Unauthorized"||i.message?.includes("Unauthorized")||i.message?.includes("Not Authorized")||i.message?.includes("NOT_AUTHORIZED")||i.message?.includes("Token")||i.message?.includes("TOKEN")||i.message?.includes("Authentication")||i.message?.includes("UNAUTHENTICATED")||i.extensions?.code==="UNAUTHENTICATED"||i.extensions?.code==="FORBIDDEN");r&&(e.isAuthError=!0,e.errorType="GraphQL Array",e.errorDetails=r,e.shouldTriggerLogout=!0,e.userFriendlyMessage="Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.",(r.message?.includes("TOKEN")||r.message?.includes("Token"))&&(e.isTokenExpired=!0),r.extensions?.code==="UNAUTHENTICATED"&&(e.isUnauthorized=!0))}if(!e.isAuthError&&t.errors&&typeof t.errors=="object"&&!Array.isArray(t.errors)){let i=Object.values(t.errors).flat().find(u=>typeof u=="string"&&(u.includes("NOT_AUTHORIZED")||u.includes("TOKEN_REFRESH_FAILED")||u.includes("TOKEN_HAS_EXPIRED")||u.includes("PLEASE_LOGIN")||u.includes("Unauthorized")||u.includes("UNAUTHENTICATED")||u.includes("SESSION_EXPIRED")||u.includes("INVALID_TOKEN")));i&&typeof i=="string"&&(e.isAuthError=!0,e.errorType="GraphQL Object",e.errorDetails=t.errors,e.shouldTriggerLogout=!0,i.includes("TOKEN_REFRESH_FAILED")?(e.isTokenRefreshFailed=!0,e.isRefreshTokenInvalid=!0,e.isIrrecoverable=!0,e.userFriendlyMessage="Tu sesi\xF3n ha caducado. Por favor, inicia sesi\xF3n nuevamente."):i.includes("TOKEN_HAS_EXPIRED")||i.includes("SESSION_EXPIRED")?(e.isTokenExpired=!0,e.userFriendlyMessage="Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente."):i.includes("INVALID_TOKEN")?(e.isTokenExpired=!0,e.isIrrecoverable=!0,e.userFriendlyMessage="Token inv\xE1lido. Por favor, inicia sesi\xF3n nuevamente."):e.userFriendlyMessage="Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.")}if(!e.isAuthError&&t.data?.response?.status){let r=t.data.response.status.toUpperCase();(r==="UNAUTHORIZED"||r==="UNAUTHENTICATED")&&(e.isAuthError=!0,e.errorType="Status",e.errorDetails=t.data.response,e.isUnauthorized=!0,e.shouldTriggerLogout=!0,e.isIrrecoverable=!0,e.userFriendlyMessage="Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.")}if(!e.isAuthError&&t.data?.response?.data)try{let r=typeof t.data.response.data=="string"?JSON.parse(t.data.response.data):t.data.response.data;(r.error==="REFRESH_TOKEN_INVALID"||r.error==="TOKEN_EXPIRED"||r.error==="INVALID_TOKEN")&&(e.isAuthError=!0,e.errorType="Parsed Data",e.errorDetails=r,e.shouldTriggerLogout=!0,e.isIrrecoverable=!0,r.error==="REFRESH_TOKEN_INVALID"?(e.isRefreshTokenInvalid=!0,e.isTokenRefreshFailed=!0,e.userFriendlyMessage="Tu sesi\xF3n ha caducado. Por favor, inicia sesi\xF3n nuevamente."):(e.isTokenExpired=!0,e.userFriendlyMessage="Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente."))}catch{}if(!e.isAuthError&&t.errorCode){let r=t.errorCode.toUpperCase();(r==="UNAUTHORIZED"||r==="UNAUTHENTICATED"||r==="TOKEN_EXPIRED"||r==="INVALID_TOKEN")&&(e.isAuthError=!0,e.errorType="Error Code",e.errorDetails={errorCode:r},e.shouldTriggerLogout=!0,r==="TOKEN_EXPIRED"?e.isTokenExpired=!0:e.isUnauthorized=!0,e.userFriendlyMessage="Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente.")}return e}updateLastActivity(){this.lastActivityTime=Date.now(),this.log("Last activity updated")}getTimeSinceLastActivity(){return this.lastActivityTime===0?0:Date.now()-this.lastActivityTime}checkInactivity(){let t=this.getTimeSinceLastActivity(),e=T.getTokenData();if(this.lastActivityTime===0)return"none";let r=900*1e3,i=300*1e3,u=300*1e3;return t>r?(this.log(`Inactivity timeout: ${Math.floor(t/6e4)} minutes since last activity`),"logout"):t<i&&e.expiresIn<u&&e.expiresIn>0?(this.log(`User active recently (${Math.floor(t/6e4)}min ago) and token expiring soon, should refresh`),"refresh"):"none"}clearSession(){f.clearTokens(),T.logout(),this.lastActivityTime=0,this.log("Session cleared completely")}getSessionExpiredMessage(){return this.config.translateFn?_("SESSION_EXPIRED",{translateFn:this.config.translateFn,enableDebug:this.config.enableLogging}):"Tu sesi\xF3n ha expirado. Por favor, inicia sesi\xF3n nuevamente."}log(t,...e){this.config.enableLogging&&console.log(`[SessionManager] ${t}`,...e)}formatError(t){return t?typeof t=="string"?t:typeof t=="object"?Object.values(t).flat().join(", "):"Authentication failed":"Unknown error"}};import{useState as ee,useEffect as K,useCallback as R}from"react";function Y(o={}){let[t,e]=ee({isAuthenticated:!1,isLoading:!0,isInitialized:!1,tokens:null,error:null}),r=O.getInstance(),i=R(async()=>{try{e(a=>({...a,isLoading:!0,error:null}));let c={autoRestore:o.autoRestore??!0,enableLogging:o.enableLogging??!1,showNotification:o.showNotification,translateFn:o.translateFn,onSessionExpired:()=>{e(a=>({...a,isAuthenticated:!1,tokens:null,error:"Session expired"})),o.onSessionExpired?.()},onSessionRestored:a=>{e(g=>({...g,isAuthenticated:!0,tokens:a,error:null})),o.onSessionRestored?.(a)},onLoginSuccess:a=>{e(g=>({...g,isAuthenticated:!0,tokens:a,error:null}))},onLogout:()=>{e(a=>({...a,isAuthenticated:!1,tokens:null,error:null}))}};await r.initialize(c),r.setupResponseInterceptor();let s=r.isAuthenticated(),n=r.getTokenInfo();e(a=>({...a,isAuthenticated:s,isInitialized:!0,isLoading:!1,tokens:n.crudifyTokens.accessToken?{accessToken:n.crudifyTokens.accessToken,refreshToken:n.crudifyTokens.refreshToken,expiresAt:n.crudifyTokens.expiresAt,refreshExpiresAt:n.crudifyTokens.refreshExpiresAt}:null}))}catch(c){let s=c instanceof Error?c.message:"Initialization failed";e(n=>({...n,isLoading:!1,isInitialized:!0,error:s}))}},[o.autoRestore,o.enableLogging,o.onSessionExpired,o.onSessionRestored]),u=R(async(c,s)=>{e(n=>({...n,isLoading:!0,error:null}));try{let n=await r.login(c,s);return n.success&&n.tokens?e(a=>({...a,isAuthenticated:!0,tokens:n.tokens,isLoading:!1,error:null})):e(a=>({...a,isAuthenticated:!1,tokens:null,isLoading:!1,error:null})),n}catch(n){let a=n instanceof Error?n.message:"Login failed",g=a.includes("INVALID_CREDENTIALS")||a.includes("Invalid email")||a.includes("Invalid password")||a.includes("credentials");return e(m=>({...m,isAuthenticated:!1,tokens:null,isLoading:!1,error:g?null:a})),{success:!1,error:a}}},[r]),E=R(async()=>{e(c=>({...c,isLoading:!0}));try{await r.logout(),e(c=>({...c,isAuthenticated:!1,tokens:null,isLoading:!1,error:null}))}catch(c){e(s=>({...s,isAuthenticated:!1,tokens:null,isLoading:!1,error:c instanceof Error?c.message:"Logout error"}))}},[r]),h=R(async()=>{try{let c=await r.refreshTokens();if(c){let s=r.getTokenInfo();e(n=>({...n,tokens:s.crudifyTokens.accessToken?{accessToken:s.crudifyTokens.accessToken,refreshToken:s.crudifyTokens.refreshToken,expiresAt:s.crudifyTokens.expiresAt,refreshExpiresAt:s.crudifyTokens.refreshExpiresAt}:null,error:null}))}else e(s=>({...s,isAuthenticated:!1,tokens:null,error:"Token refresh failed"}));return c}catch(c){return e(s=>({...s,isAuthenticated:!1,tokens:null,error:c instanceof Error?c.message:"Token refresh failed"})),!1}},[r]),x=R(()=>{e(c=>({...c,error:null}))},[]),y=R(()=>r.getTokenInfo(),[r]);K(()=>{i()},[i]),K(()=>{if(!t.isAuthenticated||!t.tokens)return;let c=G.getInstance(),s=()=>{r.updateLastActivity(),o.enableLogging&&console.log("\u{1F4CD} User navigating - activity updated")},n=c.subscribe(s);window.addEventListener("popstate",s);let a=setInterval(async()=>{if(r.isRefreshing()){o.enableLogging&&console.log("\u23F8\uFE0F Refresh already in progress, skipping inactivity check");return}let g=r.checkInactivity();if(g==="logout")o.enableLogging&&console.log("\u23F1\uFE0F Inactivity timeout - logging out user"),await E();else if(g==="refresh")if(o.enableLogging&&console.log("\u{1F504} User active, token expiring soon - refreshing..."),e(p=>({...p,isLoading:!0})),await r.refreshTokens()){let p=r.getTokenInfo();e(S=>({...S,isLoading:!1,tokens:p.crudifyTokens.accessToken?{accessToken:p.crudifyTokens.accessToken,refreshToken:p.crudifyTokens.refreshToken,expiresAt:p.crudifyTokens.expiresAt,refreshExpiresAt:p.crudifyTokens.refreshExpiresAt}:null}))}else e(p=>({...p,isLoading:!1,isAuthenticated:!1,tokens:null}))},120*1e3);return()=>{clearInterval(a),window.removeEventListener("popstate",s),n()}},[t.isAuthenticated,t.tokens,r,o.enableLogging,E]),K(()=>{let c=v.subscribe(async s=>{if(o.enableLogging&&console.log(`\u{1F4E2} useSession: Received auth event: ${s.type}`),s.type==="TOKEN_EXPIRED"){if(r.isRefreshing()){o.enableLogging&&console.log("\u23F8\uFE0F Refresh already in progress, skipping TOKEN_EXPIRED handler");return}o.enableLogging&&console.log("\u{1F504} Token expired, attempting refresh..."),e(n=>({...n,isLoading:!0}));try{if(await r.refreshTokens()){o.enableLogging&&console.log("\u2705 Token refreshed successfully");let a=r.getTokenInfo();e(g=>({...g,isLoading:!1,tokens:a.crudifyTokens.accessToken?{accessToken:a.crudifyTokens.accessToken,refreshToken:a.crudifyTokens.refreshToken,expiresAt:a.crudifyTokens.expiresAt,refreshExpiresAt:a.crudifyTokens.refreshExpiresAt}:null}))}else o.enableLogging&&console.log("\u274C Token refresh failed, session expired"),v.emit("SESSION_EXPIRED",{message:"Failed to refresh token after detecting expiration",source:"useSession.TOKEN_EXPIRED handler"})}catch(n){o.enableLogging&&console.error("\u274C Error during token refresh:",n),v.emit("SESSION_EXPIRED",{message:n instanceof Error?n.message:"Unknown error during refresh",source:"useSession.TOKEN_EXPIRED handler (error)"})}}(s.type==="SESSION_EXPIRED"||s.type==="TOKEN_REFRESH_FAILED")&&(o.enableLogging&&console.log(`\u{1F534} Session expired (${s.type}), logging out...`),e(n=>({...n,isAuthenticated:!1,tokens:null,isLoading:!1,error:s.details?.message||"Session expired"})),o.onSessionExpired?.())});return()=>c()},[o.enableLogging,o.onSessionExpired,r]),K(()=>{let c=f.subscribeToChanges(s=>{s?(o.enableLogging&&console.log("\u{1F504} Tokens updated in another tab"),e(n=>({...n,tokens:s,isAuthenticated:!0}))):(o.enableLogging&&console.log("\u{1F504} Logout detected in another tab"),e(n=>({...n,isAuthenticated:!1,tokens:null})),v.emit("SESSION_EXPIRED",{message:"Sesi\xF3n cerrada en otra pesta\xF1a",source:"CrossTabSync"}))});return()=>c()},[o.enableLogging]);let I=R(()=>{r.updateLastActivity()},[r]);return{...t,login:u,logout:E,refreshTokens:h,clearError:x,getTokenInfo:y,updateActivity:I,isExpiringSoon:t.tokens?t.tokens.expiresAt-Date.now()<300*1e3:!1,expiresIn:t.tokens?Math.max(0,t.tokens.expiresAt-Date.now()):0,refreshExpiresIn:t.tokens?Math.max(0,t.tokens.refreshExpiresAt-Date.now()):0}}import{useState as j,createContext as te,useContext as re,useCallback as U,useEffect as oe}from"react";import{Snackbar as se,Alert as ie,Box as ne,Portal as ae}from"@mui/material";import{v4 as le}from"uuid";import ce from"dompurify";import{jsx as D,jsxs as fe}from"react/jsx-runtime";var B=te(null),ue=o=>ce.sanitize(o,{ALLOWED_TAGS:["b","i","em","strong","br","span"],ALLOWED_ATTR:["class"],FORBID_TAGS:["script","iframe","object","embed"],FORBID_ATTR:["onload","onerror","onclick","onmouseover","onfocus","onblur"],WHOLE_DOCUMENT:!1,RETURN_DOM:!1,RETURN_DOM_FRAGMENT:!1,RETURN_TRUSTED_TYPE:!1}),W=({children:o,maxNotifications:t=5,defaultAutoHideDuration:e=6e3,position:r={vertical:"top",horizontal:"right"},enabled:i=!1,allowHtml:u=!1})=>{let[E,h]=j([]),x=U((s,n="info",a)=>{if(!i)return"";if(!s||typeof s!="string")return console.warn("\u26A0\uFE0F GlobalNotificationProvider: Invalid message provided"),"";s.length>1e3&&(console.warn("\u26A0\uFE0F GlobalNotificationProvider: Message too long, truncating"),s=s.substring(0,1e3)+"...");let g=le(),m={id:g,message:s,severity:n,autoHideDuration:a?.autoHideDuration??e,persistent:a?.persistent??!1,allowHtml:a?.allowHtml??u};return h(p=>[...p.length>=t?p.slice(-(t-1)):p,m]),g},[t,e,i,u]),y=U(s=>{h(n=>n.filter(a=>a.id!==s))},[]),I=U(()=>{h([])},[]),c={showNotification:x,hideNotification:y,clearAllNotifications:I};return fe(B.Provider,{value:c,children:[o,i&&D(ae,{children:D(ne,{sx:{position:"fixed",zIndex:9999,[r.vertical]:(r.vertical==="top",24),[r.horizontal]:r.horizontal==="right"||r.horizontal==="left"?24:"50%",...r.horizontal==="center"&&{transform:"translateX(-50%)"},display:"flex",flexDirection:r.vertical==="top"?"column":"column-reverse",gap:1,maxWidth:"400px",width:"auto"},children:E.map(s=>D(de,{notification:s,onClose:()=>y(s.id)},s.id))})})]})},de=({notification:o,onClose:t})=>{let[e,r]=j(!0),i=U((u,E)=>{E!=="clickaway"&&(r(!1),setTimeout(t,300))},[t]);return oe(()=>{if(!o.persistent&&o.autoHideDuration){let u=setTimeout(()=>{i()},o.autoHideDuration);return()=>clearTimeout(u)}},[o.autoHideDuration,o.persistent,i]),D(se,{open:e,onClose:i,sx:{position:"relative","& .MuiSnackbarContent-root":{minWidth:"auto"}},TransitionProps:{enter:!0,exit:!0},children:D(ie,{variant:"filled",severity:o.severity,onClose:i,sx:{width:"100%",minWidth:"280px",maxWidth:"400px",wordBreak:"break-word"},children:o.allowHtml?D("span",{dangerouslySetInnerHTML:{__html:ue(o.message)}}):D("span",{children:o.message})})})},$=()=>{let o=re(B);if(!o)throw new Error("useGlobalNotification debe ser usado dentro de un GlobalNotificationProvider");return o};import ge,{createContext as pe,useContext as he,useMemo as J}from"react";import{Fragment as ke,jsx as k,jsxs as A}from"react/jsx-runtime";var Z=pe(void 0);function Te({children:o,options:t={},config:e,showNotifications:r=!1,notificationOptions:i={}}){let u;try{let{showNotification:s}=$();u=s}catch{}let E=ge.useMemo(()=>({...t,showNotification:u,onSessionExpired:()=>{t.onSessionExpired?.()}}),[t,u]),h=Y(E),x=J(()=>{let s,n,a,g,m,p="unknown";if(e?.publicApiKey&&(s=e.publicApiKey,p="props"),e?.env&&(n=e.env),e?.appName&&(a=e.appName),e?.loginActions&&(g=e.loginActions),e?.logo&&(m=e.logo),!s){let S=w("publicApiKey"),N=w("environment"),L=w("appName"),b=w("loginActions"),d=w("logo");S&&(s=S,p="cookies"),N&&["dev","stg","prod"].includes(N)&&(n=N),L&&(a=decodeURIComponent(L)),b&&(g=decodeURIComponent(b).split(",").map(P=>P.trim()).filter(Boolean)),d&&(m=decodeURIComponent(d))}return{publicApiKey:s,env:n,appName:a,loginActions:g,logo:m}},[e]),y=J(()=>{if(!h.tokens?.accessToken||!h.isAuthenticated)return null;try{let s=X(h.tokens.accessToken);if(s&&s.sub&&s.email&&s.subscriber){let n={_id:s.sub,email:s.email,subscriberKey:s.subscriber};return Object.keys(s).forEach(a=>{["sub","email","subscriber"].includes(a)||(n[a]=s[a])}),n}}catch(s){console.error("Error decoding JWT token for sessionData:",s)}return null},[h.tokens?.accessToken,h.isAuthenticated]),I={...h,sessionData:y,config:x},c={enabled:r,maxNotifications:i.maxNotifications||5,defaultAutoHideDuration:i.defaultAutoHideDuration||6e3,position:i.position||{vertical:"top",horizontal:"right"}};return k(Z.Provider,{value:I,children:o})}function Qe(o){let t={enabled:o.showNotifications,maxNotifications:o.notificationOptions?.maxNotifications||5,defaultAutoHideDuration:o.notificationOptions?.defaultAutoHideDuration||6e3,position:o.notificationOptions?.position||{vertical:"top",horizontal:"right"},allowHtml:o.notificationOptions?.allowHtml||!1};return k(W,{...t,children:k(Te,{...o})})}function ye(){let o=he(Z);if(o===void 0)throw new Error("useSessionContext must be used within a SessionProvider");return o}function et(){let o=ye();return o.isInitialized?A("div",{style:{padding:"10px",margin:"10px",border:"1px solid #ccc",borderRadius:"4px",fontSize:"12px",fontFamily:"monospace"},children:[k("h4",{children:"Session Debug Info"}),A("div",{children:[k("strong",{children:"Authenticated:"})," ",o.isAuthenticated?"Yes":"No"]}),A("div",{children:[k("strong",{children:"Loading:"})," ",o.isLoading?"Yes":"No"]}),A("div",{children:[k("strong",{children:"Error:"})," ",o.error||"None"]}),o.tokens&&A(ke,{children:[A("div",{children:[k("strong",{children:"Access Token:"})," ",o.tokens.accessToken.substring(0,20),"..."]}),A("div",{children:[k("strong",{children:"Refresh Token:"})," ",o.tokens.refreshToken.substring(0,20),"..."]}),A("div",{children:[k("strong",{children:"Access Expires In:"})," ",Math.round(o.expiresIn/1e3/60)," minutes"]}),A("div",{children:[k("strong",{children:"Refresh Expires In:"})," ",Math.round(o.refreshExpiresIn/1e3/60/60)," hours"]}),A("div",{children:[k("strong",{children:"Expiring Soon:"})," ",o.isExpiringSoon?"Yes":"No"]})]})]}):k("div",{children:"Session not initialized"})}import{useState as F,useEffect as q,useCallback as Q,useRef as M}from"react";import Ee from"@nocios/crudify-browser";var nt=(o={})=>{let{autoFetch:t=!0,retryOnError:e=!1,maxRetries:r=3}=o,[i,u]=F(null),[E,h]=F(!1),[x,y]=F(null),[I,c]=F({}),s=M(null),n=M(!0),a=M(0),g=M(0),m=Q(()=>{u(null),y(null),h(!1),c({})},[]),p=Q(async()=>{let S=V();if(!S){n.current&&(y("No user email available"),h(!1));return}s.current&&s.current.abort();let N=new AbortController;s.current=N;let L=++a.current;try{n.current&&(h(!0),y(null));let b=await Ee.readItems("users",{filter:{email:S},pagination:{limit:1}});if(L===a.current&&n.current&&!N.signal.aborted)if(b.success&&b.data&&b.data.length>0){let d=b.data[0];u(d);let H={fullProfile:d,totalFields:Object.keys(d).length,displayData:{id:d.id,email:d.email,username:d.username,firstName:d.firstName,lastName:d.lastName,fullName:d.fullName||`${d.firstName||""} ${d.lastName||""}`.trim(),role:d.role,permissions:d.permissions||[],isActive:d.isActive,lastLogin:d.lastLogin,createdAt:d.createdAt,updatedAt:d.updatedAt,...Object.keys(d).filter(P=>!["id","email","username","firstName","lastName","fullName","role","permissions","isActive","lastLogin","createdAt","updatedAt"].includes(P)).reduce((P,z)=>({...P,[z]:d[z]}),{})}};c(H),y(null),g.current=0}else y("User profile not found"),u(null),c({})}catch(b){if(L===a.current&&n.current){let d=b;if(d.name==="AbortError")return;e&&g.current<r&&(d.message?.includes("Network Error")||d.message?.includes("Failed to fetch"))?(g.current++,setTimeout(()=>{n.current&&p()},1e3*g.current)):(y("Failed to load user profile"),u(null),c({}))}}finally{L===a.current&&n.current&&h(!1),s.current===N&&(s.current=null)}},[e,r]);return q(()=>{t&&p()},[t,p]),q(()=>(n.current=!0,()=>{n.current=!1,s.current&&(s.current.abort(),s.current=null)}),[]),{userProfile:i,loading:E,error:x,extendedData:I,refreshProfile:p,clearProfile:m}};export{f as a,O as b,Y as c,W as d,$ as e,Qe as f,ye as g,et as h,nt as i};
|