@nocios/crudify-ui 3.0.6 → 3.0.12

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/README.md CHANGED
@@ -24,28 +24,122 @@ npm install @nocios/crudify-ui
24
24
  npm install @mui/material @mui/icons-material react react-dom
25
25
  ```
26
26
 
27
- ## 🏗️ Configuración Rápida
27
+ ## 🏗️ Configuración
28
28
 
29
- ### 1. Configurar SessionProvider
29
+ ### ⚙️ Sistema de Configuración
30
+
31
+ La librería utiliza un sistema de configuración por prioridad para obtener credenciales y configuración:
32
+
33
+ 1. **Props directos** (máxima prioridad) - Override manual
34
+ 2. **Variables de entorno** (desarrollo local) - Se leen desde `.env`
35
+ 3. **Cookies** (producción) - Las establece Lambda automáticamente
36
+ 4. **Error** - Si no hay configuración válida
37
+
38
+ ### 🏗️ Arquitectura
39
+
40
+ ### 📋 Configuración Centralizada
41
+
42
+ **IMPORTANTE**: La configuración ahora se pasa al `SessionProvider` en lugar de individual componentes como `CrudifyLogin`. Esta arquitectura centralizada garantiza que todos los componentes tengan acceso a la misma configuración.
43
+
44
+ ````tsx
45
+ // ✅ CORRECTO - Nueva arquitectura
46
+ <SessionProvider config={{ publicApiKey: "...", env: "dev" }}>
47
+ <CrudifyLogin />
48
+ </SessionProvider>
49
+
50
+ **Requisito**: `CrudifyLogin` debe estar dentro de un `SessionProvider` para funcionar correctamente.
51
+
52
+ ## 🔧 Configuración para Desarrollo Local
53
+
54
+ #### 1. Crear archivo `.env` en tu proyecto
55
+
56
+ ```bash
57
+ # .env (para desarrollo local)
58
+ VITE_TEST_PUBLIC_API_KEY=CRUD_tu_api_key_aqui
59
+ VITE_TEST_ENV=dev
60
+ VITE_TEST_LOGIN_ACTIONS=createUser,forgotPassword
61
+ ````
62
+
63
+ #### 2. Configurar Providers
30
64
 
31
65
  ```tsx
32
- import { SessionProvider } from "@nocios/crudify-ui";
66
+ import { SessionProvider, crudify } from "@nocios/crudify-ui";
33
67
 
34
68
  function App() {
69
+ useEffect(() => {
70
+ // Inicializar crudify (opcional)
71
+ const initCrudify = async () => {
72
+ const publicApiKey = import.meta.env.VITE_TEST_PUBLIC_API_KEY;
73
+ const environment = import.meta.env.VITE_TEST_ENV || "dev";
74
+
75
+ if (publicApiKey) {
76
+ crudify.config(environment);
77
+ await crudify.init(publicApiKey, "debug");
78
+ }
79
+ };
80
+
81
+ initCrudify();
82
+ }, []);
83
+
35
84
  return (
36
- <SessionProvider>
85
+ <SessionProvider
86
+ options={{
87
+ autoRestore: true,
88
+ enableLogging: process.env.NODE_ENV === "development",
89
+ }}
90
+ config={{
91
+ publicApiKey: import.meta.env.VITE_TEST_PUBLIC_API_KEY,
92
+ env: import.meta.env.VITE_TEST_ENV,
93
+ loginActions: import.meta.env.VITE_TEST_LOGIN_ACTIONS?.split(","),
94
+ }}
95
+ >
37
96
  <YourApp />
38
97
  </SessionProvider>
39
98
  );
40
99
  }
41
100
  ```
42
101
 
43
- ### 2. Variables de Entorno
102
+ #### 3. Usar CrudifyLogin con configuración automática
44
103
 
45
- ```bash
46
- # .env
47
- REACT_APP_CRUDIFY_PUBLIC_API_KEY=tu_api_key
48
- REACT_APP_CRUDIFY_ENV=dev
104
+ ```tsx
105
+ import { CrudifyLogin } from "@nocios/crudify-ui";
106
+
107
+ function LoginPage() {
108
+ return (
109
+ <CrudifyLogin
110
+ onLoginSuccess={(userData) => {
111
+ console.log("Login exitoso:", userData);
112
+ // Navegar al dashboard
113
+ }}
114
+ onError={(error) => {
115
+ console.error("Error en login:", error);
116
+ }}
117
+ />
118
+ );
119
+ }
120
+ ```
121
+
122
+ ### 🌐 Configuración para Producción
123
+
124
+ En producción (staging/prod), **NO** uses variables de entorno. El Lambda de AWS se encarga de establecer las cookies automáticamente:
125
+
126
+ - `publicApiKey` → Cookie
127
+ - `environment` → Cookie
128
+ - `loginActions` → Cookie
129
+
130
+ La librería las detectará automáticamente:
131
+
132
+ ```tsx
133
+ // En producción, la configuración se lee de cookies automáticamente
134
+ <SessionProvider
135
+ config={{
136
+ appName: "Mi App",
137
+ colors: { primaryColor: "#1976d2" },
138
+ // publicApiKey, env y loginActions se leen de cookies automáticamente
139
+ }}
140
+ >
141
+ <CrudifyLogin />
142
+ </SessionProvider>
49
143
  ```
50
144
 
51
145
  ## 🪝 Hooks Principales
@@ -117,21 +211,24 @@ function ProductManager() {
117
211
  ### CrudifyLogin - Login Completo
118
212
 
119
213
  ```tsx
120
- import { CrudifyLogin } from "@nocios/crudify-ui";
214
+ import { CrudifyLogin, SessionProvider } from "@nocios/crudify-ui";
121
215
 
