@nocios/crudify-ui 1.2.28 → 1.2.32
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.md +201 -0
- package/dist/{CrudifyDataProvider-VQUGF4OL.mjs → CrudifyDataProvider-5GXGNQKI.mjs} +4 -2
- package/dist/TokenManager-AYUNIXQU.mjs +8 -0
- package/dist/{chunk-UAYA54B3.mjs → chunk-GY5F6KOF.mjs} +40 -510
- package/dist/chunk-M7V4UGCN.mjs +512 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +67 -13
- package/dist/index.mjs +24 -8
- package/package.json +1 -1
package/MIGRATION.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# Guía de Migración - useCrudifyUser v1.2.25+
|
|
2
|
+
|
|
3
|
+
## Cambios Importantes
|
|
4
|
+
|
|
5
|
+
A partir de la versión 1.2.25, el hook `useCrudifyUser` ha sido completamente reestructurado para ser más simple y claro.
|
|
6
|
+
|
|
7
|
+
## Antes (❌ Estructura Anterior)
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
const {
|
|
11
|
+
userEmail,
|
|
12
|
+
userId,
|
|
13
|
+
userIdentifier,
|
|
14
|
+
userProfile,
|
|
15
|
+
profileLoading,
|
|
16
|
+
profileError,
|
|
17
|
+
extendedData,
|
|
18
|
+
refreshProfile,
|
|
19
|
+
clearProfile
|
|
20
|
+
} = useCrudifyUser();
|
|
21
|
+
|
|
22
|
+
// Acceso a datos
|
|
23
|
+
console.log(extendedData.fullProfile);
|
|
24
|
+
console.log(extendedData.displayData);
|
|
25
|
+
console.log(extendedData.totalFields);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Ahora (✅ Nueva Estructura)
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
const {
|
|
32
|
+
user,
|
|
33
|
+
loading,
|
|
34
|
+
error,
|
|
35
|
+
refreshProfile,
|
|
36
|
+
clearProfile
|
|
37
|
+
} = useCrudifyUser();
|
|
38
|
+
|
|
39
|
+
// Acceso a datos
|
|
40
|
+
console.log(user.session); // Datos del JWT token
|
|
41
|
+
console.log(user.data); // Datos de la base de datos
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Estructura del objeto `user`
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
interface CrudifyUserData {
|
|
48
|
+
session: JWTPayload | null; // Datos del token JWT
|
|
49
|
+
data: UserProfile | null; // Datos de la base de datos
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### `user.session` (Datos del JWT)
|
|
54
|
+
- `user.session.sub` - User ID
|
|
55
|
+
- `user.session.email` - Email del usuario
|
|
56
|
+
- `user.session.name` - Nombre del usuario
|
|
57
|
+
- `user.session.exp` - Timestamp de expiración
|
|
58
|
+
- `user.session.iat` - Timestamp de emisión
|
|
59
|
+
- Y todos los demás campos del JWT token
|
|
60
|
+
|
|
61
|
+
### `user.data` (Datos de la Base de Datos)
|
|
62
|
+
- `user.data.id` - ID del perfil en la BD
|
|
63
|
+
- `user.data.email` - Email del perfil
|
|
64
|
+
- `user.data.firstName` - Nombre
|
|
65
|
+
- `user.data.lastName` - Apellido
|
|
66
|
+
- `user.data.role` - Rol del usuario
|
|
67
|
+
- Y todos los demás campos del perfil de usuario
|
|
68
|
+
|
|
69
|
+
## Migraciones Necesarias
|
|
70
|
+
|
|
71
|
+
### 1. Cambiar las destructuraciones
|
|
72
|
+
```typescript
|
|
73
|
+
// ❌ Antes
|
|
74
|
+
const { userProfile, profileLoading, profileError } = useCrudifyUser();
|
|
75
|
+
|
|
76
|
+
// ✅ Ahora
|
|
77
|
+
const { user, loading, error } = useCrudifyUser();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 2. Actualizar acceso a datos de sesión
|
|
81
|
+
```typescript
|
|
82
|
+
// ❌ Antes
|
|
83
|
+
const email = userEmail;
|
|
84
|
+
const userId = userId;
|
|
85
|
+
|
|
86
|
+
// ✅ Ahora
|
|
87
|
+
const email = user.session?.email;
|
|
88
|
+
const userId = user.session?.sub;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 3. Actualizar acceso a datos de perfil
|
|
92
|
+
```typescript
|
|
93
|
+
// ❌ Antes
|
|
94
|
+
const profileData = userProfile;
|
|
95
|
+
const fullName = extendedData.displayData.fullName;
|
|
96
|
+
|
|
97
|
+
// ✅ Ahora
|
|
98
|
+
const profileData = user.data;
|
|
99
|
+
const fullName = user.data?.fullName;
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 4. Actualizar estados de carga y error
|
|
103
|
+
```typescript
|
|
104
|
+
// ❌ Antes
|
|
105
|
+
if (profileLoading) return <Loading />;
|
|
106
|
+
if (profileError) return <Error message={profileError} />;
|
|
107
|
+
|
|
108
|
+
// ✅ Ahora
|
|
109
|
+
if (loading) return <Loading />;
|
|
110
|
+
if (error) return <Error message={error} />;
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Beneficios de la Nueva Estructura
|
|
114
|
+
|
|
115
|
+
1. **Más Simple**: Solo un objeto `user` con `session` y `data`
|
|
116
|
+
2. **Más Claro**: Es obvio qué viene del JWT (`session`) y qué de la DB (`data`)
|
|
117
|
+
3. **Sin Duplicación**: La información no se repite en múltiples lugares
|
|
118
|
+
4. **Mejor TypeScript**: Tipos más precisos y claros
|
|
119
|
+
5. **Más Fácil de Usar**: Los desarrolladores entienden inmediatamente la estructura
|
|
120
|
+
|
|
121
|
+
## Ejemplo Completo de Migración
|
|
122
|
+
|
|
123
|
+
### Antes
|
|
124
|
+
```tsx
|
|
125
|
+
function UserProfile() {
|
|
126
|
+
const {
|
|
127
|
+
userEmail,
|
|
128
|
+
userProfile,
|
|
129
|
+
profileLoading,
|
|
130
|
+
profileError,
|
|
131
|
+
extendedData,
|
|
132
|
+
refreshProfile
|
|
133
|
+
} = useCrudifyUser();
|
|
134
|
+
|
|
135
|
+
if (profileLoading) return <div>Cargando...</div>;
|
|
136
|
+
if (profileError) return <div>Error: {profileError}</div>;
|
|
137
|
+
|
|
138
|
+
return (
|
|
139
|
+
<div>
|
|
140
|
+
<h1>Welcome {userProfile?.fullName || userEmail}</h1>
|
|
141
|
+
<p>Total fields: {extendedData.totalFields}</p>
|
|
142
|
+
<pre>{JSON.stringify(extendedData.displayData, null, 2)}</pre>
|
|
143
|
+
<button onClick={refreshProfile}>Refresh</button>
|
|
144
|
+
</div>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Después
|
|
150
|
+
```tsx
|
|
151
|
+
function UserProfile() {
|
|
152
|
+
const {
|
|
153
|
+
user,
|
|
154
|
+
loading,
|
|
155
|
+
error,
|
|
156
|
+
refreshProfile
|
|
157
|
+
} = useCrudifyUser();
|
|
158
|
+
|
|
159
|
+
if (loading) return <div>Cargando...</div>;
|
|
160
|
+
if (error) return <div>Error: {error}</div>;
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<div>
|
|
164
|
+
<h1>Welcome {user.data?.fullName || user.session?.email}</h1>
|
|
165
|
+
<h2>Datos de Sesión:</h2>
|
|
166
|
+
<pre>{JSON.stringify(user.session, null, 2)}</pre>
|
|
167
|
+
<h2>Datos de Perfil:</h2>
|
|
168
|
+
<pre>{JSON.stringify(user.data, null, 2)}</pre>
|
|
169
|
+
<button onClick={refreshProfile}>Refresh</button>
|
|
170
|
+
</div>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Retrocompatibilidad
|
|
176
|
+
|
|
177
|
+
Para mantener compatibilidad temporal, puedes crear un wrapper:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
// wrapper temporal para compatibilidad
|
|
181
|
+
export const useLegacyUserProfile = () => {
|
|
182
|
+
const { user, loading, error, refreshProfile, clearProfile } = useCrudifyUser();
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
userEmail: user.session?.email || null,
|
|
186
|
+
userId: user.session?.sub || null,
|
|
187
|
+
userProfile: user.data,
|
|
188
|
+
profileLoading: loading,
|
|
189
|
+
profileError: error,
|
|
190
|
+
extendedData: {
|
|
191
|
+
fullProfile: user.data,
|
|
192
|
+
displayData: user.data,
|
|
193
|
+
totalFields: user.data ? Object.keys(user.data).length : 0
|
|
194
|
+
},
|
|
195
|
+
refreshProfile,
|
|
196
|
+
clearProfile
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
**Nota**: Este wrapper es solo para facilitar la migración. Se recomienda migrar completamente a la nueva estructura.
|
|
@@ -2,9 +2,11 @@ import {
|
|
|
2
2
|
CrudifyDataProvider,
|
|
3
3
|
configurationManager,
|
|
4
4
|
crudifyInitializer,
|
|
5
|
-
tokenManager,
|
|
6
5
|
useCrudifyDataContext
|
|
7
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-GY5F6KOF.mjs";
|
|
7
|
+
import {
|
|
8
|
+
tokenManager
|
|
9
|
+
} from "./chunk-M7V4UGCN.mjs";
|
|
8
10
|
export {
|
|
9
11
|
CrudifyDataProvider,
|
|
10
12
|
configurationManager,
|