@massimo.mazzoleni/cognito-max 1.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.
Files changed (64) hide show
  1. package/README.md +2410 -0
  2. package/dist/chunk-AD7T42HJ.js +3 -0
  3. package/dist/chunk-AD7T42HJ.js.map +1 -0
  4. package/dist/chunk-DKPFVGTY.js +683 -0
  5. package/dist/chunk-DKPFVGTY.js.map +1 -0
  6. package/dist/chunk-N4OQLBV6.js +135 -0
  7. package/dist/chunk-N4OQLBV6.js.map +1 -0
  8. package/dist/client-63FraVdm.d.ts +69 -0
  9. package/dist/client-BAoL8h4E.d.cts +69 -0
  10. package/dist/core/index.cjs +696 -0
  11. package/dist/core/index.cjs.map +1 -0
  12. package/dist/core/index.d.cts +3 -0
  13. package/dist/core/index.d.ts +3 -0
  14. package/dist/core/index.js +4 -0
  15. package/dist/core/index.js.map +1 -0
  16. package/dist/errors-BkUDHleb.d.cts +22 -0
  17. package/dist/errors-BkUDHleb.d.ts +22 -0
  18. package/dist/index.cjs +696 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/index.d.cts +3 -0
  21. package/dist/index.d.ts +3 -0
  22. package/dist/index.js +4 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/react/index.cjs +844 -0
  25. package/dist/react/index.cjs.map +1 -0
  26. package/dist/react/index.d.cts +104 -0
  27. package/dist/react/index.d.ts +104 -0
  28. package/dist/react/index.js +64 -0
  29. package/dist/react/index.js.map +1 -0
  30. package/dist/types-bxA1vonL.d.cts +113 -0
  31. package/dist/types-bxA1vonL.d.ts +113 -0
  32. package/dist/ui/index.cjs +1183 -0
  33. package/dist/ui/index.cjs.map +1 -0
  34. package/dist/ui/index.d.cts +241 -0
  35. package/dist/ui/index.d.ts +241 -0
  36. package/dist/ui/index.js +1109 -0
  37. package/dist/ui/index.js.map +1 -0
  38. package/package.json +81 -0
  39. package/src/core/client.ts +604 -0
  40. package/src/core/errors.ts +91 -0
  41. package/src/core/event-bus.ts +41 -0
  42. package/src/core/index.ts +5 -0
  43. package/src/core/internal/converters.ts +32 -0
  44. package/src/core/storage.ts +79 -0
  45. package/src/core/types.ts +87 -0
  46. package/src/index.ts +1 -0
  47. package/src/react/components/ProtectedRoute.tsx +56 -0
  48. package/src/react/context.tsx +126 -0
  49. package/src/react/hooks/useAuth.ts +75 -0
  50. package/src/react/hooks/useMfa.ts +19 -0
  51. package/src/react/hooks/useSession.ts +16 -0
  52. package/src/react/hooks/useUser.ts +24 -0
  53. package/src/react/index.ts +10 -0
  54. package/src/ui/components/ChangePasswordForm.tsx +105 -0
  55. package/src/ui/components/ForgotPasswordForm.tsx +159 -0
  56. package/src/ui/components/MfaSetupWizard.tsx +136 -0
  57. package/src/ui/components/RegisterForm.tsx +159 -0
  58. package/src/ui/components/SignInForm.tsx +296 -0
  59. package/src/ui/hooks/useChangePasswordForm.ts +81 -0
  60. package/src/ui/hooks/useForgotPasswordForm.ts +109 -0
  61. package/src/ui/hooks/useMfaSetup.ts +93 -0
  62. package/src/ui/hooks/useRegisterForm.ts +120 -0
  63. package/src/ui/hooks/useSignInForm.ts +245 -0
  64. package/src/ui/index.ts +31 -0
