@nocios/crudify-ui 2.0.0 → 3.0.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/dist/index.d.mts +92 -788
- package/dist/index.d.ts +92 -788
- package/dist/index.js +1543 -3275
- package/dist/index.mjs +279 -741
- package/package.json +2 -2
- package/dist/CrudifyDataProvider-5GXGNQKI.mjs +0 -16
- package/dist/TokenManager-AYUNIXQU.mjs +0 -8
- package/dist/chunk-GY5F6KOF.mjs +0 -701
- package/dist/chunk-M7V4UGCN.mjs +0 -512
package/dist/chunk-GY5F6KOF.mjs
DELETED
|
@@ -1,701 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
tokenManager
|
|
3
|
-
} from "./chunk-M7V4UGCN.mjs";
|
|
4
|
-
|
|
5
|
-
// src/providers/CrudifyDataProvider.tsx
|
|
6
|
-
import { createContext, useContext, useEffect, useState, useCallback } from "react";
|
|
7
|
-
|
|
8
|
-
// src/components/CrudifyLogin/utils/cookies.ts
|
|
9
|
-
var getCookie = (name) => {
|
|
10
|
-
const match = document.cookie.match(new RegExp("(^|;)\\s*" + name + "=([^;]+)"));
|
|
11
|
-
return match ? match[2] : null;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
// src/core/ConfigurationManager.ts
|
|
15
|
-
var _ConfigurationManager = class _ConfigurationManager {
|
|
16
|
-
constructor() {
|
|
17
|
-
this.resolvedConfig = null;
|
|
18
|
-
this.configError = null;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Singleton pattern to ensure consistent configuration across the app
|
|
22
|
-
*/
|
|
23
|
-
static getInstance() {
|
|
24
|
-
if (!_ConfigurationManager.instance) {
|
|
25
|
-
_ConfigurationManager.instance = new _ConfigurationManager();
|
|
26
|
-
}
|
|
27
|
-
return _ConfigurationManager.instance;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Reset the singleton instance (useful for testing)
|
|
31
|
-
*/
|
|
32
|
-
static resetInstance() {
|
|
33
|
-
_ConfigurationManager.instance = null;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Resolve configuration from all sources with proper priority
|
|
37
|
-
*/
|
|
38
|
-
resolveConfig(propsConfig = {}) {
|
|
39
|
-
console.log("\u{1F50D} ConfigurationManager - resolveConfig called with props:", propsConfig);
|
|
40
|
-
if (this.resolvedConfig && this.isConfigStillValid(propsConfig)) {
|
|
41
|
-
console.log("\u{1F50D} ConfigurationManager - Using cached config");
|
|
42
|
-
return this.resolvedConfig;
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
this.configError = null;
|
|
46
|
-
const envConfig = this.getEnvConfig();
|
|
47
|
-
const cookieConfig = this.getCookieConfig();
|
|
48
|
-
console.log("\u{1F50D} ConfigurationManager - envConfig:", envConfig);
|
|
49
|
-
console.log("\u{1F50D} ConfigurationManager - cookieConfig:", cookieConfig);
|
|
50
|
-
const configSource = {
|
|
51
|
-
env: "default",
|
|
52
|
-
publicApiKey: "default",
|
|
53
|
-
loginActions: "default",
|
|
54
|
-
appName: "default",
|
|
55
|
-
logo: "default",
|
|
56
|
-
colors: "default"
|
|
57
|
-
};
|
|
58
|
-
const env = this.resolveValue("env", propsConfig.env, envConfig.env, cookieConfig.env, "prod", configSource);
|
|
59
|
-
const publicApiKey = this.resolveValue(
|
|
60
|
-
"publicApiKey",
|
|
61
|
-
propsConfig.publicApiKey,
|
|
62
|
-
envConfig.publicApiKey,
|
|
63
|
-
cookieConfig.publicApiKey,
|
|
64
|
-
void 0,
|
|
65
|
-
configSource
|
|
66
|
-
);
|
|
67
|
-
const loginActions = this.resolveValue(
|
|
68
|
-
"loginActions",
|
|
69
|
-
propsConfig.loginActions,
|
|
70
|
-
envConfig.loginActions,
|
|
71
|
-
cookieConfig.loginActions,
|
|
72
|
-
[],
|
|
73
|
-
configSource
|
|
74
|
-
);
|
|
75
|
-
const appName = this.resolveValue(
|
|
76
|
-
"appName",
|
|
77
|
-
propsConfig.appName,
|
|
78
|
-
envConfig.appName,
|
|
79
|
-
cookieConfig.appName,
|
|
80
|
-
"Crudify App",
|
|
81
|
-
configSource
|
|
82
|
-
);
|
|
83
|
-
const logo = this.resolveValue("logo", propsConfig.logo, envConfig.logo, cookieConfig.logo, "", configSource);
|
|
84
|
-
const colors = this.resolveValue("colors", propsConfig.colors, envConfig.colors, cookieConfig.colors, {}, configSource);
|
|
85
|
-
console.log("\u{1F50D} ConfigurationManager - Resolved values:");
|
|
86
|
-
console.log(" - publicApiKey:", publicApiKey, "from:", configSource.publicApiKey);
|
|
87
|
-
console.log(" - env:", env, "from:", configSource.env);
|
|
88
|
-
console.log(" - loginActions:", loginActions, "from:", configSource.loginActions);
|
|
89
|
-
if (!publicApiKey) {
|
|
90
|
-
throw new Error(
|
|
91
|
-
"publicApiKey es requerido. Proporci\xF3nalo v\xEDa:\n1. Props: <CrudifyDataProvider publicApiKey={...} />\n2. Variable de entorno: VITE_TEST_PUBLIC_API_KEY\n3. Cookie: publicApiKey"
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
this.resolvedConfig = {
|
|
95
|
-
env,
|
|
96
|
-
publicApiKey,
|
|
97
|
-
loginActions,
|
|
98
|
-
appName,
|
|
99
|
-
logo,
|
|
100
|
-
colors,
|
|
101
|
-
configSource,
|
|
102
|
-
rawConfig: {
|
|
103
|
-
props: propsConfig,
|
|
104
|
-
env: envConfig,
|
|
105
|
-
cookies: cookieConfig
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
return this.resolvedConfig;
|
|
109
|
-
} catch (error) {
|
|
110
|
-
this.configError = error instanceof Error ? error.message : "Error de configuraci\xF3n desconocido";
|
|
111
|
-
console.error("ConfigurationManager - Error de configuraci\xF3n:", this.configError);
|
|
112
|
-
this.resolvedConfig = {
|
|
113
|
-
env: "prod",
|
|
114
|
-
publicApiKey: "",
|
|
115
|
-
loginActions: [],
|
|
116
|
-
appName: "Crudify App",
|
|
117
|
-
logo: "",
|
|
118
|
-
colors: {},
|
|
119
|
-
configSource: {
|
|
120
|
-
env: "default",
|
|
121
|
-
publicApiKey: "default",
|
|
122
|
-
loginActions: "default",
|
|
123
|
-
appName: "default",
|
|
124
|
-
logo: "default",
|
|
125
|
-
colors: "default"
|
|
126
|
-
},
|
|
127
|
-
rawConfig: {
|
|
128
|
-
props: propsConfig,
|
|
129
|
-
env: {},
|
|
130
|
-
cookies: {},
|
|
131
|
-
error: this.configError
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
return this.resolvedConfig;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Check if current configuration is still valid for the given props
|
|
139
|
-
*/
|
|
140
|
-
isConfigStillValid(propsConfig) {
|
|
141
|
-
if (!this.resolvedConfig) return false;
|
|
142
|
-
const currentProps = this.resolvedConfig.rawConfig.props;
|
|
143
|
-
return JSON.stringify(currentProps) === JSON.stringify(propsConfig);
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Resolve a single config value with priority and source tracking
|
|
147
|
-
*/
|
|
148
|
-
resolveValue(key, propsValue, envValue, cookieValue, defaultValue, configSource) {
|
|
149
|
-
if (propsValue !== void 0) {
|
|
150
|
-
configSource[key] = "props";
|
|
151
|
-
return propsValue;
|
|
152
|
-
}
|
|
153
|
-
if (envValue !== void 0) {
|
|
154
|
-
configSource[key] = "env";
|
|
155
|
-
return envValue;
|
|
156
|
-
}
|
|
157
|
-
if (cookieValue !== void 0) {
|
|
158
|
-
configSource[key] = "cookies";
|
|
159
|
-
return cookieValue;
|
|
160
|
-
}
|
|
161
|
-
configSource[key] = "default";
|
|
162
|
-
return defaultValue;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Obtener configuración de variables de entorno
|
|
166
|
-
*/
|
|
167
|
-
getEnvConfig() {
|
|
168
|
-
const config = {};
|
|
169
|
-
try {
|
|
170
|
-
if (typeof import.meta !== "undefined" && import.meta.env) {
|
|
171
|
-
const vitEnv = import.meta.env;
|
|
172
|
-
const env = vitEnv.VITE_TEST_ENV;
|
|
173
|
-
if (env && ["dev", "stg", "prod"].includes(env)) {
|
|
174
|
-
config.env = env;
|
|
175
|
-
}
|
|
176
|
-
const publicApiKey = vitEnv.VITE_TEST_PUBLIC_API_KEY;
|
|
177
|
-
if (publicApiKey) {
|
|
178
|
-
config.publicApiKey = publicApiKey;
|
|
179
|
-
}
|
|
180
|
-
const loginActions = vitEnv.VITE_TEST_LOGIN_ACTIONS;
|
|
181
|
-
if (loginActions) {
|
|
182
|
-
config.loginActions = loginActions.split(",").map((action) => action.trim()).filter(Boolean);
|
|
183
|
-
}
|
|
184
|
-
const appName = vitEnv.VITE_TEST_APP_NAME;
|
|
185
|
-
if (appName) {
|
|
186
|
-
config.appName = appName;
|
|
187
|
-
}
|
|
188
|
-
const logo = vitEnv.VITE_TEST_LOGO;
|
|
189
|
-
if (logo) {
|
|
190
|
-
config.logo = logo;
|
|
191
|
-
}
|
|
192
|
-
const colors = vitEnv.VITE_TEST_COLORS;
|
|
193
|
-
if (colors) {
|
|
194
|
-
try {
|
|
195
|
-
config.colors = JSON.parse(colors);
|
|
196
|
-
} catch (error) {
|
|
197
|
-
console.warn("ConfigurationManager - Error al parsear colors desde env:", error);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
if (typeof globalThis !== "undefined" && globalThis.process?.env) {
|
|
202
|
-
const processEnv = globalThis.process.env;
|
|
203
|
-
const env = processEnv.VITE_TEST_ENV;
|
|
204
|
-
if (env && ["dev", "stg", "prod"].includes(env) && !config.env) {
|
|
205
|
-
config.env = env;
|
|
206
|
-
}
|
|
207
|
-
const publicApiKey = processEnv.VITE_TEST_PUBLIC_API_KEY;
|
|
208
|
-
if (publicApiKey && !config.publicApiKey) {
|
|
209
|
-
config.publicApiKey = publicApiKey;
|
|
210
|
-
}
|
|
211
|
-
const loginActions = processEnv.VITE_TEST_LOGIN_ACTIONS;
|
|
212
|
-
if (loginActions && !config.loginActions) {
|
|
213
|
-
config.loginActions = loginActions.split(",").map((action) => action.trim()).filter(Boolean);
|
|
214
|
-
}
|
|
215
|
-
const appName = processEnv.VITE_TEST_APP_NAME;
|
|
216
|
-
if (appName && !config.appName) {
|
|
217
|
-
config.appName = appName;
|
|
218
|
-
}
|
|
219
|
-
const logo = processEnv.VITE_TEST_LOGO;
|
|
220
|
-
if (logo && !config.logo) {
|
|
221
|
-
config.logo = logo;
|
|
222
|
-
}
|
|
223
|
-
const colors = processEnv.VITE_TEST_COLORS;
|
|
224
|
-
if (colors && !config.colors) {
|
|
225
|
-
try {
|
|
226
|
-
config.colors = JSON.parse(colors);
|
|
227
|
-
} catch (error) {
|
|
228
|
-
console.warn("ConfigurationManager - Error al parsear colors desde process.env:", error);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
} catch (error) {
|
|
233
|
-
console.warn("ConfigurationManager - Variables de entorno no disponibles:", error);
|
|
234
|
-
}
|
|
235
|
-
return config;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Obtener configuración de cookies (soporte multi-tenant)
|
|
239
|
-
*/
|
|
240
|
-
getCookieConfig() {
|
|
241
|
-
const config = {};
|
|
242
|
-
try {
|
|
243
|
-
const env = getCookie("environment");
|
|
244
|
-
if (env && ["dev", "stg", "prod"].includes(env)) {
|
|
245
|
-
config.env = env;
|
|
246
|
-
}
|
|
247
|
-
const publicApiKey = getCookie("publicApiKey");
|
|
248
|
-
if (publicApiKey) {
|
|
249
|
-
config.publicApiKey = publicApiKey;
|
|
250
|
-
}
|
|
251
|
-
const appName = getCookie("appName");
|
|
252
|
-
if (appName) {
|
|
253
|
-
config.appName = decodeURIComponent(appName);
|
|
254
|
-
}
|
|
255
|
-
const loginActions = getCookie("loginActions");
|
|
256
|
-
if (loginActions) {
|
|
257
|
-
const decodedActions = decodeURIComponent(loginActions);
|
|
258
|
-
config.loginActions = decodedActions.split(",").map((action) => action.trim()).filter(Boolean);
|
|
259
|
-
}
|
|
260
|
-
const logo = getCookie("logo");
|
|
261
|
-
if (logo) {
|
|
262
|
-
config.logo = decodeURIComponent(logo);
|
|
263
|
-
}
|
|
264
|
-
const colors = getCookie("colors");
|
|
265
|
-
if (colors) {
|
|
266
|
-
try {
|
|
267
|
-
const decodedColors = decodeURIComponent(colors);
|
|
268
|
-
config.colors = JSON.parse(decodedColors);
|
|
269
|
-
} catch (error) {
|
|
270
|
-
console.warn("ConfigurationManager - Error al parsear colors desde cookie:", error);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
} catch (error) {
|
|
274
|
-
console.warn("ConfigurationManager - Error leyendo cookies:", error);
|
|
275
|
-
}
|
|
276
|
-
return config;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Get the current resolved configuration
|
|
280
|
-
*/
|
|
281
|
-
getConfig() {
|
|
282
|
-
return this.resolvedConfig;
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Get any configuration errors
|
|
286
|
-
*/
|
|
287
|
-
getConfigError() {
|
|
288
|
-
return this.configError;
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Check if configuration is valid (no errors and has required fields)
|
|
292
|
-
*/
|
|
293
|
-
isConfigured() {
|
|
294
|
-
return this.resolvedConfig !== null && this.configError === null && !!this.resolvedConfig.publicApiKey;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Clear the current configuration (useful for testing or reconfiguration)
|
|
298
|
-
*/
|
|
299
|
-
clearConfig() {
|
|
300
|
-
this.resolvedConfig = null;
|
|
301
|
-
this.configError = null;
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
_ConfigurationManager.instance = null;
|
|
305
|
-
var ConfigurationManager = _ConfigurationManager;
|
|
306
|
-
var configurationManager = ConfigurationManager.getInstance();
|
|
307
|
-
|
|
308
|
-
// src/core/CrudifyInitializer.ts
|
|
309
|
-
import crudify from "@nocios/crudify-browser";
|
|
310
|
-
var _CrudifyInitializer = class _CrudifyInitializer {
|
|
311
|
-
constructor() {
|
|
312
|
-
this.state = {
|
|
313
|
-
isInitialized: false,
|
|
314
|
-
isInitializing: false,
|
|
315
|
-
initializationError: null,
|
|
316
|
-
config: null,
|
|
317
|
-
initializationPromise: null
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Singleton pattern to ensure global initialization coordination
|
|
322
|
-
*/
|
|
323
|
-
static getInstance() {
|
|
324
|
-
if (!_CrudifyInitializer.instance) {
|
|
325
|
-
_CrudifyInitializer.instance = new _CrudifyInitializer();
|
|
326
|
-
}
|
|
327
|
-
return _CrudifyInitializer.instance;
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Reset the singleton instance (useful for testing)
|
|
331
|
-
*/
|
|
332
|
-
static resetInstance() {
|
|
333
|
-
_CrudifyInitializer.instance = null;
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Inicializar crudify con la configuración dada
|
|
337
|
-
* Este método es idempotente y thread-safe
|
|
338
|
-
*/
|
|
339
|
-
async initialize(config) {
|
|
340
|
-
if (this.state.isInitialized && this.isConfigurationSame(config)) {
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
if (this.state.isInitializing && this.state.initializationPromise) {
|
|
344
|
-
await this.state.initializationPromise;
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
if (this.state.isInitialized && !this.isConfigurationSame(config)) {
|
|
348
|
-
this.reset();
|
|
349
|
-
}
|
|
350
|
-
this.state.isInitializing = true;
|
|
351
|
-
this.state.initializationError = null;
|
|
352
|
-
this.state.initializationPromise = this.performInitialization(config);
|
|
353
|
-
try {
|
|
354
|
-
await this.state.initializationPromise;
|
|
355
|
-
this.state.isInitialized = true;
|
|
356
|
-
this.state.config = { ...config };
|
|
357
|
-
} catch (error) {
|
|
358
|
-
this.state.initializationError = error instanceof Error ? error.message : "Error de inicializaci\xF3n desconocido";
|
|
359
|
-
console.error("CrudifyInitializer - Inicializaci\xF3n fall\xF3:", this.state.initializationError);
|
|
360
|
-
throw error;
|
|
361
|
-
} finally {
|
|
362
|
-
this.state.isInitializing = false;
|
|
363
|
-
this.state.initializationPromise = null;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Realizar el proceso de inicialización actual
|
|
368
|
-
*/
|
|
369
|
-
async performInitialization(config) {
|
|
370
|
-
if (!config.publicApiKey) {
|
|
371
|
-
throw new Error("publicApiKey es requerido para la inicializaci\xF3n de crudify");
|
|
372
|
-
}
|
|
373
|
-
try {
|
|
374
|
-
const environment = config.env || "prod";
|
|
375
|
-
await crudify.config(environment);
|
|
376
|
-
await crudify.init(config.publicApiKey, "none");
|
|
377
|
-
await this.verifyInitialization();
|
|
378
|
-
} catch (error) {
|
|
379
|
-
throw new Error(
|
|
380
|
-
`Inicializaci\xF3n de Crudify fall\xF3: ${error instanceof Error ? error.message : "Error desconocido"}. Por favor revisa tu configuraci\xF3n (env: ${config.env || "prod"}, publicApiKey: ${config.publicApiKey ? "proporcionado" : "faltante"})`
|
|
381
|
-
);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Verificar que crudify esté correctamente inicializado revisando métodos principales
|
|
386
|
-
*/
|
|
387
|
-
async verifyInitialization() {
|
|
388
|
-
const requiredMethods = ["readItems", "readItem", "createItem", "updateItem", "deleteItem", "login", "transaction"];
|
|
389
|
-
const missingMethods = [];
|
|
390
|
-
for (const method of requiredMethods) {
|
|
391
|
-
if (typeof crudify[method] !== "function") {
|
|
392
|
-
missingMethods.push(method);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
if (missingMethods.length > 0) {
|
|
396
|
-
throw new Error(
|
|
397
|
-
`Inicializaci\xF3n de Crudify incompleta. M\xE9todos faltantes: ${missingMethods.join(", ")}. Esto usualmente indica un problema de configuraci\xF3n o red.`
|
|
398
|
-
);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* Verificar si la configuración dada es la misma que la actual
|
|
403
|
-
*/
|
|
404
|
-
isConfigurationSame(config) {
|
|
405
|
-
if (!this.state.config) return false;
|
|
406
|
-
return this.state.config.env === config.env && this.state.config.publicApiKey === config.publicApiKey;
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* Resetear el estado de inicialización (útil para testing o cambios de configuración)
|
|
410
|
-
*/
|
|
411
|
-
reset() {
|
|
412
|
-
this.state = {
|
|
413
|
-
isInitialized: false,
|
|
414
|
-
isInitializing: false,
|
|
415
|
-
initializationError: null,
|
|
416
|
-
config: null,
|
|
417
|
-
initializationPromise: null
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* Obtener el estado actual de inicialización
|
|
422
|
-
*/
|
|
423
|
-
getStatus() {
|
|
424
|
-
return {
|
|
425
|
-
isInitialized: this.state.isInitialized,
|
|
426
|
-
isInitializing: this.state.isInitializing,
|
|
427
|
-
initializationError: this.state.initializationError,
|
|
428
|
-
config: this.state.config
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Verificar si crudify está listo para usar
|
|
433
|
-
*/
|
|
434
|
-
isReady() {
|
|
435
|
-
return this.state.isInitialized && !this.state.initializationError;
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Obtener el error de inicialización actual, si existe
|
|
439
|
-
*/
|
|
440
|
-
getError() {
|
|
441
|
-
return this.state.initializationError;
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* Forzar re-inicialización (útil cuando la configuración cambia)
|
|
445
|
-
*/
|
|
446
|
-
async reinitialize(config) {
|
|
447
|
-
this.reset();
|
|
448
|
-
await this.initialize(config);
|
|
449
|
-
}
|
|
450
|
-
/**
|
|
451
|
-
* Verificar si la inicialización está actualmente en progreso
|
|
452
|
-
*/
|
|
453
|
-
isInitializing() {
|
|
454
|
-
return this.state.isInitializing;
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Esperar a que cualquier inicialización en curso se complete
|
|
458
|
-
*/
|
|
459
|
-
async waitForInitialization() {
|
|
460
|
-
if (this.state.initializationPromise) {
|
|
461
|
-
await this.state.initializationPromise;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
};
|
|
465
|
-
_CrudifyInitializer.instance = null;
|
|
466
|
-
var CrudifyInitializer = _CrudifyInitializer;
|
|
467
|
-
var crudifyInitializer = CrudifyInitializer.getInstance();
|
|
468
|
-
|
|
469
|
-
// src/providers/CrudifyDataProvider.tsx
|
|
470
|
-
import { jsx } from "react/jsx-runtime";
|
|
471
|
-
var CrudifyDataContext = createContext(null);
|
|
472
|
-
var CrudifyDataProvider = ({
|
|
473
|
-
children,
|
|
474
|
-
env,
|
|
475
|
-
publicApiKey,
|
|
476
|
-
loginActions,
|
|
477
|
-
appName,
|
|
478
|
-
logo,
|
|
479
|
-
colors
|
|
480
|
-
}) => {
|
|
481
|
-
console.log("\u{1F50D} CrudifyDataProvider - Received props:", {
|
|
482
|
-
env,
|
|
483
|
-
publicApiKey,
|
|
484
|
-
loginActions,
|
|
485
|
-
appName,
|
|
486
|
-
logo,
|
|
487
|
-
colors
|
|
488
|
-
});
|
|
489
|
-
const [config, setConfig] = useState(null);
|
|
490
|
-
const [isConfigured, setIsConfigured] = useState(false);
|
|
491
|
-
const [configError, setConfigError] = useState(null);
|
|
492
|
-
const [isInitialized, setIsInitialized] = useState(false);
|
|
493
|
-
const [isInitializing, setIsInitializing] = useState(false);
|
|
494
|
-
const [initializationError, setInitializationError] = useState(null);
|
|
495
|
-
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
496
|
-
const [token, setTokenState] = useState(null);
|
|
497
|
-
const [user, setUser] = useState(null);
|
|
498
|
-
const [tokenExpiration, setTokenExpiration] = useState(null);
|
|
499
|
-
const initializeConfiguration = useCallback(() => {
|
|
500
|
-
try {
|
|
501
|
-
const propsConfig = {
|
|
502
|
-
env,
|
|
503
|
-
publicApiKey,
|
|
504
|
-
loginActions,
|
|
505
|
-
appName,
|
|
506
|
-
logo,
|
|
507
|
-
colors
|
|
508
|
-
};
|
|
509
|
-
const resolvedConfig = configurationManager.resolveConfig(propsConfig);
|
|
510
|
-
const error = configurationManager.getConfigError();
|
|
511
|
-
setConfig(resolvedConfig);
|
|
512
|
-
setConfigError(error);
|
|
513
|
-
setIsConfigured(configurationManager.isConfigured());
|
|
514
|
-
return resolvedConfig;
|
|
515
|
-
} catch (error) {
|
|
516
|
-
const errorMessage = error instanceof Error ? error.message : "Error en inicializaci\xF3n de configuraci\xF3n";
|
|
517
|
-
console.error("CrudifyDataProvider - Error de configuraci\xF3n:", errorMessage);
|
|
518
|
-
setConfigError(errorMessage);
|
|
519
|
-
setIsConfigured(false);
|
|
520
|
-
return null;
|
|
521
|
-
}
|
|
522
|
-
}, [env, publicApiKey, loginActions, appName, logo, colors]);
|
|
523
|
-
const initializeCrudify = useCallback(async (resolvedConfig) => {
|
|
524
|
-
if (!resolvedConfig || !resolvedConfig.publicApiKey) {
|
|
525
|
-
setInitializationError("No se puede inicializar crudify sin configuraci\xF3n v\xE1lida");
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
try {
|
|
529
|
-
setIsInitializing(true);
|
|
530
|
-
setInitializationError(null);
|
|
531
|
-
await crudifyInitializer.initialize({
|
|
532
|
-
env: resolvedConfig.env,
|
|
533
|
-
publicApiKey: resolvedConfig.publicApiKey,
|
|
534
|
-
loginActions: resolvedConfig.loginActions,
|
|
535
|
-
appName: resolvedConfig.appName,
|
|
536
|
-
logo: resolvedConfig.logo,
|
|
537
|
-
colors: resolvedConfig.colors
|
|
538
|
-
});
|
|
539
|
-
setIsInitialized(true);
|
|
540
|
-
} catch (error) {
|
|
541
|
-
const errorMessage = error instanceof Error ? error.message : "Error en inicializaci\xF3n de Crudify";
|
|
542
|
-
console.error("CrudifyDataProvider - Error de inicializaci\xF3n:", errorMessage);
|
|
543
|
-
setInitializationError(errorMessage);
|
|
544
|
-
setIsInitialized(false);
|
|
545
|
-
} finally {
|
|
546
|
-
setIsInitializing(false);
|
|
547
|
-
}
|
|
548
|
-
}, []);
|
|
549
|
-
const updateAuthenticationState = useCallback(() => {
|
|
550
|
-
try {
|
|
551
|
-
const currentToken = tokenManager.getToken();
|
|
552
|
-
const parsedUser = tokenManager.parseToken();
|
|
553
|
-
const expiration = tokenManager.getTokenExpiration();
|
|
554
|
-
const authenticated = tokenManager.isAuthenticated();
|
|
555
|
-
setTokenState(currentToken);
|
|
556
|
-
setUser(parsedUser);
|
|
557
|
-
setTokenExpiration(expiration);
|
|
558
|
-
setIsAuthenticated(authenticated);
|
|
559
|
-
} catch (error) {
|
|
560
|
-
console.error("CrudifyDataProvider - Error actualizando estado de autenticaci\xF3n:", error);
|
|
561
|
-
}
|
|
562
|
-
}, []);
|
|
563
|
-
const setToken = useCallback((newToken) => {
|
|
564
|
-
tokenManager.setToken(newToken);
|
|
565
|
-
if (newToken) {
|
|
566
|
-
const parsedUser = tokenManager.parseToken(newToken);
|
|
567
|
-
const expiration = tokenManager.getTokenExpiration();
|
|
568
|
-
const authenticated = tokenManager.isTokenValid(newToken);
|
|
569
|
-
setTokenState(newToken);
|
|
570
|
-
setUser(parsedUser);
|
|
571
|
-
setTokenExpiration(expiration);
|
|
572
|
-
setIsAuthenticated(authenticated);
|
|
573
|
-
} else {
|
|
574
|
-
setTokenState(null);
|
|
575
|
-
setUser(null);
|
|
576
|
-
setTokenExpiration(null);
|
|
577
|
-
setIsAuthenticated(false);
|
|
578
|
-
}
|
|
579
|
-
}, []);
|
|
580
|
-
const logout = useCallback(() => {
|
|
581
|
-
tokenManager.clearToken();
|
|
582
|
-
setTokenState(null);
|
|
583
|
-
setUser(null);
|
|
584
|
-
setTokenExpiration(null);
|
|
585
|
-
setIsAuthenticated(false);
|
|
586
|
-
}, []);
|
|
587
|
-
const refreshConfig = useCallback(() => {
|
|
588
|
-
configurationManager.clearConfig();
|
|
589
|
-
const newConfig = initializeConfiguration();
|
|
590
|
-
if (newConfig && newConfig.publicApiKey) {
|
|
591
|
-
initializeCrudify(newConfig);
|
|
592
|
-
}
|
|
593
|
-
}, [initializeConfiguration, initializeCrudify]);
|
|
594
|
-
const reinitialize = useCallback(async () => {
|
|
595
|
-
if (!config || !config.publicApiKey) {
|
|
596
|
-
console.warn("CrudifyDataProvider - No se puede reinicializar sin configuraci\xF3n v\xE1lida");
|
|
597
|
-
return;
|
|
598
|
-
}
|
|
599
|
-
crudifyInitializer.reset();
|
|
600
|
-
await initializeCrudify(config);
|
|
601
|
-
}, [config, initializeCrudify]);
|
|
602
|
-
const getDebugInfo = useCallback(() => {
|
|
603
|
-
return {
|
|
604
|
-
provider: {
|
|
605
|
-
isConfigured,
|
|
606
|
-
configError,
|
|
607
|
-
isInitialized,
|
|
608
|
-
isInitializing,
|
|
609
|
-
initializationError,
|
|
610
|
-
isAuthenticated
|
|
611
|
-
},
|
|
612
|
-
configuration: {
|
|
613
|
-
config: config ? {
|
|
614
|
-
env: config.env,
|
|
615
|
-
publicApiKey: `${config.publicApiKey.substring(0, 8)}...`,
|
|
616
|
-
appName: config.appName,
|
|
617
|
-
loginActionsCount: config.loginActions.length,
|
|
618
|
-
hasLogo: !!config.logo,
|
|
619
|
-
colorsCount: Object.keys(config.colors).length
|
|
620
|
-
} : null,
|
|
621
|
-
sources: config?.configSource || null,
|
|
622
|
-
rawConfig: config?.rawConfig || null
|
|
623
|
-
},
|
|
624
|
-
authentication: {
|
|
625
|
-
hasToken: !!token,
|
|
626
|
-
tokenLength: token?.length || 0,
|
|
627
|
-
userEmail: user?.email || null,
|
|
628
|
-
userId: user?.sub || null,
|
|
629
|
-
expiration: tokenExpiration?.toISOString() || null,
|
|
630
|
-
minutesUntilExpiry: tokenManager.getTimeUntilExpiration()
|
|
631
|
-
},
|
|
632
|
-
tokenManager: tokenManager.getDebugInfo(),
|
|
633
|
-
crudifyInitializer: crudifyInitializer.getStatus()
|
|
634
|
-
};
|
|
635
|
-
}, [
|
|
636
|
-
isConfigured,
|
|
637
|
-
configError,
|
|
638
|
-
isInitialized,
|
|
639
|
-
isInitializing,
|
|
640
|
-
initializationError,
|
|
641
|
-
isAuthenticated,
|
|
642
|
-
config,
|
|
643
|
-
token,
|
|
644
|
-
user,
|
|
645
|
-
tokenExpiration
|
|
646
|
-
]);
|
|
647
|
-
useEffect(() => {
|
|
648
|
-
const resolvedConfig = initializeConfiguration();
|
|
649
|
-
updateAuthenticationState();
|
|
650
|
-
if (resolvedConfig && resolvedConfig.publicApiKey) {
|
|
651
|
-
initializeCrudify(resolvedConfig);
|
|
652
|
-
}
|
|
653
|
-
return () => {
|
|
654
|
-
tokenManager.cleanup();
|
|
655
|
-
};
|
|
656
|
-
}, []);
|
|
657
|
-
useEffect(() => {
|
|
658
|
-
updateAuthenticationState();
|
|
659
|
-
}, []);
|
|
660
|
-
const contextValue = {
|
|
661
|
-
// Configuración
|
|
662
|
-
config,
|
|
663
|
-
isConfigured,
|
|
664
|
-
configError,
|
|
665
|
-
configSource: config ? JSON.stringify(config.configSource) : "none",
|
|
666
|
-
// Inicialización
|
|
667
|
-
isInitialized,
|
|
668
|
-
isInitializing,
|
|
669
|
-
initializationError,
|
|
670
|
-
// Autenticación
|
|
671
|
-
isAuthenticated,
|
|
672
|
-
token,
|
|
673
|
-
user,
|
|
674
|
-
tokenExpiration,
|
|
675
|
-
// Acciones
|
|
676
|
-
setToken,
|
|
677
|
-
logout,
|
|
678
|
-
refreshConfig,
|
|
679
|
-
reinitialize,
|
|
680
|
-
// Debug
|
|
681
|
-
getDebugInfo
|
|
682
|
-
};
|
|
683
|
-
return /* @__PURE__ */ jsx(CrudifyDataContext.Provider, { value: contextValue, children });
|
|
684
|
-
};
|
|
685
|
-
var useCrudifyDataContext = () => {
|
|
686
|
-
const context = useContext(CrudifyDataContext);
|
|
687
|
-
if (!context) {
|
|
688
|
-
throw new Error(
|
|
689
|
-
"useCrudifyDataContext must be used within a CrudifyDataProvider. Make sure to wrap your app with <CrudifyDataProvider>."
|
|
690
|
-
);
|
|
691
|
-
}
|
|
692
|
-
return context;
|
|
693
|
-
};
|
|
694
|
-
|
|
695
|
-
export {
|
|
696
|
-
getCookie,
|
|
697
|
-
configurationManager,
|
|
698
|
-
crudifyInitializer,
|
|
699
|
-
CrudifyDataProvider,
|
|
700
|
-
useCrudifyDataContext
|
|
701
|
-
};
|