@nocios/crudify-ui 1.0.80 → 1.0.82
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_EXAMPLE.md +538 -0
- package/TECHNICAL_SPECIFICATION.md +344 -0
- package/dist/index.d.mts +632 -3
- package/dist/index.d.ts +632 -3
- package/dist/index.js +1563 -24
- package/dist/index.mjs +1577 -22
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from '@nocios/crudify-browser';
|
|
2
2
|
export { default as crudify } from '@nocios/crudify-browser';
|
|
3
|
-
import React from 'react';
|
|
3
|
+
import React, { ReactNode } from 'react';
|
|
4
4
|
|
|
5
5
|
type BoxScreenType = "login" | "signUp" | "forgotPassword" | "resetPassword" | "checkCode";
|
|
6
6
|
interface CrudifyLoginConfig {
|
|
@@ -18,11 +18,19 @@ interface CrudifyLoginConfig {
|
|
|
18
18
|
interface CrudifyLoginTranslations {
|
|
19
19
|
[key: string]: string | CrudifyLoginTranslations;
|
|
20
20
|
}
|
|
21
|
+
interface UserLoginData {
|
|
22
|
+
token: string;
|
|
23
|
+
username?: string;
|
|
24
|
+
email?: string;
|
|
25
|
+
userId?: string;
|
|
26
|
+
profile?: any;
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
}
|
|
21
29
|
interface CrudifyLoginProps {
|
|
22
30
|
config?: CrudifyLoginConfig;
|
|
23
31
|
onScreenChange?: (screen: BoxScreenType, params?: Record<string, string>) => void;
|
|
24
32
|
onExternalNavigate?: (path: string) => void;
|
|
25
|
-
onLoginSuccess?: (
|
|
33
|
+
onLoginSuccess?: (userData: UserLoginData, redirectUrl?: string) => void;
|
|
26
34
|
onError?: (error: string) => void;
|
|
27
35
|
initialScreen?: BoxScreenType;
|
|
28
36
|
redirectUrl?: string;
|
|
@@ -34,6 +42,13 @@ interface CrudifyLoginProps {
|
|
|
34
42
|
|
|
35
43
|
declare const CrudifyLogin: React.FC<CrudifyLoginProps>;
|
|
36
44
|
|
|
45
|
+
interface UserProfileDisplayProps {
|
|
46
|
+
showExtendedData?: boolean;
|
|
47
|
+
showProfileCard?: boolean;
|
|
48
|
+
autoRefresh?: boolean;
|
|
49
|
+
}
|
|
50
|
+
declare const UserProfileDisplay: React.FC<UserProfileDisplayProps>;
|
|
51
|
+
|
|
37
52
|
interface CrudifyApiResponse<T = unknown> {
|
|
38
53
|
success: boolean;
|
|
39
54
|
data?: T;
|
|
@@ -115,6 +130,619 @@ interface ValidationError {
|
|
|
115
130
|
code: string;
|
|
116
131
|
}
|
|
117
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Configuration interface for CrudifyDataProvider
|
|
135
|
+
* Supports multi-tenant configurations via environment variables, cookies, or direct props
|
|
136
|
+
*/
|
|
137
|
+
interface CrudifyConfig {
|
|
138
|
+
env?: "dev" | "stg" | "prod";
|
|
139
|
+
publicApiKey?: string;
|
|
140
|
+
loginActions?: string[];
|
|
141
|
+
appName?: string;
|
|
142
|
+
logo?: string;
|
|
143
|
+
colors?: Record<string, string>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Source of configuration values for debugging and validation
|
|
147
|
+
*/
|
|
148
|
+
type ConfigSource = "props" | "env" | "cookies" | "default";
|
|
149
|
+
/**
|
|
150
|
+
* Detailed configuration with source tracking for debugging
|
|
151
|
+
*/
|
|
152
|
+
interface ResolvedConfig extends Required<CrudifyConfig> {
|
|
153
|
+
configSource: Record<keyof CrudifyConfig, ConfigSource>;
|
|
154
|
+
rawConfig: Record<string, any>;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Configuration Manager for CrudifyDataProvider
|
|
158
|
+
*
|
|
159
|
+
* Handles configuration priority:
|
|
160
|
+
* 1. Props passed explicitly to the Provider
|
|
161
|
+
* 2. Environment variables (VITE_TEST_*)
|
|
162
|
+
* 3. Cookies (for multi-tenant)
|
|
163
|
+
* 4. Default values or error if required fields missing
|
|
164
|
+
*
|
|
165
|
+
* This ensures compatibility with both crudia-ui (cookie-based) and crudify-ui (env-based)
|
|
166
|
+
*/
|
|
167
|
+
declare class ConfigurationManager {
|
|
168
|
+
private static instance;
|
|
169
|
+
private resolvedConfig;
|
|
170
|
+
private configError;
|
|
171
|
+
/**
|
|
172
|
+
* Singleton pattern to ensure consistent configuration across the app
|
|
173
|
+
*/
|
|
174
|
+
static getInstance(): ConfigurationManager;
|
|
175
|
+
/**
|
|
176
|
+
* Reset the singleton instance (useful for testing)
|
|
177
|
+
*/
|
|
178
|
+
static resetInstance(): void;
|
|
179
|
+
private constructor();
|
|
180
|
+
/**
|
|
181
|
+
* Resolve configuration from all sources with proper priority
|
|
182
|
+
*/
|
|
183
|
+
resolveConfig(propsConfig?: Partial<CrudifyConfig>): ResolvedConfig;
|
|
184
|
+
/**
|
|
185
|
+
* Check if current configuration is still valid for the given props
|
|
186
|
+
*/
|
|
187
|
+
private isConfigStillValid;
|
|
188
|
+
/**
|
|
189
|
+
* Resolve a single config value with priority and source tracking
|
|
190
|
+
*/
|
|
191
|
+
private resolveValue;
|
|
192
|
+
/**
|
|
193
|
+
* Get configuration from environment variables
|
|
194
|
+
*/
|
|
195
|
+
private getEnvConfig;
|
|
196
|
+
/**
|
|
197
|
+
* Get configuration from cookies (multi-tenant support)
|
|
198
|
+
*/
|
|
199
|
+
private getCookieConfig;
|
|
200
|
+
/**
|
|
201
|
+
* Get the current resolved configuration
|
|
202
|
+
*/
|
|
203
|
+
getConfig(): ResolvedConfig | null;
|
|
204
|
+
/**
|
|
205
|
+
* Get any configuration errors
|
|
206
|
+
*/
|
|
207
|
+
getConfigError(): string | null;
|
|
208
|
+
/**
|
|
209
|
+
* Check if configuration is valid (no errors and has required fields)
|
|
210
|
+
*/
|
|
211
|
+
isConfigured(): boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Clear the current configuration (useful for testing or reconfiguration)
|
|
214
|
+
*/
|
|
215
|
+
clearConfig(): void;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Singleton instance for easy access
|
|
219
|
+
*/
|
|
220
|
+
declare const configurationManager: ConfigurationManager;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* CrudifyInitializer handles the critical task of initializing the crudify library
|
|
224
|
+
* exactly once, preventing the "Crudify: Not initialized" and double initialization errors
|
|
225
|
+
* that occur when both crudia-ui and crudify-ui try to initialize crudify independently.
|
|
226
|
+
*
|
|
227
|
+
* This is a singleton that ensures:
|
|
228
|
+
* 1. Only one initialization attempt at a time
|
|
229
|
+
* 2. Subsequent calls wait for the first initialization to complete
|
|
230
|
+
* 3. Proper error handling and recovery
|
|
231
|
+
* 4. Verification that crudify methods are available after initialization
|
|
232
|
+
* 5. Thread-safe initialization in React's concurrent mode
|
|
233
|
+
*/
|
|
234
|
+
declare class CrudifyInitializer {
|
|
235
|
+
private static instance;
|
|
236
|
+
private state;
|
|
237
|
+
/**
|
|
238
|
+
* Singleton pattern to ensure global initialization coordination
|
|
239
|
+
*/
|
|
240
|
+
static getInstance(): CrudifyInitializer;
|
|
241
|
+
/**
|
|
242
|
+
* Reset the singleton instance (useful for testing)
|
|
243
|
+
*/
|
|
244
|
+
static resetInstance(): void;
|
|
245
|
+
private constructor();
|
|
246
|
+
/**
|
|
247
|
+
* Initialize crudify with the given configuration
|
|
248
|
+
* This method is idempotent and thread-safe
|
|
249
|
+
*/
|
|
250
|
+
initialize(config: CrudifyConfig): Promise<void>;
|
|
251
|
+
/**
|
|
252
|
+
* Perform the actual initialization process
|
|
253
|
+
*/
|
|
254
|
+
private performInitialization;
|
|
255
|
+
/**
|
|
256
|
+
* Verify that crudify is properly initialized by checking core methods
|
|
257
|
+
*/
|
|
258
|
+
private verifyInitialization;
|
|
259
|
+
/**
|
|
260
|
+
* Check if the given configuration is the same as the current one
|
|
261
|
+
*/
|
|
262
|
+
private isConfigurationSame;
|
|
263
|
+
/**
|
|
264
|
+
* Reset the initialization state (useful for testing or configuration changes)
|
|
265
|
+
*/
|
|
266
|
+
reset(): void;
|
|
267
|
+
/**
|
|
268
|
+
* Get the current initialization status
|
|
269
|
+
*/
|
|
270
|
+
getStatus(): {
|
|
271
|
+
isInitialized: boolean;
|
|
272
|
+
isInitializing: boolean;
|
|
273
|
+
initializationError: string | null;
|
|
274
|
+
config: CrudifyConfig | null;
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* Check if crudify is ready to use
|
|
278
|
+
*/
|
|
279
|
+
isReady(): boolean;
|
|
280
|
+
/**
|
|
281
|
+
* Get the current initialization error, if any
|
|
282
|
+
*/
|
|
283
|
+
getError(): string | null;
|
|
284
|
+
/**
|
|
285
|
+
* Force re-initialization (useful when configuration changes)
|
|
286
|
+
*/
|
|
287
|
+
reinitialize(config: CrudifyConfig): Promise<void>;
|
|
288
|
+
/**
|
|
289
|
+
* Check if initialization is currently in progress
|
|
290
|
+
*/
|
|
291
|
+
isInitializing(): boolean;
|
|
292
|
+
/**
|
|
293
|
+
* Wait for any ongoing initialization to complete
|
|
294
|
+
*/
|
|
295
|
+
waitForInitialization(): Promise<void>;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Singleton instance for easy access
|
|
299
|
+
*/
|
|
300
|
+
declare const crudifyInitializer: CrudifyInitializer;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Enhanced JWT payload interface with Cognito-specific fields
|
|
304
|
+
*/
|
|
305
|
+
interface JWTPayload$1 extends JwtPayload {
|
|
306
|
+
"cognito:username"?: string;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* TokenManager handles all JWT token operations with automatic synchronization
|
|
310
|
+
* between storage and crudify library. It maintains 100% compatibility with
|
|
311
|
+
* the existing crudia-ui storage patterns while providing enhanced functionality.
|
|
312
|
+
*
|
|
313
|
+
* Key features:
|
|
314
|
+
* - Automatic storage <-> crudify synchronization
|
|
315
|
+
* - Token validation and expiration checking
|
|
316
|
+
* - Migration support from localStorage to sessionStorage
|
|
317
|
+
* - Backward compatibility with existing token storage keys
|
|
318
|
+
* - Automatic cleanup of expired tokens
|
|
319
|
+
*/
|
|
320
|
+
declare class TokenManager {
|
|
321
|
+
private static instance;
|
|
322
|
+
private readonly TOKEN_KEY;
|
|
323
|
+
private tokenCache;
|
|
324
|
+
private parsedTokenCache;
|
|
325
|
+
private expirationCheckInterval;
|
|
326
|
+
private storageEventListener;
|
|
327
|
+
/**
|
|
328
|
+
* Singleton pattern to ensure consistent token management
|
|
329
|
+
*/
|
|
330
|
+
static getInstance(): TokenManager;
|
|
331
|
+
/**
|
|
332
|
+
* Reset the singleton instance (useful for testing)
|
|
333
|
+
*/
|
|
334
|
+
static resetInstance(): void;
|
|
335
|
+
private constructor();
|
|
336
|
+
/**
|
|
337
|
+
* Initialize the token manager with storage synchronization
|
|
338
|
+
*/
|
|
339
|
+
private initializeTokenManager;
|
|
340
|
+
/**
|
|
341
|
+
* Migrate tokens from localStorage to sessionStorage for better security
|
|
342
|
+
* This ensures compatibility with older implementations
|
|
343
|
+
*/
|
|
344
|
+
private migrateFromLocalStorage;
|
|
345
|
+
/**
|
|
346
|
+
* Load token from storage and synchronize with crudify
|
|
347
|
+
*/
|
|
348
|
+
private loadTokenFromStorage;
|
|
349
|
+
/**
|
|
350
|
+
* Set up automatic token expiration checking
|
|
351
|
+
*/
|
|
352
|
+
private setupExpirationCheck;
|
|
353
|
+
/**
|
|
354
|
+
* Set up storage event listener for cross-tab synchronization
|
|
355
|
+
*/
|
|
356
|
+
private setupStorageListener;
|
|
357
|
+
/**
|
|
358
|
+
* Set a new JWT token with automatic synchronization
|
|
359
|
+
*/
|
|
360
|
+
setToken(token: string | null): void;
|
|
361
|
+
/**
|
|
362
|
+
* Get the current JWT token
|
|
363
|
+
*/
|
|
364
|
+
getToken(): string | null;
|
|
365
|
+
/**
|
|
366
|
+
* Parse the current JWT token
|
|
367
|
+
*/
|
|
368
|
+
parseToken(token?: string | null): JWTPayload$1 | null;
|
|
369
|
+
/**
|
|
370
|
+
* Check if a token is valid (properly formatted and not expired)
|
|
371
|
+
*/
|
|
372
|
+
isTokenValid(token?: string | null): boolean;
|
|
373
|
+
/**
|
|
374
|
+
* Get token expiration time as Date object
|
|
375
|
+
*/
|
|
376
|
+
getTokenExpiration(): Date | null;
|
|
377
|
+
/**
|
|
378
|
+
* Clear the current token from all storages and crudify
|
|
379
|
+
*/
|
|
380
|
+
clearToken(): void;
|
|
381
|
+
/**
|
|
382
|
+
* Synchronize token with crudify library
|
|
383
|
+
*/
|
|
384
|
+
private syncTokenWithCrudify;
|
|
385
|
+
/**
|
|
386
|
+
* Refresh token (placeholder for future implementation)
|
|
387
|
+
*/
|
|
388
|
+
refreshToken(): Promise<void>;
|
|
389
|
+
/**
|
|
390
|
+
* Get user information from the current token
|
|
391
|
+
*/
|
|
392
|
+
getUserInfo(): {
|
|
393
|
+
email: string | null;
|
|
394
|
+
userId: string | null;
|
|
395
|
+
userIdentifier: string | null;
|
|
396
|
+
username: string | null;
|
|
397
|
+
};
|
|
398
|
+
/**
|
|
399
|
+
* Check if user is currently authenticated
|
|
400
|
+
*/
|
|
401
|
+
isAuthenticated(): boolean;
|
|
402
|
+
/**
|
|
403
|
+
* Get time until token expires in minutes
|
|
404
|
+
*/
|
|
405
|
+
getTimeUntilExpiration(): number | null;
|
|
406
|
+
/**
|
|
407
|
+
* Cleanup resources (call when the component unmounts)
|
|
408
|
+
*/
|
|
409
|
+
cleanup(): void;
|
|
410
|
+
/**
|
|
411
|
+
* Get debug information about the current token state
|
|
412
|
+
*/
|
|
413
|
+
getDebugInfo(): {
|
|
414
|
+
hasToken: boolean;
|
|
415
|
+
tokenLength: number;
|
|
416
|
+
isValid: boolean;
|
|
417
|
+
isAuthenticated: boolean;
|
|
418
|
+
expiration: string | null;
|
|
419
|
+
minutesUntilExpiry: number | null;
|
|
420
|
+
userInfo: {
|
|
421
|
+
email: string | null;
|
|
422
|
+
userId: string | null;
|
|
423
|
+
userIdentifier: string | null;
|
|
424
|
+
username: string | null;
|
|
425
|
+
};
|
|
426
|
+
parsedTokenKeys: string[];
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Singleton instance for easy access
|
|
431
|
+
*/
|
|
432
|
+
declare const tokenManager: TokenManager;
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Context state interface for CrudifyDataProvider
|
|
436
|
+
*/
|
|
437
|
+
interface CrudifyDataContextState {
|
|
438
|
+
config: ResolvedConfig | null;
|
|
439
|
+
isConfigured: boolean;
|
|
440
|
+
configError: string | null;
|
|
441
|
+
configSource: string;
|
|
442
|
+
isInitialized: boolean;
|
|
443
|
+
isInitializing: boolean;
|
|
444
|
+
initializationError: string | null;
|
|
445
|
+
isAuthenticated: boolean;
|
|
446
|
+
token: string | null;
|
|
447
|
+
user: JWTPayload$1 | null;
|
|
448
|
+
tokenExpiration: Date | null;
|
|
449
|
+
setToken: (token: string | null) => void;
|
|
450
|
+
logout: () => void;
|
|
451
|
+
refreshConfig: () => void;
|
|
452
|
+
reinitialize: () => Promise<void>;
|
|
453
|
+
getDebugInfo: () => Record<string, any>;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Props for CrudifyDataProvider
|
|
457
|
+
*/
|
|
458
|
+
interface CrudifyDataProviderProps {
|
|
459
|
+
children: ReactNode;
|
|
460
|
+
env?: "dev" | "stg" | "prod";
|
|
461
|
+
publicApiKey?: string;
|
|
462
|
+
loginActions?: string[];
|
|
463
|
+
appName?: string;
|
|
464
|
+
logo?: string;
|
|
465
|
+
colors?: Record<string, string>;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* CrudifyDataProvider - The unified provider that encapsulates all crudify functionality
|
|
469
|
+
*
|
|
470
|
+
* This provider replaces the fragmented implementations in both crudia-ui and crudify-ui
|
|
471
|
+
* with a single, robust solution that handles:
|
|
472
|
+
*
|
|
473
|
+
* 1. Configuration management (props > env vars > cookies)
|
|
474
|
+
* 2. Crudify initialization (single, thread-safe initialization)
|
|
475
|
+
* 3. JWT token management (compatible with existing storage patterns)
|
|
476
|
+
* 4. Error handling and recovery
|
|
477
|
+
* 5. Cross-tab synchronization
|
|
478
|
+
*
|
|
479
|
+
* It maintains 100% backward compatibility with crudia-ui while providing
|
|
480
|
+
* enhanced functionality for crudify-ui.
|
|
481
|
+
*/
|
|
482
|
+
declare const CrudifyDataProvider: React.FC<CrudifyDataProviderProps>;
|
|
483
|
+
/**
|
|
484
|
+
* Hook to use the CrudifyDataProvider context
|
|
485
|
+
*/
|
|
486
|
+
declare const useCrudifyDataContext: () => CrudifyDataContextState;
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Return type for useCrudifyAuth hook
|
|
490
|
+
*/
|
|
491
|
+
interface UseCrudifyAuthReturn {
|
|
492
|
+
isAuthenticated: boolean;
|
|
493
|
+
loading: boolean;
|
|
494
|
+
error: string | null;
|
|
495
|
+
token: string | null;
|
|
496
|
+
user: JWTPayload$1 | null;
|
|
497
|
+
tokenExpiration: Date | null;
|
|
498
|
+
setToken: (token: string | null) => void;
|
|
499
|
+
logout: () => void;
|
|
500
|
+
refreshToken?: () => Promise<void>;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* useCrudifyAuth - Simplified hook for authentication state management
|
|
504
|
+
*
|
|
505
|
+
* This hook provides a clean interface for managing authentication state
|
|
506
|
+
* within the CrudifyDataProvider system. It abstracts away the complexity
|
|
507
|
+
* of token management, storage synchronization, and crudify integration.
|
|
508
|
+
*
|
|
509
|
+
* Features:
|
|
510
|
+
* - Real-time authentication status
|
|
511
|
+
* - Automatic token validation
|
|
512
|
+
* - Cross-tab synchronization
|
|
513
|
+
* - Simple login/logout actions
|
|
514
|
+
* - JWT payload access
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* ```tsx
|
|
518
|
+
* function LoginComponent() {
|
|
519
|
+
* const { isAuthenticated, login, logout, user } = useCrudifyAuth();
|
|
520
|
+
*
|
|
521
|
+
* if (isAuthenticated) {
|
|
522
|
+
* return (
|
|
523
|
+
* <div>
|
|
524
|
+
* Welcome {user?.email}!
|
|
525
|
+
* <button onClick={logout}>Logout</button>
|
|
526
|
+
* </div>
|
|
527
|
+
* );
|
|
528
|
+
* }
|
|
529
|
+
*
|
|
530
|
+
* return <LoginForm onLogin={login} />;
|
|
531
|
+
* }
|
|
532
|
+
* ```
|
|
533
|
+
*/
|
|
534
|
+
declare const useCrudifyAuth: () => UseCrudifyAuthReturn;
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Extended user data with formatted information
|
|
538
|
+
*/
|
|
539
|
+
interface ExtendedUserData {
|
|
540
|
+
fullProfile: UserProfile | null;
|
|
541
|
+
totalFields: number;
|
|
542
|
+
displayData: Record<string, any>;
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Return type for useCrudifyUser hook
|
|
546
|
+
*/
|
|
547
|
+
interface UseCrudifyUserReturn {
|
|
548
|
+
userEmail: string | null;
|
|
549
|
+
userId: string | null;
|
|
550
|
+
userIdentifier: string | null;
|
|
551
|
+
userProfile: UserProfile | null;
|
|
552
|
+
profileLoading: boolean;
|
|
553
|
+
profileError: string | null;
|
|
554
|
+
extendedData: ExtendedUserData;
|
|
555
|
+
refreshProfile: () => Promise<void>;
|
|
556
|
+
clearProfile: () => void;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Options for useCrudifyUser hook
|
|
560
|
+
*/
|
|
561
|
+
interface UseCrudifyUserOptions {
|
|
562
|
+
autoFetch?: boolean;
|
|
563
|
+
retryOnError?: boolean;
|
|
564
|
+
maxRetries?: number;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* useCrudifyUser - Comprehensive user data management hook
|
|
568
|
+
*
|
|
569
|
+
* This hook provides complete user data management by combining:
|
|
570
|
+
* 1. JWT token data (basic user information)
|
|
571
|
+
* 2. Database profile data (complete user profile)
|
|
572
|
+
* 3. Extended formatted data for display
|
|
573
|
+
*
|
|
574
|
+
* It automatically fetches user profile data from the database when
|
|
575
|
+
* the user is authenticated and provides intelligent caching,
|
|
576
|
+
* error handling, and retry mechanisms.
|
|
577
|
+
*
|
|
578
|
+
* Features:
|
|
579
|
+
* - Automatic profile fetching when authenticated
|
|
580
|
+
* - Intelligent caching and deduplication
|
|
581
|
+
* - Retry mechanism for network errors
|
|
582
|
+
* - Cross-tab synchronization
|
|
583
|
+
* - Extended data formatting for easy display
|
|
584
|
+
* - Proper cleanup and memory management
|
|
585
|
+
*
|
|
586
|
+
* @example
|
|
587
|
+
* ```tsx
|
|
588
|
+
* function UserProfilePage() {
|
|
589
|
+
* const {
|
|
590
|
+
* userEmail,
|
|
591
|
+
* userProfile,
|
|
592
|
+
* profileLoading,
|
|
593
|
+
* extendedData,
|
|
594
|
+
* refreshProfile
|
|
595
|
+
* } = useCrudifyUser({ autoFetch: true });
|
|
596
|
+
*
|
|
597
|
+
* if (profileLoading) return <LoadingSpinner />;
|
|
598
|
+
*
|
|
599
|
+
* return (
|
|
600
|
+
* <div>
|
|
601
|
+
* <h1>Welcome {userProfile?.fullName || userEmail}</h1>
|
|
602
|
+
* <p>Total fields: {extendedData.totalFields}</p>
|
|
603
|
+
* <button onClick={refreshProfile}>Refresh</button>
|
|
604
|
+
* </div>
|
|
605
|
+
* );
|
|
606
|
+
* }
|
|
607
|
+
* ```
|
|
608
|
+
*/
|
|
609
|
+
declare const useCrudifyUser: (options?: UseCrudifyUserOptions) => UseCrudifyUserReturn;
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Return type for useCrudifyData hook
|
|
613
|
+
*/
|
|
614
|
+
interface UseCrudifyDataReturn {
|
|
615
|
+
readItems: (moduleKey: string, filter?: object, options?: any) => Promise<CrudifyApiResponse>;
|
|
616
|
+
readItem: (moduleKey: string, filter: object, options?: any) => Promise<CrudifyApiResponse>;
|
|
617
|
+
createItem: (moduleKey: string, data: object, options?: any) => Promise<CrudifyApiResponse>;
|
|
618
|
+
updateItem: (moduleKey: string, data: object, options?: any) => Promise<CrudifyApiResponse>;
|
|
619
|
+
deleteItem: (moduleKey: string, id: string, options?: any) => Promise<CrudifyApiResponse>;
|
|
620
|
+
transaction: (operations: any[], options?: any) => Promise<CrudifyApiResponse>;
|
|
621
|
+
login: (email: string, password: string) => Promise<CrudifyApiResponse>;
|
|
622
|
+
isInitialized: boolean;
|
|
623
|
+
isInitializing: boolean;
|
|
624
|
+
initializationError: string | null;
|
|
625
|
+
isReady: () => boolean;
|
|
626
|
+
waitForReady: () => Promise<void>;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* useCrudifyData - Comprehensive hook for crudify operations
|
|
630
|
+
*
|
|
631
|
+
* This hook provides a clean interface for all crudify database operations
|
|
632
|
+
* with automatic initialization checking, error handling, and loading states.
|
|
633
|
+
* It ensures that all operations are only executed when crudify is properly
|
|
634
|
+
* initialized and configured.
|
|
635
|
+
*
|
|
636
|
+
* Features:
|
|
637
|
+
* - Automatic initialization checking
|
|
638
|
+
* - Type-safe CRUD operations
|
|
639
|
+
* - Transaction support
|
|
640
|
+
* - Login operations
|
|
641
|
+
* - Ready state management
|
|
642
|
+
* - Proper error handling
|
|
643
|
+
*
|
|
644
|
+
* All operations will throw an error if crudify is not properly initialized,
|
|
645
|
+
* ensuring data integrity and preventing silent failures.
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
* ```tsx
|
|
649
|
+
* function DataComponent() {
|
|
650
|
+
* const {
|
|
651
|
+
* readItems,
|
|
652
|
+
* createItem,
|
|
653
|
+
* isInitialized,
|
|
654
|
+
* isReady
|
|
655
|
+
* } = useCrudifyData();
|
|
656
|
+
*
|
|
657
|
+
* const loadUsers = async () => {
|
|
658
|
+
* if (!isReady()) {
|
|
659
|
+
* console.warn("Crudify not ready yet");
|
|
660
|
+
* return;
|
|
661
|
+
* }
|
|
662
|
+
*
|
|
663
|
+
* try {
|
|
664
|
+
* const response = await readItems("users", { limit: 10 });
|
|
665
|
+
* if (response.success) {
|
|
666
|
+
* console.log("Users:", response.data);
|
|
667
|
+
* }
|
|
668
|
+
* } catch (error) {
|
|
669
|
+
* console.error("Error loading users:", error);
|
|
670
|
+
* }
|
|
671
|
+
* };
|
|
672
|
+
*
|
|
673
|
+
* return (
|
|
674
|
+
* <div>
|
|
675
|
+
* <button onClick={loadUsers} disabled={!isInitialized}>
|
|
676
|
+
* Load Users
|
|
677
|
+
* </button>
|
|
678
|
+
* </div>
|
|
679
|
+
* );
|
|
680
|
+
* }
|
|
681
|
+
* ```
|
|
682
|
+
*/
|
|
683
|
+
declare const useCrudifyData: () => UseCrudifyDataReturn;
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Return type for useCrudifyConfig hook
|
|
687
|
+
*/
|
|
688
|
+
interface UseCrudifyConfigReturn {
|
|
689
|
+
config: ResolvedConfig | null;
|
|
690
|
+
isConfigured: boolean;
|
|
691
|
+
configError: string | null;
|
|
692
|
+
configSource: string;
|
|
693
|
+
rawConfig: Record<string, any>;
|
|
694
|
+
refreshConfig: () => void;
|
|
695
|
+
getDebugInfo: () => Record<string, any>;
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* useCrudifyConfig - Configuration access and debugging hook
|
|
699
|
+
*
|
|
700
|
+
* This hook provides access to the current crudify configuration,
|
|
701
|
+
* including source tracking for debugging and configuration validation.
|
|
702
|
+
* It's particularly useful for development and troubleshooting
|
|
703
|
+
* configuration issues across different environments.
|
|
704
|
+
*
|
|
705
|
+
* Features:
|
|
706
|
+
* - Current configuration access
|
|
707
|
+
* - Source tracking (props, env, cookies, defaults)
|
|
708
|
+
* - Configuration validation status
|
|
709
|
+
* - Debug information for troubleshooting
|
|
710
|
+
* - Configuration refresh capability
|
|
711
|
+
*
|
|
712
|
+
* @example
|
|
713
|
+
* ```tsx
|
|
714
|
+
* function ConfigDebugComponent() {
|
|
715
|
+
* const {
|
|
716
|
+
* config,
|
|
717
|
+
* isConfigured,
|
|
718
|
+
* configError,
|
|
719
|
+
* configSource,
|
|
720
|
+
* getDebugInfo
|
|
721
|
+
* } = useCrudifyConfig();
|
|
722
|
+
*
|
|
723
|
+
* if (!isConfigured) {
|
|
724
|
+
* return (
|
|
725
|
+
* <div>
|
|
726
|
+
* <h3>Configuration Error</h3>
|
|
727
|
+
* <p>{configError}</p>
|
|
728
|
+
* </div>
|
|
729
|
+
* );
|
|
730
|
+
* }
|
|
731
|
+
*
|
|
732
|
+
* return (
|
|
733
|
+
* <div>
|
|
734
|
+
* <h3>Current Configuration</h3>
|
|
735
|
+
* <p>Environment: {config?.env}</p>
|
|
736
|
+
* <p>App Name: {config?.appName}</p>
|
|
737
|
+
* <p>Source: {configSource}</p>
|
|
738
|
+
* <pre>{JSON.stringify(getDebugInfo(), null, 2)}</pre>
|
|
739
|
+
* </div>
|
|
740
|
+
* );
|
|
741
|
+
* }
|
|
742
|
+
* ```
|
|
743
|
+
*/
|
|
744
|
+
declare const useCrudifyConfig: () => UseCrudifyConfigReturn;
|
|
745
|
+
|
|
118
746
|
interface UseUserProfileOptions {
|
|
119
747
|
autoFetch?: boolean;
|
|
120
748
|
retryOnError?: boolean;
|
|
@@ -124,6 +752,7 @@ interface UseUserProfileReturn {
|
|
|
124
752
|
userProfile: UserProfile | null;
|
|
125
753
|
loading: boolean;
|
|
126
754
|
error: string | null;
|
|
755
|
+
extendedData: Record<string, any>;
|
|
127
756
|
refreshProfile: () => Promise<void>;
|
|
128
757
|
clearProfile: () => void;
|
|
129
758
|
}
|
|
@@ -218,4 +847,4 @@ declare function parseJavaScriptError(error: unknown): ParsedError;
|
|
|
218
847
|
*/
|
|
219
848
|
declare function handleCrudifyError(error: unknown): ParsedError[];
|
|
220
849
|
|
|
221
|
-
export { type ApiError, type BoxScreenType, type CrudifyApiResponse, CrudifyLogin, type CrudifyLoginConfig, type CrudifyLoginProps, type CrudifyLoginTranslations, type CrudifyTransactionResponse, ERROR_CODES, ERROR_SEVERITY_MAP, type ErrorCode, type ErrorSeverity, type ForgotPasswordRequest, type JwtPayload, type LoginRequest, type LoginResponse, type ParsedError, type ResetPasswordRequest, type TransactionResponseData, type UserProfile, type ValidateCodeRequest, type ValidationError, decodeJwtSafely, getCookie, getCurrentUserEmail, getErrorMessage, handleCrudifyError, isTokenExpired, parseApiError, parseJavaScriptError, parseTransactionError, secureLocalStorage, secureSessionStorage, useCrudifyLogin, useUserProfile };
|
|
850
|
+
export { type ApiError, type BoxScreenType, type CrudifyApiResponse, type CrudifyConfig, type CrudifyDataContextState, CrudifyDataProvider, type CrudifyDataProviderProps, CrudifyLogin, type CrudifyLoginConfig, type CrudifyLoginProps, type CrudifyLoginTranslations, type CrudifyTransactionResponse, ERROR_CODES, ERROR_SEVERITY_MAP, type ErrorCode, type ErrorSeverity, type ExtendedUserData, type ForgotPasswordRequest, type JWTPayload$1 as JWTPayload, type JwtPayload, type LoginRequest, type LoginResponse, type ParsedError, type ResetPasswordRequest, type ResolvedConfig, type TransactionResponseData, type UseCrudifyAuthReturn, type UseCrudifyConfigReturn, type UseCrudifyDataReturn, type UseCrudifyUserOptions, type UseCrudifyUserReturn, type UserProfile, UserProfileDisplay, type ValidateCodeRequest, type ValidationError, configurationManager, crudifyInitializer, decodeJwtSafely, getCookie, getCurrentUserEmail, getErrorMessage, handleCrudifyError, isTokenExpired, parseApiError, parseJavaScriptError, parseTransactionError, secureLocalStorage, secureSessionStorage, tokenManager, useCrudifyAuth, useCrudifyConfig, useCrudifyData, useCrudifyDataContext, useCrudifyLogin, useCrudifyUser, useUserProfile };
|