@@ -0,0 +1,113 @@
1
+ interface StorageAdapter {
2
+ getItem(key: string): string | null;
3
+ setItem(key: string, value: string): void;
4
+ removeItem(key: string): void;
5
+ clear?(): void;
6
+ }
7
+ declare class LocalStorageAdapter implements StorageAdapter {
8
+ getItem(key: string): string | null;
9
+ setItem(key: string, value: string): void;
10
+ removeItem(key: string): void;
11
+ clear(): void;
12
+ }
13
+ declare class SessionStorageAdapter implements StorageAdapter {
14
+ getItem(key: string): string | null;
15
+ setItem(key: string, value: string): void;
16
+ removeItem(key: string): void;
17
+ clear(): void;
18
+ }
19
+ declare class InMemoryStorageAdapter implements StorageAdapter {
20
+ private readonly store;
21
+ getItem(key: string): string | null;
22
+ setItem(key: string, value: string): void;
23
+ removeItem(key: string): void;
24
+ clear(): void;
25
+ }
26
+ declare class AutoStorageAdapter implements StorageAdapter {
27
+ private readonly delegate;
28
+ constructor();
29
+ getItem(key: string): string | null;
30
+ setItem(key: string, value: string): void;
31
+ removeItem(key: string): void;
32
+ clear(): void;
33
+ }
34
+
35
+ type AuthState = 'idle' | 'loading' | 'authenticated' | 'unauthenticated' | 'mfa_required' | 'new_password_required' | 'confirm_signup';
36
+ type MfaType = 'TOTP' | 'SMS' | 'NOMFA';
37
+ interface MfaSetupResult {
38
+ secretCode: string;
39
+ /** otpauth://totp/<issuer>:<email>?secret=<secret>&issuer=<issuer> */
40
+ qrCodeUri: string;
41
+ }
42
+ interface MfaPreference {
43
+ enabled: boolean;
44
+ preferred: MfaType | null;
45
+ totp: boolean;
46
+ sms: boolean;
47
+ }
48
+ interface AuthUser {
49
+ sub: string;
50
+ username: string;
51
+ email: string;
52
+ emailVerified: boolean;
53
+ groups: string[];
54
+ attributes: Record<string, string>;
55
+ }
56
+ interface AuthSession {
57
+ accessToken: string;
58
+ idToken: string;
59
+ refreshToken: string;
60
+ expiresAt: Date;
61
+ isValid(): boolean;
62
+ }
63
+ type SignInResult = {
64
+ status: 'SUCCESS';
65
+ user: AuthUser;
66
+ session: AuthSession;
67
+ } | {
68
+ status: 'MFA_REQUIRED';
69
+ mfaType: MfaType;
70
+ challengeSession: string;
71
+ } | {
72
+ status: 'NEW_PASSWORD_REQUIRED';
73
+ requiredAttributes: string[];
74
+ challengeSession: string;
75
+ } | {
76
+ status: 'MFA_SETUP_REQUIRED';
77
+ challengeSession: string;
78
+ } | {
79
+ status: 'CONFIRM_SIGNUP';
80
+ };
81
+
82
+ interface AuthConfig {
83
+ userPoolId: string;
84
+ clientId: string;
85
+ region: string;
86
+ storage?: StorageAdapter;
87
+ /** Rinnova il token automaticamente prima della scadenza. Default: true */
88
+ autoRefresh?: boolean;
89
+ /** Secondi prima della scadenza in cui scatta il refresh. Default: 300 */
90
+ refreshMarginSeconds?: number;
91
+ /** Label mostrata nell'app authenticator (es. "MioApp"). Default: clientId */
92
+ totpIssuer?: string;
93
+ }
94
+ interface ResolvedAuthConfig extends Required<AuthConfig> {
95
+ }
96
+ interface AuthEvents {
97
+ signedIn: AuthUser;
98
+ signedOut: void;
99
+ tokenRefreshed: AuthSession;
100
+ sessionExpired: void;
101
+ mfaRequired: {
102
+ mfaType: MfaType;
103
+ challengeSession: string;
104
+ };
105
+ newPasswordRequired: {
106
+ requiredAttributes: string[];
107
+ challengeSession: string;
108
+ };
109
+ userUpdated: AuthUser;
110
+ stateChanged: AuthState;
111
+ }
112
+
113
+ export { type AuthConfig as A, InMemoryStorageAdapter as I, LocalStorageAdapter as L, type MfaPreference as M, type ResolvedAuthConfig as R, SessionStorageAdapter as S, type AuthEvents as a, type AuthSession as b, type AuthState as c, type AuthUser as d, AutoStorageAdapter as e, type MfaSetupResult as f, type MfaType as g, type SignInResult as h, type StorageAdapter as i };