@nocios/crudify-ui 2.0.1 → 3.0.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
@@ -1,4 +1,3 @@
1
- import crudify__default from '@nocios/crudify-browser';
2
1
  export * from '@nocios/crudify-browser';
3
2
  export { default as crudify } from '@nocios/crudify-browser';
4
3
  import React, { ReactNode } from 'react';
@@ -158,792 +157,6 @@ interface ValidationError {
158
157
  code: string;
159
158
  }
160
159
 
161
- /**
162
- * Configuration interface for CrudifyDataProvider
163
- * Supports multi-tenant configurations via environment variables, cookies, or direct props
164
- */
165
- interface CrudifyConfig {
166
- env?: "dev" | "stg" | "prod";
167
- publicApiKey?: string;
168
- loginActions?: string[];
169
- appName?: string;
170
- logo?: string;
171
- colors?: Record<string, string>;
172
- }
173
- /**
174
- * Source of configuration values for debugging and validation
175
- */
176
- type ConfigSource = "props" | "env" | "cookies" | "default";
177
- /**
178
- * Detailed configuration with source tracking for debugging
179
- */
180
- interface ResolvedConfig extends Required<CrudifyConfig> {
181
- configSource: Record<keyof CrudifyConfig, ConfigSource>;
182
- rawConfig: Record<string, any>;
183
- }
184
- /**
185
- * Configuration Manager for CrudifyDataProvider
186
- *
187
- * Handles configuration priority:
188
- * 1. Props passed explicitly to the Provider
189
- * 2. Environment variables (VITE_TEST_*)
190
- * 3. Cookies (for multi-tenant)
191
- * 4. Default values or error if required fields missing
192
- *
193
- * This ensures compatibility with both crudia-ui (cookie-based) and crudify-ui (env-based)
194
- */
195
- declare class ConfigurationManager {
196
- private static instance;
197
- private resolvedConfig;
198
- private configError;
199
- /**
200
- * Singleton pattern to ensure consistent configuration across the app
201
- */
202
- static getInstance(): ConfigurationManager;
203
- /**
204
- * Reset the singleton instance (useful for testing)
205
- */
206
- static resetInstance(): void;
207
- private constructor();
208
- /**
209
- * Resolve configuration from all sources with proper priority
210
- */
211
- resolveConfig(propsConfig?: Partial<CrudifyConfig>): ResolvedConfig;
212
- /**
213
- * Check if current configuration is still valid for the given props
214
- */
215
- private isConfigStillValid;
216
- /**
217
- * Resolve a single config value with priority and source tracking
218
- */
219
- private resolveValue;
220
- /**
221
- * Obtener configuración de variables de entorno
222
- */
223
- private getEnvConfig;
224
- /**
225
- * Obtener configuración de cookies (soporte multi-tenant)
226
- */
227
- private getCookieConfig;
228
- /**
229
- * Get the current resolved configuration
230
- */
231
- getConfig(): ResolvedConfig | null;
232
- /**
233
- * Get any configuration errors
234
- */
235
- getConfigError(): string | null;
236
- /**
237
- * Check if configuration is valid (no errors and has required fields)
238
- */
239
- isConfigured(): boolean;
240
- /**
241
- * Clear the current configuration (useful for testing or reconfiguration)
242
- */
243
- clearConfig(): void;
244
- }
245
- /**
246
- * Singleton instance for easy access
247
- */
248
- declare const configurationManager: ConfigurationManager;
249
-
250
- /**
251
- * CrudifyInitializer handles the critical task of initializing the crudify library
252
- * exactly once, preventing the "Crudify: Not initialized" and double initialization errors
253
- * that occur when both crudia-ui and crudify-ui try to initialize crudify independently.
254
- *
255
- * This is a singleton that ensures:
256
- * 1. Only one initialization attempt at a time
257
- * 2. Subsequent calls wait for the first initialization to complete
258
- * 3. Proper error handling and recovery
259
- * 4. Verification that crudify methods are available after initialization
260
- * 5. Thread-safe initialization in React's concurrent mode
261
- */
262
- declare class CrudifyInitializer {
263
- private static instance;
264
- private state;
265
- /**
266
- * Singleton pattern to ensure global initialization coordination
267
- */
268
- static getInstance(): CrudifyInitializer;
269
- /**
270
- * Reset the singleton instance (useful for testing)
271
- */
272
- static resetInstance(): void;
273
- private constructor();
274
- /**
275
- * Inicializar crudify con la configuración dada
276
- * Este método es idempotente y thread-safe
277
- */
278
- initialize(config: CrudifyConfig): Promise<void>;
279
- /**
280
- * Realizar el proceso de inicialización actual
281
- */
282
- private performInitialization;
283
- /**
284
- * Verificar que crudify esté correctamente inicializado revisando métodos principales
285
- */
286
- private verifyInitialization;
287
- /**
288
- * Verificar si la configuración dada es la misma que la actual
289
- */
290
- private isConfigurationSame;
291
- /**
292
- * Resetear el estado de inicialización (útil para testing o cambios de configuración)
293
- */
294
- reset(): void;
295
- /**
296
- * Obtener el estado actual de inicialización
297
- */
298
- getStatus(): {
299
- isInitialized: boolean;
300
- isInitializing: boolean;
301
- initializationError: string | null;
302
- config: CrudifyConfig | null;
303
- };
304
- /**
305
- * Verificar si crudify está listo para usar
306
- */
307
- isReady(): boolean;
308
- /**
309
- * Obtener el error de inicialización actual, si existe
310
- */
311
- getError(): string | null;
312
- /**
313
- * Forzar re-inicialización (útil cuando la configuración cambia)
314
- */
315
- reinitialize(config: CrudifyConfig): Promise<void>;
316
- /**
317
- * Verificar si la inicialización está actualmente en progreso
318
- */
319
- isInitializing(): boolean;
320
- /**
321
- * Esperar a que cualquier inicialización en curso se complete
322
- */
323
- waitForInitialization(): Promise<void>;
324
- }
325
- /**
326
- * Instancia singleton para fácil acceso
327
- */
328
- declare const crudifyInitializer: CrudifyInitializer;
329
-
330
- /**
331
- * Enhanced JWT payload interface with Cognito-specific fields
332
- */
333
- interface JWTPayload$1 extends JwtPayload {
334
- "cognito:username"?: string;
335
- }
336
- /**
337
- * TokenManager handles all JWT token operations with automatic synchronization
338
- * between storage and crudify library. It maintains 100% compatibility with
339
- * the existing crudia-ui storage patterns while providing enhanced functionality.
340
- *
341
- * Key features:
342
- * - Automatic storage <-> crudify synchronization
343
- * - Token validation and expiration checking
344
- * - Migration support from plain localStorage to encrypted localStorage
345
- * - Backward compatibility with existing token storage keys
346
- * - Automatic cleanup of expired tokens
347
- */
348
- declare class TokenManager {
349
- private static instance;
350
- private readonly TOKEN_KEY;
351
- private tokenCache;
352
- private parsedTokenCache;
353
- private expirationCheckInterval;
354
- private storageEventListener;
355
- /**
356
- * Singleton pattern to ensure consistent token management
357
- */
358
- static getInstance(): TokenManager;
359
- /**
360
- * Reset the singleton instance (useful for testing)
361
- */
362
- static resetInstance(): void;
363
- private constructor();
364
- /**
365
- * Initialize the token manager with storage synchronization
366
- */
367
- private initializeTokenManager;
368
- /**
369
- * Migrate tokens from plain localStorage to encrypted localStorage
370
- * This ensures compatibility with older implementations
371
- */
372
- private migrateFromLocalStorage;
373
- /**
374
- * Load token from storage and synchronize with crudify
375
- */
376
- private loadTokenFromStorage;
377
- /**
378
- * Set up automatic token expiration checking
379
- */
380
- private setupExpirationCheck;
381
- /**
382
- * Set up storage event listener for cross-tab synchronization
383
- */
384
- private setupStorageListener;
385
- /**
386
- * Set a new JWT token with automatic synchronization
387
- */
388
- setToken(token: string | null): void;
389
- /**
390
- * Get the current JWT token
391
- */
392
- getToken(): string | null;
393
- /**
394
- * Parse the current JWT token
395
- */
396
- parseToken(token?: string | null): JWTPayload$1 | null;
397
- /**
398
- * Check if a token is valid (properly formatted and not expired)
399
- */
400
- isTokenValid(token?: string | null): boolean;
401
- /**
402
- * Get token expiration time as Date object
403
- */
404
- getTokenExpiration(): Date | null;
405
- /**
406
- * Clear the current token from all storages and crudify
407
- */
408
- clearToken(): void;
409
- /**
410
- * Synchronize token with crudify library
411
- */
412
- private syncTokenWithCrudify;
413
- /**
414
- * Refresh token (placeholder for future implementation)
415
- */
416
- refreshToken(): Promise<void>;
417
- /**
418
- * Get user information from the current token
419
- */
420
- getUserInfo(): {
421
- email: string | null;
422
- userId: string | null;
423
- userIdentifier: string | null;
424
- username: string | null;
425
- };
426
- /**
427
- * Check if user is currently authenticated
428
- */
429
- isAuthenticated(): boolean;
430
- /**
431
- * Get time until token expires in minutes
432
- */
433
- getTimeUntilExpiration(): number | null;
434
- /**
435
- * Cleanup resources (call when the component unmounts)
436
- */
437
- cleanup(): void;
438
- /**
439
- * Get debug information about the current token state
440
- */
441
- getDebugInfo(): {
442
- hasToken: boolean;
443
- tokenLength: number;
444
- isValid: boolean;
445
- isAuthenticated: boolean;
446
- expiration: string | null;
447
- minutesUntilExpiry: number | null;
448
- userInfo: {
449
- email: string | null;
450
- userId: string | null;
451
- userIdentifier: string | null;
452
- username: string | null;
453
- };
454
- parsedTokenKeys: string[];
455
- };
456
- }
457
- /**
458
- * Singleton instance for easy access
459
- */
460
- declare const tokenManager: TokenManager;
461
-
462
- /**
463
- * Context state interface for CrudifyDataProvider
464
- */
465
- interface CrudifyDataContextState {
466
- config: ResolvedConfig | null;
467
- isConfigured: boolean;
468
- configError: string | null;
469
- configSource: string;
470
- isInitialized: boolean;
471
- isInitializing: boolean;
472
- initializationError: string | null;
473
- isAuthenticated: boolean;
474
- token: string | null;
475
- user: JWTPayload$1 | null;
476
- tokenExpiration: Date | null;
477
- setToken: (token: string | null) => void;
478
- logout: () => void;
479
- refreshConfig: () => void;
480
- reinitialize: () => Promise<void>;
481
- getDebugInfo: () => Record<string, any>;
482
- }
483
- /**
484
- * Props for CrudifyDataProvider
485
- */
486
- interface CrudifyDataProviderProps {
487
- children: ReactNode;
488
- env?: "dev" | "stg" | "prod";
489
- publicApiKey?: string;
490
- loginActions?: string[];
491
- appName?: string;
492
- logo?: string;
493
- colors?: Record<string, string>;
494
- }
495
- /**
496
- * CrudifyDataProvider - The unified provider that encapsulates all crudify functionality
497
- *
498
- * This provider replaces the fragmented implementations in both crudia-ui and crudify-ui
499
- * with a single, robust solution that handles:
500
- *
501
- * 1. Configuration management (props > env vars > cookies)
502
- * 2. Crudify initialization (single, thread-safe initialization)
503
- * 3. JWT token management (compatible with existing storage patterns)
504
- * 4. Error handling and recovery
505
- * 5. Cross-tab synchronization
506
- *
507
- * It maintains 100% backward compatibility with crudia-ui while providing
508
- * enhanced functionality for crudify-ui.
509
- */
510
- declare const CrudifyDataProvider: React.FC<CrudifyDataProviderProps>;
511
- /**
512
- * Hook para usar el contexto de CrudifyDataProvider
513
- */
514
- declare const useCrudifyDataContext: () => CrudifyDataContextState;
515
-
516
- /**
517
- * Return type for useCrudifyAuth hook
518
- */
519
- interface UseCrudifyAuthReturn {
520
- isAuthenticated: boolean;
521
- loading: boolean;
522
- error: string | null;
523
- token: string | null;
524
- user: JWTPayload$1 | null;
525
- tokenExpiration: Date | null;
526
- setToken: (token: string | null) => void;
527
- logout: () => void;
528
- refreshToken?: () => Promise<void>;
529
- }
530
- /**
531
- * useCrudifyAuth - Simplified hook for authentication state management
532
- *
533
- * This hook provides a clean interface for managing authentication state
534
- * within the CrudifyDataProvider system. It abstracts away the complexity
535
- * of token management, storage synchronization, and crudify integration.
536
- *
537
- * Features:
538
- * - Real-time authentication status
539
- * - Automatic token validation
540
- * - Cross-tab synchronization
541
- * - Simple login/logout actions
542
- * - JWT payload access
543
- *
544
- * @example
545
- * ```tsx
546
- * function LoginComponent() {
547
- * const { isAuthenticated, login, logout, user } = useCrudifyAuth();
548
- *
549
- * if (isAuthenticated) {
550
- * return (
551
- * <div>
552
- * Welcome {user?.email}!
553
- * <button onClick={logout}>Logout</button>
554
- * </div>
555
- * );
556
- * }
557
- *
558
- * return <LoginForm onLogin={login} />;
559
- * }
560
- * ```
561
- */
562
- declare const useCrudifyAuth: () => UseCrudifyAuthReturn;
563
-
564
- /**
565
- * Complete user data structure
566
- */
567
- interface CrudifyUserData {
568
- session: JWTPayload$1 | null;
569
- data: UserProfile | null;
570
- }
571
- /**
572
- * Return type for useCrudifyUser hook
573
- */
574
- interface UseCrudifyUserReturn {
575
- user: CrudifyUserData;
576
- loading: boolean;
577
- error: string | null;
578
- refreshProfile: () => Promise<void>;
579
- clearProfile: () => void;
580
- }
581
- /**
582
- * Options for useCrudifyUser hook
583
- */
584
- interface UseCrudifyUserOptions {
585
- autoFetch?: boolean;
586
- retryOnError?: boolean;
587
- maxRetries?: number;
588
- }
589
- /**
590
- * useCrudifyUser - Comprehensive user data management hook
591
- *
592
- * This hook provides complete user data management by combining:
593
- * 1. JWT token data (basic user information)
594
- * 2. Database profile data (complete user profile)
595
- * 3. Extended formatted data for display
596
- *
597
- * It automatically fetches user profile data from the database when
598
- * the user is authenticated and provides intelligent caching,
599
- * error handling, and retry mechanisms.
600
- *
601
- * Features:
602
- * - Automatic profile fetching when authenticated
603
- * - Intelligent caching and deduplication
604
- * - Retry mechanism for network errors
605
- * - Cross-tab synchronization
606
- * - Extended data formatting for easy display
607
- * - Proper cleanup and memory management
608
- *
609
- * @example
610
- * ```tsx
611
- * function UserProfilePage() {
612
- * const {
613
- * user,
614
- * loading,
615
- * error,
616
- * refreshProfile
617
- * } = useCrudifyUser({ autoFetch: true });
618
- *
619
- * if (loading) return <LoadingSpinner />;
620
- * if (error) return <div>Error: {error}</div>;
621
- *
622
- * return (
623
- * <div>
624
- * <h1>Welcome {user.data?.fullName || user.session?.email}</h1>
625
- * <p>Session data: {JSON.stringify(user.session, null, 2)}</p>
626
- * <p>Profile data: {JSON.stringify(user.data, null, 2)}</p>
627
- * <button onClick={refreshProfile}>Refresh</button>
628
- * </div>
629
- * );
630
- * }
631
- * ```
632
- */
633
- declare const useCrudifyUser: (options?: UseCrudifyUserOptions) => UseCrudifyUserReturn;
634
-
635
- /**
636
- * Return type for useCrudifyData hook
637
- */
638
- interface UseCrudifyDataReturn {
639
- readItems: (moduleKey: string, filter?: object, options?: any) => Promise<CrudifyApiResponse>;
640
- readItem: (moduleKey: string, filter: object, options?: any) => Promise<CrudifyApiResponse>;
641
- createItem: (moduleKey: string, data: object, options?: any) => Promise<CrudifyApiResponse>;
642
- updateItem: (moduleKey: string, data: object, options?: any) => Promise<CrudifyApiResponse>;
643
- deleteItem: (moduleKey: string, id: string, options?: any) => Promise<CrudifyApiResponse>;
644
- transaction: (operations: any[], options?: any) => Promise<CrudifyApiResponse>;
645
- login: (email: string, password: string) => Promise<CrudifyApiResponse>;
646
- isInitialized: boolean;
647
- isInitializing: boolean;
648
- initializationError: string | null;
649
- isReady: () => boolean;
650
- waitForReady: () => Promise<void>;
651
- }
652
- /**
653
- * useCrudifyData - Comprehensive hook for crudify operations
654
- *
655
- * This hook provides a clean interface for all crudify database operations
656
- * with automatic initialization checking, error handling, and loading states.
657
- * It ensures that all operations are only executed when crudify is properly
658
- * initialized and configured.
659
- *
660
- * Features:
661
- * - Automatic initialization checking
662
- * - Type-safe CRUD operations
663
- * - Transaction support
664
- * - Login operations
665
- * - Ready state management
666
- * - Proper error handling
667
- *
668
- * All operations will throw an error if crudify is not properly initialized,
669
- * ensuring data integrity and preventing silent failures.
670
- *
671
- * @example
672
- * ```tsx
673
- * function DataComponent() {
674
- * const {
675
- * readItems,
676
- * createItem,
677
- * isInitialized,
678
- * isReady
679
- * } = useCrudifyData();
680
- *
681
- * const loadUsers = async () => {
682
- * if (!isReady()) {
683
- * console.warn("Crudify not ready yet");
684
- * return;
685
- * }
686
- *
687
- * try {
688
- * const response = await readItems("users", { limit: 10 });
689
- * if (response.success) {
690
- * console.log("Users:", response.data);
691
- * }
692
- * } catch (error) {
693
- * console.error("Error loading users:", error);
694
- * }
695
- * };
696
- *
697
- * return (
698
- * <div>
699
- * <button onClick={loadUsers} disabled={!isInitialized}>
700
- * Load Users
701
- * </button>
702
- * </div>
703
- * );
704
- * }
705
- * ```
706
- */
707
- declare const useCrudifyData: () => UseCrudifyDataReturn;
708
-
709
- /**
710
- * Return type for useCrudifyConfig hook
711
- */
712
- interface UseCrudifyConfigReturn {
713
- config: ResolvedConfig | null;
714
- isConfigured: boolean;
715
- configError: string | null;
716
- configSource: string;
717
- rawConfig: Record<string, any>;
718
- refreshConfig: () => void;
719
- getDebugInfo: () => Record<string, any>;
720
- }
721
- /**
722
- * useCrudifyConfig - Configuration access and debugging hook
723
- *
724
- * This hook provides access to the current crudify configuration,
725
- * including source tracking for debugging and configuration validation.
726
- * It's particularly useful for development and troubleshooting
727
- * configuration issues across different environments.
728
- *
729
- * Features:
730
- * - Current configuration access
731
- * - Source tracking (props, env, cookies, defaults)
732
- * - Configuration validation status
733
- * - Debug information for troubleshooting
734
- * - Configuration refresh capability
735
- *
736
- * @example
737
- * ```tsx
738
- * function ConfigDebugComponent() {
739
- * const {
740
- * config,
741
- * isConfigured,
742
- * configError,
743
- * configSource,
744
- * getDebugInfo
745
- * } = useCrudifyConfig();
746
- *
747
- * if (!isConfigured) {
748
- * return (
749
- * <div>
750
- * <h3>Configuration Error</h3>
751
- * <p>{configError}</p>
752
- * </div>
753
- * );
754
- * }
755
- *
756
- * return (
757
- * <div>
758
- * <h3>Current Configuration</h3>
759
- * <p>Environment: {config?.env}</p>
760
- * <p>App Name: {config?.appName}</p>
761
- * <p>Source: {configSource}</p>
762
- * <pre>{JSON.stringify(getDebugInfo(), null, 2)}</pre>
763
- * </div>
764
- * );
765
- * }
766
- * ```
767
- */
768
- declare const useCrudifyConfig: () => UseCrudifyConfigReturn;
769
-
770
- /**
771
- * Return type for useCrudifyInstance hook
772
- */
773
- interface UseCrudifyInstanceReturn {
774
- getStructure: (options?: any) => Promise<CrudifyApiResponse>;
775
- getStructurePublic: (options?: any) => Promise<CrudifyApiResponse>;
776
- readItems: (moduleKey: string, filter?: object, options?: any) => Promise<CrudifyApiResponse>;
777
- readItem: (moduleKey: string, filter: object, options?: any) => Promise<CrudifyApiResponse>;
778
- createItem: (moduleKey: string, data: object, options?: any) => Promise<CrudifyApiResponse>;
779
- updateItem: (moduleKey: string, data: object, options?: any) => Promise<CrudifyApiResponse>;
780
- deleteItem: (moduleKey: string, id: string, options?: any) => Promise<CrudifyApiResponse>;
781
- transaction: (operations: any[], options?: any) => Promise<CrudifyApiResponse>;
782
- login: (email: string, password: string) => Promise<CrudifyApiResponse>;
783
- isReady: boolean;
784
- isInitialized: boolean;
785
- isInitializing: boolean;
786
- initializationError: string | null;
787
- waitForReady: () => Promise<void>;
788
- }
789
- /**
790
- * useCrudifyInstance - Hook that provides access to the initialized crudify instance
791
- *
792
- * This hook ensures that all parts of the application use the same, properly initialized
793
- * instance of crudify. It waits for initialization to complete and provides methods
794
- * that are guaranteed to work with the initialized instance.
795
- *
796
- * Key benefits:
797
- * - Single source of truth for crudify instance
798
- * - Automatic waiting for initialization
799
- * - Consistent error handling
800
- * - Type-safe operations
801
- *
802
- * @example
803
- * ```tsx
804
- * function MyComponent() {
805
- * const { getStructure, isReady } = useCrudifyInstance();
806
- *
807
- * const loadStructure = async () => {
808
- * if (!isReady) {
809
- * console.warn("Crudify not ready yet");
810
- * return;
811
- * }
812
- *
813
- * try {
814
- * const response = await getStructure();
815
- * if (response.success) {
816
- * console.log("Structure:", response.data);
817
- * }
818
- * } catch (error) {
819
- * console.error("Error loading structure:", error);
820
- * }
821
- * };
822
- *
823
- * return (
824
- * <button onClick={loadStructure} disabled={!isReady}>
825
- * Load Structure
826
- * </button>
827
- * );
828
- * }
829
- * ```
830
- */
831
- declare const useCrudifyInstance: () => UseCrudifyInstanceReturn;
832
- /**
833
- * Get the initialized crudify instance directly (for use outside React components)
834
- * This function waits for initialization to complete before returning the instance
835
- */
836
- declare const getCrudifyInstanceAsync: () => Promise<typeof crudify__default>;
837
- /**
838
- * Get crudify instance with manual ready check (for use outside React components)
839
- * Throws error if not ready - use getCrudifyInstanceAsync for automatic waiting
840
- */
841
- declare const getCrudifyInstanceSync: () => Promise<typeof crudify__default>;
842
-
843
- interface UseUserProfileOptions {
844
- autoFetch?: boolean;
845
- retryOnError?: boolean;
846
- maxRetries?: number;
847
- }
848
- interface UseUserProfileReturn {
849
- userProfile: UserProfile | null;
850
- loading: boolean;
851
- error: string | null;
852
- extendedData: Record<string, any>;
853
- refreshProfile: () => Promise<void>;
854
- clearProfile: () => void;
855
- }
856
- declare const useUserProfile: (options?: UseUserProfileOptions) => UseUserProfileReturn;
857
-
858
- interface UseCrudifyLoginOptions {
859
- showErrorNotifications?: boolean;
860
- showSuccessNotifications?: boolean;
861
- }
862
- declare const useCrudifyLogin: (config: CrudifyLoginConfig, _options?: UseCrudifyLoginOptions) => {
863
- config: {
864
- publicApiKey: string | null;
865
- env: "dev" | "stg" | "prod";
866
- appName: string;
867
- loginActions: string[];
868
- };
869
- };
870
-
871
- interface JWTPayload extends JwtPayload {
872
- "cognito:username"?: string;
873
- }
874
- declare const decodeJwtSafely: (token: string) => JWTPayload | null;
875
- declare const getCurrentUserEmail: () => string | null;
876
- declare const isTokenExpired: (token: string) => boolean;
877
-
878
- declare const getCookie: (name: string) => string | null;
879
-
880
- declare class SecureStorage {
881
- private readonly encryptionKey;
882
- private readonly storage;
883
- constructor(storageType?: "localStorage" | "sessionStorage");
884
- private generateEncryptionKey;
885
- setItem(key: string, value: string, expiryMinutes?: number): void;
886
- getItem(key: string): string | null;
887
- removeItem(key: string): void;
888
- setToken(token: string): void;
889
- getToken(): string | null;
890
- }
891
- declare const secureSessionStorage: SecureStorage;
892
- declare const secureLocalStorage: SecureStorage;
893
-
894
- declare const ERROR_CODES: {
895
- readonly INVALID_CREDENTIALS: "INVALID_CREDENTIALS";
896
- readonly UNAUTHORIZED: "UNAUTHORIZED";
897
- readonly INVALID_API_KEY: "INVALID_API_KEY";
898
- readonly USER_NOT_FOUND: "USER_NOT_FOUND";
899
- readonly USER_NOT_ACTIVE: "USER_NOT_ACTIVE";
900
- readonly NO_PERMISSION: "NO_PERMISSION";
901
- readonly ITEM_NOT_FOUND: "ITEM_NOT_FOUND";
902
- readonly NOT_FOUND: "NOT_FOUND";
903
- readonly IN_USE: "IN_USE";
904
- readonly FIELD_ERROR: "FIELD_ERROR";
905
- readonly BAD_REQUEST: "BAD_REQUEST";
906
- readonly INVALID_EMAIL: "INVALID_EMAIL";
907
- readonly INVALID_CODE: "INVALID_CODE";
908
- readonly INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR";
909
- readonly DATABASE_CONNECTION_ERROR: "DATABASE_CONNECTION_ERROR";
910
- readonly INVALID_CONFIGURATION: "INVALID_CONFIGURATION";
911
- readonly UNKNOWN_OPERATION: "UNKNOWN_OPERATION";
912
- readonly TOO_MANY_REQUESTS: "TOO_MANY_REQUESTS";
913
- readonly NETWORK_ERROR: "NETWORK_ERROR";
914
- readonly TIMEOUT_ERROR: "TIMEOUT_ERROR";
915
- };
916
- type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
917
- type ErrorSeverity = "info" | "warning" | "error" | "critical";
918
- declare const ERROR_SEVERITY_MAP: Record<ErrorCode, ErrorSeverity>;
919
- interface ParsedError {
920
- code: ErrorCode;
921
- message: string;
922
- severity: ErrorSeverity;
923
- field?: string;
924
- details?: Record<string, unknown>;
925
- }
926
- /**
927
- * Parse a Crudify API response and extract standardized error information
928
- */
929
- declare function parseApiError(response: unknown): ParsedError[];
930
- /**
931
- * Parse transaction response errors
932
- */
933
- declare function parseTransactionError(response: unknown): ParsedError[];
934
- /**
935
- * Get a human-readable error message for an error code
936
- */
937
- declare function getErrorMessage(code: ErrorCode): string;
938
- /**
939
- * Handle JavaScript/Network errors and convert to ParsedError
940
- */
941
- declare function parseJavaScriptError(error: unknown): ParsedError;
942
- /**
943
- * Universal error handler that can process any type of error from Crudify APIs
944
- */
945
- declare function handleCrudifyError(error: unknown): ParsedError[];
946
-
947
160
  type TokenData = {
948
161
  accessToken: string;
949
162
  refreshToken: string;
@@ -1356,4 +569,95 @@ interface UseDataReturn {
1356
569
  */
1357
570
  declare const useData: () => UseDataReturn;
1358
571
 
1359
- 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, POLICY_ACTIONS, PREFERRED_POLICY_ORDER, type ParsedError, Policies, type PolicyAction, 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 };
572
+ interface UseUserProfileOptions {
573
+ autoFetch?: boolean;
574
+ retryOnError?: boolean;
575
+ maxRetries?: number;
576
+ }
577
+ interface UseUserProfileReturn {
578
+ userProfile: UserProfile | null;
579
+ loading: boolean;
580
+ error: string | null;
581
+ extendedData: Record<string, any>;
582
+ refreshProfile: () => Promise<void>;
583
+ clearProfile: () => void;
584
+ }
585
+ declare const useUserProfile: (options?: UseUserProfileOptions) => UseUserProfileReturn;
586
+
587
+ interface JWTPayload extends JwtPayload {
588
+ "cognito:username"?: string;
589
+ }
590
+ declare const decodeJwtSafely: (token: string) => JWTPayload | null;
591
+ declare const getCurrentUserEmail: () => string | null;
592
+ declare const isTokenExpired: (token: string) => boolean;
593
+
594
+ declare const getCookie: (name: string) => string | null;
595
+
596
+ declare class SecureStorage {
597
+ private readonly encryptionKey;
598
+ private readonly storage;
599
+ constructor(storageType?: "localStorage" | "sessionStorage");
600
+ private generateEncryptionKey;
601
+ setItem(key: string, value: string, expiryMinutes?: number): void;
602
+ getItem(key: string): string | null;
603
+ removeItem(key: string): void;
604
+ setToken(token: string): void;
605
+ getToken(): string | null;
606
+ }
607
+ declare const secureSessionStorage: SecureStorage;
608
+ declare const secureLocalStorage: SecureStorage;
609
+
610
+ declare const ERROR_CODES: {
611
+ readonly INVALID_CREDENTIALS: "INVALID_CREDENTIALS";
612
+ readonly UNAUTHORIZED: "UNAUTHORIZED";
613
+ readonly INVALID_API_KEY: "INVALID_API_KEY";
614
+ readonly USER_NOT_FOUND: "USER_NOT_FOUND";
615
+ readonly USER_NOT_ACTIVE: "USER_NOT_ACTIVE";
616
+ readonly NO_PERMISSION: "NO_PERMISSION";
617
+ readonly ITEM_NOT_FOUND: "ITEM_NOT_FOUND";
618
+ readonly NOT_FOUND: "NOT_FOUND";
619
+ readonly IN_USE: "IN_USE";
620
+ readonly FIELD_ERROR: "FIELD_ERROR";
621
+ readonly BAD_REQUEST: "BAD_REQUEST";
622
+ readonly INVALID_EMAIL: "INVALID_EMAIL";
623
+ readonly INVALID_CODE: "INVALID_CODE";
624
+ readonly INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR";
625
+ readonly DATABASE_CONNECTION_ERROR: "DATABASE_CONNECTION_ERROR";
626
+ readonly INVALID_CONFIGURATION: "INVALID_CONFIGURATION";
627
+ readonly UNKNOWN_OPERATION: "UNKNOWN_OPERATION";
628
+ readonly TOO_MANY_REQUESTS: "TOO_MANY_REQUESTS";
629
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
630
+ readonly TIMEOUT_ERROR: "TIMEOUT_ERROR";
631
+ };
632
+ type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
633
+ type ErrorSeverity = "info" | "warning" | "error" | "critical";
634
+ declare const ERROR_SEVERITY_MAP: Record<ErrorCode, ErrorSeverity>;
635
+ interface ParsedError {
636
+ code: ErrorCode;
637
+ message: string;
638
+ severity: ErrorSeverity;
639
+ field?: string;
640
+ details?: Record<string, unknown>;
641
+ }
642
+ /**
643
+ * Parse a Crudify API response and extract standardized error information
644
+ */
645
+ declare function parseApiError(response: unknown): ParsedError[];
646
+ /**
647
+ * Parse transaction response errors
648
+ */
649
+ declare function parseTransactionError(response: unknown): ParsedError[];
650
+ /**
651
+ * Get a human-readable error message for an error code
652
+ */
653
+ declare function getErrorMessage(code: ErrorCode): string;
654
+ /**
655
+ * Handle JavaScript/Network errors and convert to ParsedError
656
+ */
657
+ declare function parseJavaScriptError(error: unknown): ParsedError;
658
+ /**
659
+ * Universal error handler that can process any type of error from Crudify APIs
660
+ */
661
+ declare function handleCrudifyError(error: unknown): ParsedError[];
662
+
663
+ 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, LoginComponent, type LoginRequest, type LoginResponse, type LoginResult, POLICY_ACTIONS, PREFERRED_POLICY_ORDER, type ParsedError, Policies, type PolicyAction, ProtectedRoute, type ProtectedRouteProps, type ResetPasswordRequest, type SessionConfig, SessionDebugInfo, SessionManager, SessionProvider, type SessionProviderProps, type SessionState, SessionStatus, type StorageType, type TokenData, TokenStorage, type TransactionResponseData, type UseAuthReturn, type UseDataReturn, type UseSessionOptions, type UseUserDataOptions, type UseUserDataReturn, type UserData, type UserLoginData, type UserProfile, UserProfileDisplay, type ValidateCodeRequest, type ValidationError, decodeJwtSafely, getCookie, getCurrentUserEmail, getErrorMessage, handleCrudifyError, isTokenExpired, parseApiError, parseJavaScriptError, parseTransactionError, secureLocalStorage, secureSessionStorage, useAuth, useData, useSession, useSessionContext, useUserData, useUserProfile };