@nocios/crudify-ui 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1103,12 +1103,19 @@ declare function useSession(options?: UseSessionOptions): {
1103
1103
  error: string | null;
1104
1104
  };
1105
1105
 
1106
+ type SessionData = {
1107
+ _id: string;
1108
+ email: string;
1109
+ subscriberKey: string;
1110
+ [key: string]: any;
1111
+ } | null;
1106
1112
  type SessionContextType = {
1107
1113
  isAuthenticated: boolean;
1108
1114
  isLoading: boolean;
1109
1115
  isInitialized: boolean;
1110
1116
  tokens: TokenData | null;
1111
1117
  error: string | null;
1118
+ sessionData: SessionData;
1112
1119
  login: (email: string, password: string) => Promise<LoginResult>;
1113
1120
  logout: () => Promise<void>;
1114
1121
  refreshTokens: () => Promise<boolean>;
@@ -1150,4 +1157,177 @@ declare function LoginComponent(): react_jsx_runtime.JSX.Element;
1150
1157
  */
1151
1158
  declare function SessionStatus(): react_jsx_runtime.JSX.Element;
1152
1159
 
1153
- export { type ApiError, type BoxScreenType, type CrudifyApiResponse, type CrudifyConfig, type CrudifyDataContextState, CrudifyDataProvider, type CrudifyDataProviderProps, CrudifyLogin, type CrudifyLoginConfig, type CrudifyLoginProps, type CrudifyLoginTranslations, type CrudifyTransactionResponse, type CrudifyUserData, ERROR_CODES, ERROR_SEVERITY_MAP, type ErrorCode, type ErrorSeverity, type ForgotPasswordRequest, type JWTPayload$1 as JWTPayload, type JwtPayload, LoginComponent, type LoginRequest, type LoginResponse, type LoginResult, type ParsedError, ProtectedRoute, type ProtectedRouteProps, type ResetPasswordRequest, type ResolvedConfig, type SessionConfig, SessionDebugInfo, SessionManager, SessionProvider, type SessionProviderProps, type SessionState, SessionStatus, type StorageType, type TokenData, TokenStorage, type TransactionResponseData, type UseCrudifyAuthReturn, type UseCrudifyConfigReturn, type UseCrudifyDataReturn, type UseCrudifyInstanceReturn, type UseCrudifyUserOptions, type UseCrudifyUserReturn, type UseSessionOptions, type UserLoginData, type UserProfile, UserProfileDisplay, type ValidateCodeRequest, type ValidationError, configurationManager, crudifyInitializer, decodeJwtSafely, getCookie, getCrudifyInstanceAsync, getCrudifyInstanceSync, getCurrentUserEmail, getErrorMessage, handleCrudifyError, isTokenExpired, parseApiError, parseJavaScriptError, parseTransactionError, secureLocalStorage, secureSessionStorage, tokenManager, useCrudifyAuth, useCrudifyConfig, useCrudifyData, useCrudifyDataContext, useCrudifyInstance, useCrudifyLogin, useCrudifyUser, useSession, useSessionContext, useUserProfile };
1160
+ /**
1161
+ * Complete user data structure (compatible con legacy)
1162
+ */
1163
+ interface UserData {
1164
+ session: any | null;
1165
+ data: UserProfile | null;
1166
+ }
1167
+ /**
1168
+ * Return type compatible con useCrudifyUser legacy
1169
+ */
1170
+ interface UseUserDataReturn {
1171
+ user: UserData;
1172
+ loading: boolean;
1173
+ error: string | null;
1174
+ refreshProfile: () => Promise<void>;
1175
+ clearProfile: () => void;
1176
+ }
1177
+ /**
1178
+ * Options compatible con useCrudifyUser legacy
1179
+ */
1180
+ interface UseUserDataOptions {
1181
+ autoFetch?: boolean;
1182
+ retryOnError?: boolean;
1183
+ maxRetries?: number;
1184
+ }
1185
+ /**
1186
+ * useUserData - Hook completo que reemplaza useCrudifyUser del sistema legacy
1187
+ *
1188
+ * Funcionalidades completas:
1189
+ * - Auto-fetch de datos del usuario desde la base de datos
1190
+ * - Manejo inteligente de caché y deduplicación
1191
+ * - Mecanismo de retry para errores de red
1192
+ * - Sincronización cross-tab vía SessionProvider
1193
+ * - Formateo extendido de datos para display
1194
+ * - Limpieza apropiada y gestión de memoria
1195
+ * - Compatible 100% con API de useCrudifyUser legacy
1196
+ * - Usa el nuevo sistema de refresh tokens por debajo
1197
+ */
1198
+ declare const useUserData: (options?: UseUserDataOptions) => UseUserDataReturn;
1199
+
1200
+ /**
1201
+ * Return type compatible con useCrudifyAuth legacy
1202
+ */
1203
+ interface UseAuthReturn {
1204
+ isAuthenticated: boolean;
1205
+ loading: boolean;
1206
+ error: string | null;
1207
+ token: string | null;
1208
+ user: any | null;
1209
+ tokenExpiration: Date | null;
1210
+ setToken: (token: string | null) => void;
1211
+ logout: () => Promise<void>;
1212
+ refreshToken: () => Promise<boolean>;
1213
+ login: (email: string, password: string) => Promise<any>;
1214
+ isExpiringSoon: boolean;
1215
+ expiresIn: number;
1216
+ refreshExpiresIn: number;
1217
+ getTokenInfo: () => any;
1218
+ clearError: () => void;
1219
+ }
1220
+ /**
1221
+ * useAuth - Hook de autenticación completo
1222
+ *
1223
+ * Este hook reemplaza completamente a useCrudifyAuth del sistema legacy
1224
+ * manteniendo 100% compatibilidad de API pero usando el nuevo SessionProvider
1225
+ * que incluye Refresh Token Pattern, almacenamiento seguro, y gestión automática
1226
+ * de expiración de tokens.
1227
+ *
1228
+ * Funcionalidades completas:
1229
+ * - Estado de autenticación en tiempo real
1230
+ * - Validación automática de tokens
1231
+ * - Sincronización cross-tab
1232
+ * - Acciones simples login/logout
1233
+ * - Acceso al payload JWT vía sessionData
1234
+ * - Refresh automático de tokens
1235
+ * - Gestión de expiración de sesiones
1236
+ * - Almacenamiento seguro y encriptado
1237
+ * - Compatibilidad 100% con API legacy
1238
+ *
1239
+ * @example
1240
+ * ```tsx
1241
+ * function LoginComponent() {
1242
+ * const { isAuthenticated, login, logout, user } = useAuth();
1243
+ *
1244
+ * if (isAuthenticated) {
1245
+ * return (
1246
+ * <div>
1247
+ * Welcome {user?.email}!
1248
+ * <button onClick={logout}>Logout</button>
1249
+ * </div>
1250
+ * );
1251
+ * }
1252
+ *
1253
+ * return <LoginForm onLogin={login} />;
1254
+ * }
1255
+ * ```
1256
+ */
1257
+ declare const useAuth: () => UseAuthReturn;
1258
+
1259
+ /**
1260
+ * Return type compatible con useCrudifyData legacy
1261
+ */
1262
+ interface UseDataReturn {
1263
+ readItems: (moduleKey: string, filter?: object, options?: any) => Promise<CrudifyApiResponse>;
1264
+ readItem: (moduleKey: string, filter: object, options?: any) => Promise<CrudifyApiResponse>;
1265
+ createItem: (moduleKey: string, data: object, options?: any) => Promise<CrudifyApiResponse>;
1266
+ updateItem: (moduleKey: string, data: object, options?: any) => Promise<CrudifyApiResponse>;
1267
+ deleteItem: (moduleKey: string, id: string, options?: any) => Promise<CrudifyApiResponse>;
1268
+ transaction: (operations: any[], options?: any) => Promise<CrudifyApiResponse>;
1269
+ login: (email: string, password: string) => Promise<CrudifyApiResponse>;
1270
+ isInitialized: boolean;
1271
+ isInitializing: boolean;
1272
+ initializationError: string | null;
1273
+ isReady: () => boolean;
1274
+ waitForReady: () => Promise<void>;
1275
+ }
1276
+ /**
1277
+ * useData - Hook completo para operaciones de datos
1278
+ *
1279
+ * Este hook reemplaza completamente a useCrudifyData del sistema legacy
1280
+ * manteniendo 100% compatibilidad de API pero usando el nuevo SessionProvider
1281
+ * que proporciona mejor manejo de estados y errores.
1282
+ *
1283
+ * Funcionalidades completas:
1284
+ * - Verificación automática de inicialización
1285
+ * - Operaciones CRUD type-safe
1286
+ * - Soporte para transacciones
1287
+ * - Operaciones de login
1288
+ * - Gestión de estados ready
1289
+ * - Manejo apropiado de errores
1290
+ * - Compatible 100% con API legacy
1291
+ *
1292
+ * Todas las operaciones verifican que el sistema esté inicializado correctamente,
1293
+ * asegurando integridad de datos y previniendo fallas silenciosas.
1294
+ *
1295
+ * @example
1296
+ * ```tsx
1297
+ * function DataComponent() {
1298
+ * const {
1299
+ * readItems,
1300
+ * createItem,
1301
+ * isInitialized,
1302
+ * isReady
1303
+ * } = useData();
1304
+ *
1305
+ * const loadUsers = async () => {
1306
+ * if (!isReady()) {
1307
+ * console.warn("System not ready yet");
1308
+ * return;
1309
+ * }
1310
+ *
1311
+ * try {
1312
+ * const response = await readItems("users", { limit: 10 });
1313
+ * if (response.success) {
1314
+ * console.log("Users:", response.data);
1315
+ * }
1316
+ * } catch (error) {
1317
+ * console.error("Error loading users:", error);
1318
+ * }
1319
+ * };
1320
+ *
1321
+ * return (
1322
+ * <div>
1323
+ * <button onClick={loadUsers} disabled={!isInitialized}>
1324
+ * Load Users
1325
+ * </button>
1326
+ * </div>
1327
+ * );
1328
+ * }
1329
+ * ```
1330
+ */
1331
+ declare const useData: () => UseDataReturn;
1332
+
1333
+ export { type ApiError, type BoxScreenType, type CrudifyApiResponse, type CrudifyConfig, type CrudifyDataContextState, CrudifyDataProvider, type CrudifyDataProviderProps, CrudifyLogin, type CrudifyLoginConfig, type CrudifyLoginProps, type CrudifyLoginTranslations, type CrudifyTransactionResponse, type CrudifyUserData, ERROR_CODES, ERROR_SEVERITY_MAP, type ErrorCode, type ErrorSeverity, type ForgotPasswordRequest, type JWTPayload$1 as JWTPayload, type JwtPayload, LoginComponent, type LoginRequest, type LoginResponse, type LoginResult, type ParsedError, ProtectedRoute, type ProtectedRouteProps, type ResetPasswordRequest, type ResolvedConfig, type SessionConfig, SessionDebugInfo, SessionManager, SessionProvider, type SessionProviderProps, type SessionState, SessionStatus, type StorageType, type TokenData, TokenStorage, type TransactionResponseData, type UseAuthReturn, type UseCrudifyAuthReturn, type UseCrudifyConfigReturn, type UseCrudifyDataReturn, type UseCrudifyInstanceReturn, type UseCrudifyUserOptions, type UseCrudifyUserReturn, type UseDataReturn, type UseSessionOptions, type UseUserDataOptions, type UseUserDataReturn, type UserData, type UserLoginData, type UserProfile, UserProfileDisplay, type ValidateCodeRequest, type ValidationError, configurationManager, crudifyInitializer, decodeJwtSafely, getCookie, getCrudifyInstanceAsync, getCrudifyInstanceSync, getCurrentUserEmail, getErrorMessage, handleCrudifyError, isTokenExpired, parseApiError, parseJavaScriptError, parseTransactionError, secureLocalStorage, secureSessionStorage, tokenManager, useAuth, useCrudifyAuth, useCrudifyConfig, useCrudifyData, useCrudifyDataContext, useCrudifyInstance, useCrudifyLogin, useCrudifyUser, useData, useSession, useSessionContext, useUserData, useUserProfile };
package/dist/index.d.ts CHANGED
@@ -1103,12 +1103,19 @@ declare function useSession(options?: UseSessionOptions): {
1103
1103
  error: string | null;
1104
1104
  };
1105
1105
 
1106
+ type SessionData = {
1107
+ _id: string;
1108
+ email: string;
1109
+ subscriberKey: string;
1110
+ [key: string]: any;
1111
+ } | null;
1106
1112
  type SessionContextType = {
1107
1113
  isAuthenticated: boolean;
1108
1114
  isLoading: boolean;
1109
1115
  isInitialized: boolean;
1110
1116
  tokens: TokenData | null;
1111
1117
  error: string | null;
1118
+ sessionData: SessionData;
1112
1119
  login: (email: string, password: string) => Promise<LoginResult>;
1113
1120
  logout: () => Promise<void>;
1114
1121
  refreshTokens: () => Promise<boolean>;
@@ -1150,4 +1157,177 @@ declare function LoginComponent(): react_jsx_runtime.JSX.Element;
1150
1157
  */
1151
1158
  declare function SessionStatus(): react_jsx_runtime.JSX.Element;
1152
1159
 
1153
- export { type ApiError, type BoxScreenType, type CrudifyApiResponse, type CrudifyConfig, type CrudifyDataContextState, CrudifyDataProvider, type CrudifyDataProviderProps, CrudifyLogin, type CrudifyLoginConfig, type CrudifyLoginProps, type CrudifyLoginTranslations, type CrudifyTransactionResponse, type CrudifyUserData, ERROR_CODES, ERROR_SEVERITY_MAP, type ErrorCode, type ErrorSeverity, type ForgotPasswordRequest, type JWTPayload$1 as JWTPayload, type JwtPayload, LoginComponent, type LoginRequest, type LoginResponse, type LoginResult, type ParsedError, ProtectedRoute, type ProtectedRouteProps, type ResetPasswordRequest, type ResolvedConfig, type SessionConfig, SessionDebugInfo, SessionManager, SessionProvider, type SessionProviderProps, type SessionState, SessionStatus, type StorageType, type TokenData, TokenStorage, type TransactionResponseData, type UseCrudifyAuthReturn, type UseCrudifyConfigReturn, type UseCrudifyDataReturn, type UseCrudifyInstanceReturn, type UseCrudifyUserOptions, type UseCrudifyUserReturn, type UseSessionOptions, type UserLoginData, type UserProfile, UserProfileDisplay, type ValidateCodeRequest, type ValidationError, configurationManager, crudifyInitializer, decodeJwtSafely, getCookie, getCrudifyInstanceAsync, getCrudifyInstanceSync, getCurrentUserEmail, getErrorMessage, handleCrudifyError, isTokenExpired, parseApiError, parseJavaScriptError, parseTransactionError, secureLocalStorage, secureSessionStorage, tokenManager, useCrudifyAuth, useCrudifyConfig, useCrudifyData, useCrudifyDataContext, useCrudifyInstance, useCrudifyLogin, useCrudifyUser, useSession, useSessionContext, useUserProfile };
1160
+ /**
1161
+ * Complete user data structure (compatible con legacy)
1162
+ */
1163
+ interface UserData {
1164
+ session: any | null;
1165
+ data: UserProfile | null;
1166
+ }
1167
+ /**
1168
+ * Return type compatible con useCrudifyUser legacy
1169
+ */
1170
+ interface UseUserDataReturn {
1171
+ user: UserData;
1172
+ loading: boolean;
1173
+ error: string | null;
1174
+ refreshProfile: () => Promise<void>;
1175
+ clearProfile: () => void;
1176
+ }
1177
+ /**
1178
+ * Options compatible con useCrudifyUser legacy
1179
+ */
1180
+ interface UseUserDataOptions {
1181
+ autoFetch?: boolean;
1182
+ retryOnError?: boolean;
1183
+ maxRetries?: number;
1184
+ }
1185
+ /**
1186
+ * useUserData - Hook completo que reemplaza useCrudifyUser del sistema legacy
1187
+ *
1188
+ * Funcionalidades completas:
1189
+ * - Auto-fetch de datos del usuario desde la base de datos
1190
+ * - Manejo inteligente de caché y deduplicación
1191
+ * - Mecanismo de retry para errores de red
1192
+ * - Sincronización cross-tab vía SessionProvider
1193
+ * - Formateo extendido de datos para display
1194
+ * - Limpieza apropiada y gestión de memoria
1195
+ * - Compatible 100% con API de useCrudifyUser legacy
1196
+ * - Usa el nuevo sistema de refresh tokens por debajo
1197
+ */
1198
+ declare const useUserData: (options?: UseUserDataOptions) => UseUserDataReturn;
1199
+
1200
+ /**
1201
+ * Return type compatible con useCrudifyAuth legacy
1202
+ */
1203
+ interface UseAuthReturn {
1204
+ isAuthenticated: boolean;
1205
+ loading: boolean;
1206
+ error: string | null;
1207
+ token: string | null;
1208
+ user: any | null;
1209
+ tokenExpiration: Date | null;
1210
+ setToken: (token: string | null) => void;
1211
+ logout: () => Promise<void>;
1212
+ refreshToken: () => Promise<boolean>;
1213
+ login: (email: string, password: string) => Promise<any>;
1214
+ isExpiringSoon: boolean;
1215
+ expiresIn: number;
1216
+ refreshExpiresIn: number;
1217
+ getTokenInfo: () => any;
1218
+ clearError: () => void;
1219
+ }
1220
+ /**
1221
+ * useAuth - Hook de autenticación completo
1222
+ *
1223
+ * Este hook reemplaza completamente a useCrudifyAuth del sistema legacy
1224
+ * manteniendo 100% compatibilidad de API pero usando el nuevo SessionProvider
1225
+ * que incluye Refresh Token Pattern, almacenamiento seguro, y gestión automática
1226
+ * de expiración de tokens.
1227
+ *
1228
+ * Funcionalidades completas:
1229
+ * - Estado de autenticación en tiempo real
1230
+ * - Validación automática de tokens
1231
+ * - Sincronización cross-tab
1232
+ * - Acciones simples login/logout
1233
+ * - Acceso al payload JWT vía sessionData
1234
+ * - Refresh automático de tokens
1235
+ * - Gestión de expiración de sesiones
1236
+ * - Almacenamiento seguro y encriptado
1237
+ * - Compatibilidad 100% con API legacy
1238
+ *
1239
+ * @example
1240
+ * ```tsx
1241
+ * function LoginComponent() {
1242
+ * const { isAuthenticated, login, logout, user } = useAuth();
1243
+ *
1244
+ * if (isAuthenticated) {
1245
+ * return (
1246
+ * <div>
1247
+ * Welcome {user?.email}!
1248
+ * <button onClick={logout}>Logout</button>
1249
+ * </div>
1250
+ * );
1251
+ * }
1252
+ *
1253
+ * return <LoginForm onLogin={login} />;
1254
+ * }
1255
+ * ```
1256
+ */
1257
+ declare const useAuth: () => UseAuthReturn;
1258
+
1259
+ /**
1260
+ * Return type compatible con useCrudifyData legacy
1261
+ */
1262
+ interface UseDataReturn {
1263
+ readItems: (moduleKey: string, filter?: object, options?: any) => Promise<CrudifyApiResponse>;
1264
+ readItem: (moduleKey: string, filter: object, options?: any) => Promise<CrudifyApiResponse>;
1265
+ createItem: (moduleKey: string, data: object, options?: any) => Promise<CrudifyApiResponse>;
1266
+ updateItem: (moduleKey: string, data: object, options?: any) => Promise<CrudifyApiResponse>;
1267
+ deleteItem: (moduleKey: string, id: string, options?: any) => Promise<CrudifyApiResponse>;
1268
+ transaction: (operations: any[], options?: any) => Promise<CrudifyApiResponse>;
1269
+ login: (email: string, password: string) => Promise<CrudifyApiResponse>;
1270
+ isInitialized: boolean;
1271
+ isInitializing: boolean;
1272
+ initializationError: string | null;
1273
+ isReady: () => boolean;
1274
+ waitForReady: () => Promise<void>;
1275
+ }
1276
+ /**
1277
+ * useData - Hook completo para operaciones de datos
1278
+ *
1279
+ * Este hook reemplaza completamente a useCrudifyData del sistema legacy
1280
+ * manteniendo 100% compatibilidad de API pero usando el nuevo SessionProvider
1281
+ * que proporciona mejor manejo de estados y errores.
1282
+ *
1283
+ * Funcionalidades completas:
1284
+ * - Verificación automática de inicialización
1285
+ * - Operaciones CRUD type-safe
1286
+ * - Soporte para transacciones
1287
+ * - Operaciones de login
1288
+ * - Gestión de estados ready
1289
+ * - Manejo apropiado de errores
1290
+ * - Compatible 100% con API legacy
1291
+ *
1292
+ * Todas las operaciones verifican que el sistema esté inicializado correctamente,
1293
+ * asegurando integridad de datos y previniendo fallas silenciosas.
1294
+ *
1295
+ * @example
1296
+ * ```tsx
1297
+ * function DataComponent() {
1298
+ * const {
1299
+ * readItems,
1300
+ * createItem,
1301
+ * isInitialized,
1302
+ * isReady
1303
+ * } = useData();
1304
+ *
1305
+ * const loadUsers = async () => {
1306
+ * if (!isReady()) {
1307
+ * console.warn("System not ready yet");
1308
+ * return;
1309
+ * }
1310
+ *
1311
+ * try {
1312
+ * const response = await readItems("users", { limit: 10 });
1313
+ * if (response.success) {
1314
+ * console.log("Users:", response.data);
1315
+ * }
1316
+ * } catch (error) {
1317
+ * console.error("Error loading users:", error);
1318
+ * }
1319
+ * };
1320
+ *
1321
+ * return (
1322
+ * <div>
1323
+ * <button onClick={loadUsers} disabled={!isInitialized}>
1324
+ * Load Users
1325
+ * </button>
1326
+ * </div>
1327
+ * );
1328
+ * }
1329
+ * ```
1330
+ */
1331
+ declare const useData: () => UseDataReturn;
1332
+
1333
+ export { type ApiError, type BoxScreenType, type CrudifyApiResponse, type CrudifyConfig, type CrudifyDataContextState, CrudifyDataProvider, type CrudifyDataProviderProps, CrudifyLogin, type CrudifyLoginConfig, type CrudifyLoginProps, type CrudifyLoginTranslations, type CrudifyTransactionResponse, type CrudifyUserData, ERROR_CODES, ERROR_SEVERITY_MAP, type ErrorCode, type ErrorSeverity, type ForgotPasswordRequest, type JWTPayload$1 as JWTPayload, type JwtPayload, LoginComponent, type LoginRequest, type LoginResponse, type LoginResult, type ParsedError, ProtectedRoute, type ProtectedRouteProps, type ResetPasswordRequest, type ResolvedConfig, type SessionConfig, SessionDebugInfo, SessionManager, SessionProvider, type SessionProviderProps, type SessionState, SessionStatus, type StorageType, type TokenData, TokenStorage, type TransactionResponseData, type UseAuthReturn, type UseCrudifyAuthReturn, type UseCrudifyConfigReturn, type UseCrudifyDataReturn, type UseCrudifyInstanceReturn, type UseCrudifyUserOptions, type UseCrudifyUserReturn, type UseDataReturn, type UseSessionOptions, type UseUserDataOptions, type UseUserDataReturn, type UserData, type UserLoginData, type UserProfile, UserProfileDisplay, type ValidateCodeRequest, type ValidationError, configurationManager, crudifyInitializer, decodeJwtSafely, getCookie, getCrudifyInstanceAsync, getCrudifyInstanceSync, getCurrentUserEmail, getErrorMessage, handleCrudifyError, isTokenExpired, parseApiError, parseJavaScriptError, parseTransactionError, secureLocalStorage, secureSessionStorage, tokenManager, useAuth, useCrudifyAuth, useCrudifyConfig, useCrudifyData, useCrudifyDataContext, useCrudifyInstance, useCrudifyLogin, useCrudifyUser, useData, useSession, useSessionContext, useUserData, useUserProfile };