122
216
  function AuthPage() {
123
217
  return (
124
- <CrudifyLogin
218
+ <SessionProvider
125
219
  config={{
126
220
  appName: "Mi App",
127
221
  logo: "/logo.png",
128
222
  colors: { primaryColor: "#1976d2" },
129
223
  }}
130
- onLoginSuccess={(userData) => {
131
- console.log("Login exitoso:", userData);
132
- }}
133
- language="es"
134
- />
224
+ >
225
+ <CrudifyLogin
226
+ onLoginSuccess={(userData) => {
227
+ console.log("Login exitoso:", userData);
228
+ }}
229
+ language="es"
230
+ />
231
+ </SessionProvider>
135
232
  );
136
233
  }
137
234
  ```
@@ -221,7 +318,7 @@ function Dashboard() {
221
318
  function LoginPage() {
222
319
  return (
223
320
  <div style={{ maxWidth: "400px", margin: "0 auto" }}>
224
- <CrudifyLogin config={{ appName: "Mi App" }} onLoginSuccess={(userData) => console.log("Login:", userData)} />
321
+ <CrudifyLogin onLoginSuccess={(userData) => console.log("Login:", userData)} />
225
322
  </div>
226
323
  );
227
324
  }
package/dist/index.d.mts CHANGED
@@ -28,7 +28,6 @@ interface UserLoginData {
28
28
  [key: string]: any;
29
29
  }
30
30
  interface CrudifyLoginProps {
31
- config?: CrudifyLoginConfig;
32
31
  onScreenChange?: (screen: BoxScreenType, params?: Record<string, string>) => void;
33
32
  onExternalNavigate?: (path: string) => void;
34
33
  onLoginSuccess?: (userData: UserLoginData, redirectUrl?: string) => void;
@@ -348,6 +347,18 @@ type SessionData = {
348
347
  subscriberKey: string;
349
348
  [key: string]: any;
350
349
  } | null;
350
+ type CrudifyConfig = {
351
+ publicApiKey?: string;
352
+ env?: "dev" | "stg" | "prod";
353
+ appName?: string;
354
+ loginActions?: string[];
355
+ logo?: string;
356
+ colors?: {
357
+ primaryColor?: string;
358
+ bgColor?: string;
359
+ [key: string]: string | undefined;
360
+ };
361
+ };
351
362
  type SessionContextType = {
352
363
  isAuthenticated: boolean;
353
364
  isLoading: boolean;
@@ -355,6 +366,7 @@ type SessionContextType = {
355
366
  tokens: TokenData | null;
356
367
  error: string | null;
357
368
  sessionData: SessionData;
369
+ config: CrudifyConfig;
358
370
  login: (email: string, password: string) => Promise<LoginResult>;
359
371
  logout: () => Promise<void>;
360
372
  refreshTokens: () => Promise<boolean>;
@@ -367,11 +379,12 @@ type SessionContextType = {
367
379
  type SessionProviderProps = {
368
380
  children: ReactNode;
369
381
  options?: UseSessionOptions;
382
+ config?: CrudifyConfig;
370
383
  };
371
384
  /**
372
385
  * Provider de sesión para envolver la aplicación
373
386
  */
374
- declare function SessionProvider({ children, options }: SessionProviderProps): react_jsx_runtime.JSX.Element;
387
+ declare function SessionProvider({ children, options, config: propConfig }: SessionProviderProps): react_jsx_runtime.JSX.Element;
375
388
  /**
376
389
  * Hook para usar el contexto de sesión
377
390
  */
package/dist/index.d.ts CHANGED
@@ -28,7 +28,6 @@ interface UserLoginData {
28
28
  [key: string]: any;
29
29
  }
30
30
  interface CrudifyLoginProps {
31
- config?: CrudifyLoginConfig;
32
31
  onScreenChange?: (screen: BoxScreenType, params?: Record<string, string>) => void;
33
32
  onExternalNavigate?: (path: string) => void;
34
33
  onLoginSuccess?: (userData: UserLoginData, redirectUrl?: string) => void;
@@ -348,6 +347,18 @@ type SessionData = {
348
347
  subscriberKey: string;
349
348
  [key: string]: any;
350
349
  } | null;
350
+ type CrudifyConfig = {
351
+ publicApiKey?: string;
352
+ env?: "dev" | "stg" | "prod";
353
+ appName?: string;
354
+ loginActions?: string[];
355
+ logo?: string;
356
+ colors?: {
357
+ primaryColor?: string;
358
+ bgColor?: string;
359
+ [key: string]: string | undefined;
360
+ };
361
+ };
351
362
  type SessionContextType = {
352
363
  isAuthenticated: boolean;
353
364
  isLoading: boolean;
@@ -355,6 +366,7 @@ type SessionContextType = {
355
366
  tokens: TokenData | null;
356
367
  error: string | null;
357
368
  sessionData: SessionData;
369
+ config: CrudifyConfig;
358
370
  login: (email: string, password: string) => Promise<LoginResult>;
359
371
  logout: () => Promise<void>;
360
372
  refreshTokens: () => Promise<boolean>;
@@ -367,11 +379,12 @@ type SessionContextType = {
367
379
  type SessionProviderProps = {
368
380
  children: ReactNode;
369
381
  options?: UseSessionOptions;
382
+ config?: CrudifyConfig;
370
383
  };
371
384
  /**
372
385
  * Provider de sesión para envolver la aplicación
373
386
  */
374
- declare function SessionProvider({ children, options }: SessionProviderProps): react_jsx_runtime.JSX.Element;
387
+ declare function SessionProvider({ children, options, config: propConfig }: SessionProviderProps): react_jsx_runtime.JSX.Element;
375
388
  /**
376
389
  * Hook para usar el contexto de sesión
377
390
  */