@nocios/crudify-ui 1.2.34 → 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 +862 -18
- package/dist/index.mjs +851 -16
- package/example-app.tsx +197 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import crudify__default from '@nocios/crudify-browser';
|
|
|
2
2
|
export * from '@nocios/crudify-browser';
|
|
3
3
|
export { default as crudify } from '@nocios/crudify-browser';
|
|
4
4
|
import React, { ReactNode } from 'react';
|
|
5
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
6
|
|
|
6
7
|
type BoxScreenType = "login" | "signUp" | "forgotPassword" | "resetPassword" | "checkCode";
|
|
7
8
|
interface CrudifyLoginConfig {
|
|
@@ -917,4 +918,236 @@ declare function parseJavaScriptError(error: unknown): ParsedError;
|
|
|
917
918
|
*/
|
|
918
919
|
declare function handleCrudifyError(error: unknown): ParsedError[];
|
|
919
920
|
|
|
920
|
-
|
|
921
|
+
type TokenData = {
|
|
922
|
+
accessToken: string;
|
|
923
|
+
refreshToken: string;
|
|
924
|
+
expiresAt: number;
|
|
925
|
+
refreshExpiresAt: number;
|
|
926
|
+
};
|
|
927
|
+
type StorageType = 'localStorage' | 'sessionStorage' | 'none';
|
|
928
|
+
declare class TokenStorage {
|
|
929
|
+
private static readonly TOKEN_KEY;
|
|
930
|
+
private static readonly ENCRYPTION_KEY;
|
|
931
|
+
private static storageType;
|
|
932
|
+
/**
|
|
933
|
+
* Configurar tipo de almacenamiento
|
|
934
|
+
*/
|
|
935
|
+
static setStorageType(type: StorageType): void;
|
|
936
|
+
/**
|
|
937
|
+
* Verificar si el storage está disponible
|
|
938
|
+
*/
|
|
939
|
+
private static isStorageAvailable;
|
|
940
|
+
/**
|
|
941
|
+
* Obtener instancia de storage
|
|
942
|
+
*/
|
|
943
|
+
private static getStorage;
|
|
944
|
+
/**
|
|
945
|
+
* Encriptar datos sensibles
|
|
946
|
+
*/
|
|
947
|
+
private static encrypt;
|
|
948
|
+
/**
|
|
949
|
+
* Desencriptar datos
|
|
950
|
+
*/
|
|
951
|
+
private static decrypt;
|
|
952
|
+
/**
|
|
953
|
+
* Guardar tokens de forma segura
|
|
954
|
+
*/
|
|
955
|
+
static saveTokens(tokens: TokenData): void;
|
|
956
|
+
/**
|
|
957
|
+
* Obtener tokens guardados
|
|
958
|
+
*/
|
|
959
|
+
static getTokens(): TokenData | null;
|
|
960
|
+
/**
|
|
961
|
+
* Limpiar tokens almacenados
|
|
962
|
+
*/
|
|
963
|
+
static clearTokens(): void;
|
|
964
|
+
/**
|
|
965
|
+
* Verificar si hay tokens válidos guardados
|
|
966
|
+
*/
|
|
967
|
+
static hasValidTokens(): boolean;
|
|
968
|
+
/**
|
|
969
|
+
* Obtener información de expiración
|
|
970
|
+
*/
|
|
971
|
+
static getExpirationInfo(): {
|
|
972
|
+
accessExpired: boolean;
|
|
973
|
+
refreshExpired: boolean;
|
|
974
|
+
accessExpiresIn: number;
|
|
975
|
+
refreshExpiresIn: number;
|
|
976
|
+
} | null;
|
|
977
|
+
/**
|
|
978
|
+
* Actualizar solo el access token (después de refresh)
|
|
979
|
+
*/
|
|
980
|
+
static updateAccessToken(newAccessToken: string, newExpiresAt: number): void;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
type SessionConfig = {
|
|
984
|
+
storageType?: StorageType;
|
|
985
|
+
autoRestore?: boolean;
|
|
986
|
+
enableLogging?: boolean;
|
|
987
|
+
onSessionExpired?: () => void;
|
|
988
|
+
onSessionRestored?: (tokens: TokenData) => void;
|
|
989
|
+
onLoginSuccess?: (tokens: TokenData) => void;
|
|
990
|
+
onLogout?: () => void;
|
|
991
|
+
};
|
|
992
|
+
type LoginResult = {
|
|
993
|
+
success: boolean;
|
|
994
|
+
tokens?: TokenData;
|
|
995
|
+
error?: string;
|
|
996
|
+
};
|
|
997
|
+
declare class SessionManager {
|
|
998
|
+
private static instance;
|
|
999
|
+
private config;
|
|
1000
|
+
private initialized;
|
|
1001
|
+
private constructor();
|
|
1002
|
+
static getInstance(): SessionManager;
|
|
1003
|
+
/**
|
|
1004
|
+
* Inicializar el SessionManager
|
|
1005
|
+
*/
|
|
1006
|
+
initialize(config?: SessionConfig): Promise<void>;
|
|
1007
|
+
/**
|
|
1008
|
+
* Login con persistencia automática
|
|
1009
|
+
*/
|
|
1010
|
+
login(email: string, password: string): Promise<LoginResult>;
|
|
1011
|
+
/**
|
|
1012
|
+
* Logout con limpieza de tokens
|
|
1013
|
+
*/
|
|
1014
|
+
logout(): Promise<void>;
|
|
1015
|
+
/**
|
|
1016
|
+
* Restaurar sesión desde storage
|
|
1017
|
+
*/
|
|
1018
|
+
restoreSession(): Promise<boolean>;
|
|
1019
|
+
/**
|
|
1020
|
+
* Verificar si el usuario está autenticado
|
|
1021
|
+
*/
|
|
1022
|
+
isAuthenticated(): boolean;
|
|
1023
|
+
/**
|
|
1024
|
+
* Obtener información de tokens actuales
|
|
1025
|
+
*/
|
|
1026
|
+
getTokenInfo(): {
|
|
1027
|
+
isLoggedIn: boolean;
|
|
1028
|
+
crudifyTokens: {
|
|
1029
|
+
accessToken: string;
|
|
1030
|
+
refreshToken: string;
|
|
1031
|
+
expiresAt: number;
|
|
1032
|
+
refreshExpiresAt: number;
|
|
1033
|
+
isExpired: boolean;
|
|
1034
|
+
isRefreshExpired: boolean;
|
|
1035
|
+
};
|
|
1036
|
+
storageInfo: {
|
|
1037
|
+
accessExpired: boolean;
|
|
1038
|
+
refreshExpired: boolean;
|
|
1039
|
+
accessExpiresIn: number;
|
|
1040
|
+
refreshExpiresIn: number;
|
|
1041
|
+
} | null;
|
|
1042
|
+
hasValidTokens: boolean;
|
|
1043
|
+
};
|
|
1044
|
+
/**
|
|
1045
|
+
* Refrescar tokens manualmente
|
|
1046
|
+
*/
|
|
1047
|
+
refreshTokens(): Promise<boolean>;
|
|
1048
|
+
/**
|
|
1049
|
+
* Configurar interceptor de respuesta para manejo automático de errores
|
|
1050
|
+
*/
|
|
1051
|
+
setupResponseInterceptor(): void;
|
|
1052
|
+
/**
|
|
1053
|
+
* Limpiar sesión completamente
|
|
1054
|
+
*/
|
|
1055
|
+
clearSession(): void;
|
|
1056
|
+
private log;
|
|
1057
|
+
private formatError;
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
type SessionState = {
|
|
1061
|
+
isAuthenticated: boolean;
|
|
1062
|
+
isLoading: boolean;
|
|
1063
|
+
isInitialized: boolean;
|
|
1064
|
+
tokens: TokenData | null;
|
|
1065
|
+
error: string | null;
|
|
1066
|
+
};
|
|
1067
|
+
type UseSessionOptions = {
|
|
1068
|
+
autoRestore?: boolean;
|
|
1069
|
+
enableLogging?: boolean;
|
|
1070
|
+
onSessionExpired?: () => void;
|
|
1071
|
+
onSessionRestored?: (tokens: TokenData) => void;
|
|
1072
|
+
};
|
|
1073
|
+
declare function useSession(options?: UseSessionOptions): {
|
|
1074
|
+
login: (email: string, password: string) => Promise<LoginResult>;
|
|
1075
|
+
logout: () => Promise<void>;
|
|
1076
|
+
refreshTokens: () => Promise<boolean>;
|
|
1077
|
+
clearError: () => void;
|
|
1078
|
+
getTokenInfo: () => {
|
|
1079
|
+
isLoggedIn: boolean;
|
|
1080
|
+
crudifyTokens: {
|
|
1081
|
+
accessToken: string;
|
|
1082
|
+
refreshToken: string;
|
|
1083
|
+
expiresAt: number;
|
|
1084
|
+
refreshExpiresAt: number;
|
|
1085
|
+
isExpired: boolean;
|
|
1086
|
+
isRefreshExpired: boolean;
|
|
1087
|
+
};
|
|
1088
|
+
storageInfo: {
|
|
1089
|
+
accessExpired: boolean;
|
|
1090
|
+
refreshExpired: boolean;
|
|
1091
|
+
accessExpiresIn: number;
|
|
1092
|
+
refreshExpiresIn: number;
|
|
1093
|
+
} | null;
|
|
1094
|
+
hasValidTokens: boolean;
|
|
1095
|
+
};
|
|
1096
|
+
isExpiringSoon: boolean;
|
|
1097
|
+
expiresIn: number;
|
|
1098
|
+
refreshExpiresIn: number;
|
|
1099
|
+
isAuthenticated: boolean;
|
|
1100
|
+
isLoading: boolean;
|
|
1101
|
+
isInitialized: boolean;
|
|
1102
|
+
tokens: TokenData | null;
|
|
1103
|
+
error: string | null;
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
type SessionContextType = {
|
|
1107
|
+
isAuthenticated: boolean;
|
|
1108
|
+
isLoading: boolean;
|
|
1109
|
+
isInitialized: boolean;
|
|
1110
|
+
tokens: TokenData | null;
|
|
1111
|
+
error: string | null;
|
|
1112
|
+
login: (email: string, password: string) => Promise<LoginResult>;
|
|
1113
|
+
logout: () => Promise<void>;
|
|
1114
|
+
refreshTokens: () => Promise<boolean>;
|
|
1115
|
+
clearError: () => void;
|
|
1116
|
+
getTokenInfo: () => any;
|
|
1117
|
+
isExpiringSoon: boolean;
|
|
1118
|
+
expiresIn: number;
|
|
1119
|
+
refreshExpiresIn: number;
|
|
1120
|
+
};
|
|
1121
|
+
type SessionProviderProps = {
|
|
1122
|
+
children: ReactNode;
|
|
1123
|
+
options?: UseSessionOptions;
|
|
1124
|
+
};
|
|
1125
|
+
/**
|
|
1126
|
+
* Provider de sesión para envolver la aplicación
|
|
1127
|
+
*/
|
|
1128
|
+
declare function SessionProvider({ children, options }: SessionProviderProps): react_jsx_runtime.JSX.Element;
|
|
1129
|
+
/**
|
|
1130
|
+
* Hook para usar el contexto de sesión
|
|
1131
|
+
*/
|
|
1132
|
+
declare function useSessionContext(): SessionContextType;
|
|
1133
|
+
/**
|
|
1134
|
+
* HOC para proteger rutas que requieren autenticación
|
|
1135
|
+
*/
|
|
1136
|
+
type ProtectedRouteProps = {
|
|
1137
|
+
children: ReactNode;
|
|
1138
|
+
fallback?: ReactNode;
|
|
1139
|
+
redirectTo?: () => void;
|
|
1140
|
+
};
|
|
1141
|
+
declare function ProtectedRoute({ children, fallback, redirectTo }: ProtectedRouteProps): react_jsx_runtime.JSX.Element | null;
|
|
1142
|
+
/**
|
|
1143
|
+
* Componente para mostrar información de la sesión (debug)
|
|
1144
|
+
*/
|
|
1145
|
+
declare function SessionDebugInfo(): react_jsx_runtime.JSX.Element;
|
|
1146
|
+
|
|
1147
|
+
declare function LoginComponent(): react_jsx_runtime.JSX.Element;
|
|
1148
|
+
/**
|
|
1149
|
+
* Componente simple de estado de sesión para mostrar en cualquier lugar
|
|
1150
|
+
*/
|
|
1151
|
+
declare function SessionStatus(): react_jsx_runtime.JSX.Element;
|
|
1152
|
+
|
|
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 };
|