@nocios/crudify-ui 1.2.36 → 1.3.0
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/MIGRATION-GUIDE.md +312 -0
- package/dist/index.d.mts +234 -1
- package/dist/index.d.ts +234 -1
- package/dist/index.js +856 -18
- package/dist/index.mjs +845 -16
- package/example-app.tsx +197 -0
- package/package.json +2 -2
package/example-app.tsx
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// =============================
|
|
2
|
+
// EXAMPLE APP - REFRESH TOKEN PATTERN
|
|
3
|
+
// =============================
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Ejemplo completo de aplicación usando el Refresh Token Pattern
|
|
7
|
+
* Demuestra todas las características nuevas de crudify-ui v1.2+
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import ReactDOM from 'react-dom/client';
|
|
12
|
+
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
|
13
|
+
import { CssBaseline, Container, AppBar, Toolbar, Typography, Box } from '@mui/material';
|
|
14
|
+
import {
|
|
15
|
+
SessionProvider,
|
|
16
|
+
LoginComponent,
|
|
17
|
+
SessionStatus,
|
|
18
|
+
SessionDebugInfo,
|
|
19
|
+
useSessionContext,
|
|
20
|
+
ProtectedRoute
|
|
21
|
+
} from '@nocios/crudify-ui';
|
|
22
|
+
|
|
23
|
+
const theme = createTheme();
|
|
24
|
+
|
|
25
|
+
// Componente de aplicación principal
|
|
26
|
+
function App() {
|
|
27
|
+
return (
|
|
28
|
+
<ThemeProvider theme={theme}>
|
|
29
|
+
<CssBaseline />
|
|
30
|
+
|
|
31
|
+
{/* Envolver toda la app con SessionProvider */}
|
|
32
|
+
<SessionProvider
|
|
33
|
+
options={{
|
|
34
|
+
autoRestore: true, // Restaurar sesión automáticamente
|
|
35
|
+
enableLogging: true, // Logs para debug
|
|
36
|
+
onSessionExpired: () => { // Callback cuando expira la sesión
|
|
37
|
+
console.log('Session expired - redirecting to login');
|
|
38
|
+
// Aquí podrías hacer redirect, mostrar modal, etc.
|
|
39
|
+
},
|
|
40
|
+
onSessionRestored: (tokens) => {
|
|
41
|
+
console.log('Session restored successfully:', tokens);
|
|
42
|
+
}
|
|
43
|
+
}}
|
|
44
|
+
>
|
|
45
|
+
<AppContent />
|
|
46
|
+
</SessionProvider>
|
|
47
|
+
</ThemeProvider>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Contenido principal de la aplicación
|
|
52
|
+
function AppContent() {
|
|
53
|
+
return (
|
|
54
|
+
<>
|
|
55
|
+
{/* App Bar */}
|
|
56
|
+
<AppBar position="static">
|
|
57
|
+
<Toolbar>
|
|
58
|
+
<Typography variant="h6" component="div" sx={{ flexGrow: 1 }}>
|
|
59
|
+
Crudify Refresh Token Demo
|
|
60
|
+
</Typography>
|
|
61
|
+
<SessionStatus />
|
|
62
|
+
</Toolbar>
|
|
63
|
+
</AppBar>
|
|
64
|
+
|
|
65
|
+
{/* Contenido principal */}
|
|
66
|
+
<Container maxWidth="lg" sx={{ mt: 4, mb: 4 }}>
|
|
67
|
+
<LoginComponent />
|
|
68
|
+
|
|
69
|
+
{/* Área protegida - solo visible si está autenticado */}
|
|
70
|
+
<ProtectedRoute fallback={null}>
|
|
71
|
+
<ProtectedArea />
|
|
72
|
+
</ProtectedRoute>
|
|
73
|
+
|
|
74
|
+
{/* Debug info (solo en desarrollo) */}
|
|
75
|
+
{process.env.NODE_ENV === 'development' && (
|
|
76
|
+
<SessionDebugInfo />
|
|
77
|
+
)}
|
|
78
|
+
</Container>
|
|
79
|
+
</>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Área protegida de la aplicación
|
|
84
|
+
function ProtectedArea() {
|
|
85
|
+
const { refreshTokens, isExpiringSoon } = useSessionContext();
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<Box sx={{ mt: 4, p: 3, bgcolor: 'background.paper', borderRadius: 1 }}>
|
|
89
|
+
<Typography variant="h5" gutterBottom>
|
|
90
|
+
Protected Area 🔒
|
|
91
|
+
</Typography>
|
|
92
|
+
|
|
93
|
+
<Typography variant="body1" paragraph>
|
|
94
|
+
This content is only visible to authenticated users. The session is managed
|
|
95
|
+
automatically with the Refresh Token Pattern.
|
|
96
|
+
</Typography>
|
|
97
|
+
|
|
98
|
+
{isExpiringSoon && (
|
|
99
|
+
<Box sx={{ mb: 2, p: 2, bgcolor: 'warning.light', borderRadius: 1 }}>
|
|
100
|
+
<Typography variant="body2">
|
|
101
|
+
⚠️ Your token is expiring soon, but don't worry - it will be refreshed automatically!
|
|
102
|
+
</Typography>
|
|
103
|
+
</Box>
|
|
104
|
+
)}
|
|
105
|
+
|
|
106
|
+
{/* Ejemplo de uso de CRUD operations */}
|
|
107
|
+
<CrudOperationsExample />
|
|
108
|
+
</Box>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Ejemplo de operaciones CRUD con auto-refresh
|
|
113
|
+
function CrudOperationsExample() {
|
|
114
|
+
const [data, setData] = React.useState(null);
|
|
115
|
+
const [loading, setLoading] = React.useState(false);
|
|
116
|
+
const [error, setError] = React.useState(null);
|
|
117
|
+
|
|
118
|
+
// Importar crudify
|
|
119
|
+
const crudify = React.useMemo(() => {
|
|
120
|
+
// En una app real, ya estaría inicializado
|
|
121
|
+
import('@nocios/crudify-browser').then(module => module.default);
|
|
122
|
+
}, []);
|
|
123
|
+
|
|
124
|
+
const fetchData = async () => {
|
|
125
|
+
setLoading(true);
|
|
126
|
+
setError(null);
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
// Esta operación usará automáticamente el auto-refresh si es necesario
|
|
130
|
+
const result = await crudify.getPermissions();
|
|
131
|
+
|
|
132
|
+
if (result.success) {
|
|
133
|
+
setData(result.data);
|
|
134
|
+
} else {
|
|
135
|
+
setError('Failed to fetch data: ' + JSON.stringify(result.errors));
|
|
136
|
+
}
|
|
137
|
+
} catch (err) {
|
|
138
|
+
setError('Network error: ' + err.message);
|
|
139
|
+
} finally {
|
|
140
|
+
setLoading(false);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<Box sx={{ mt: 3 }}>
|
|
146
|
+
<Typography variant="h6" gutterBottom>
|
|
147
|
+
CRUD Operations with Auto-Refresh
|
|
148
|
+
</Typography>
|
|
149
|
+
|
|
150
|
+
<button onClick={fetchData} disabled={loading}>
|
|
151
|
+
{loading ? 'Loading...' : 'Fetch Permissions (Test Auto-Refresh)'}
|
|
152
|
+
</button>
|
|
153
|
+
|
|
154
|
+
{error && (
|
|
155
|
+
<Box sx={{ mt: 2, p: 2, bgcolor: 'error.light', borderRadius: 1 }}>
|
|
156
|
+
<Typography variant="body2" color="error">
|
|
157
|
+
{error}
|
|
158
|
+
</Typography>
|
|
159
|
+
</Box>
|
|
160
|
+
)}
|
|
161
|
+
|
|
162
|
+
{data && (
|
|
163
|
+
<Box sx={{ mt: 2, p: 2, bgcolor: 'success.light', borderRadius: 1 }}>
|
|
164
|
+
<Typography variant="body2">
|
|
165
|
+
✅ Data fetched successfully! Auto-refresh is working.
|
|
166
|
+
</Typography>
|
|
167
|
+
<pre style={{ fontSize: '12px', marginTop: '8px' }}>
|
|
168
|
+
{JSON.stringify(data, null, 2)}
|
|
169
|
+
</pre>
|
|
170
|
+
</Box>
|
|
171
|
+
)}
|
|
172
|
+
</Box>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// =============================
|
|
177
|
+
// BOOTSTRAP DE LA APLICACIÓN
|
|
178
|
+
// =============================
|
|
179
|
+
|
|
180
|
+
// Para usar este ejemplo:
|
|
181
|
+
// 1. npm install @nocios/crudify-ui@^1.2.0
|
|
182
|
+
// 2. Configurar crudify con tu API key antes de renderizar
|
|
183
|
+
// 3. Renderizar la aplicación
|
|
184
|
+
|
|
185
|
+
export default App;
|
|
186
|
+
|
|
187
|
+
// Ejemplo de inicialización
|
|
188
|
+
/*
|
|
189
|
+
import { crudify } from '@nocios/crudify-ui';
|
|
190
|
+
|
|
191
|
+
// Configurar crudify antes de renderizar la app
|
|
192
|
+
await crudify.init('your-api-key', 'debug');
|
|
193
|
+
|
|
194
|
+
// Renderizar la aplicación
|
|
195
|
+
const root = ReactDOM.createRoot(document.getElementById('root')!);
|
|
196
|
+
root.render(<App />);
|
|
197
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocios/crudify-ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Biblioteca de componentes UI para Crudify",
|
|
5
5
|
"author": "Nocios",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@mui/icons-material": "^7.1.0",
|
|
26
26
|
"@mui/material": "^7.1.0",
|
|
27
27
|
"@mui/x-data-grid": "^8.5.1",
|
|
28
|
-
"@nocios/crudify-browser": "^1.0
|
|
28
|
+
"@nocios/crudify-browser": "^1.1.0",
|
|
29
29
|
"crypto-js": "^4.2.0",
|
|
30
30
|
"i18next-browser-languagedetector": "^8.1.0",
|
|
31
31
|
"i18next-http-backend": "^3.0.2",
|