@vunexa/lixa 0.1.6-alpha.12 → 0.1.6-alpha.14

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 (41) hide show
  1. package/README.md +103 -689
  2. package/dist/credentials/credentials-manager.d.ts +65 -0
  3. package/dist/credentials/credentials-manager.d.ts.map +1 -0
  4. package/dist/credentials/hasher.d.ts +88 -0
  5. package/dist/credentials/hasher.d.ts.map +1 -0
  6. package/dist/credentials/index.d.ts +6 -0
  7. package/dist/credentials/index.d.ts.map +1 -0
  8. package/dist/credentials/local-storage.d.ts +20 -0
  9. package/dist/credentials/local-storage.d.ts.map +1 -0
  10. package/dist/credentials/policy.d.ts +12 -0
  11. package/dist/credentials/policy.d.ts.map +1 -0
  12. package/dist/credentials/types.d.ts +314 -0
  13. package/dist/credentials/types.d.ts.map +1 -0
  14. package/dist/dao/session-cache.d.ts.map +1 -1
  15. package/dist/dao/types.d.ts +19 -0
  16. package/dist/dao/types.d.ts.map +1 -1
  17. package/dist/errors.d.ts +61 -0
  18. package/dist/errors.d.ts.map +1 -1
  19. package/dist/export-types/index.d.ts +1187 -34
  20. package/dist/identity/index.d.ts +3 -0
  21. package/dist/identity/index.d.ts.map +1 -0
  22. package/dist/identity/self-managed.d.ts +52 -0
  23. package/dist/identity/self-managed.d.ts.map +1 -0
  24. package/dist/identity/types.d.ts +224 -0
  25. package/dist/identity/types.d.ts.map +1 -0
  26. package/dist/index.cjs +1408 -249
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +1149 -29
  29. package/dist/index.d.ts +6 -3
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1387 -237
  32. package/dist/index.js.map +1 -1
  33. package/dist/lixa.d.ts +165 -14
  34. package/dist/lixa.d.ts.map +1 -1
  35. package/dist/models/session.d.ts +9 -9
  36. package/dist/models/session.d.ts.map +1 -1
  37. package/dist/providers/IProvider.d.ts +4 -0
  38. package/dist/providers/IProvider.d.ts.map +1 -1
  39. package/dist/types.d.ts +97 -6
  40. package/dist/types.d.ts.map +1 -1
  41. package/package.json +3 -11
package/dist/index.d.cts CHANGED
@@ -101,33 +101,33 @@ interface ConnectedResource {
101
101
  */
102
102
  interface Session<TRaw = OAuthTokenResponse> {
103
103
  /**
104
- * Unique session ID generated by Lixa upon authentication.
104
+ * Unique canonical session ID generated by Lixa upon authentication.
105
105
  */
106
- id?: string;
106
+ sessionId?: string | undefined;
107
107
  /**
108
108
  * Linked identity provider accounts (AuthN) keyed by provider name.
109
109
  * Single source of truth for all authenticated user SSO identities.
110
110
  */
111
- accounts?: Record<string, LinkedAccount>;
111
+ accounts?: Record<string, LinkedAccount> | undefined;
112
112
  /**
113
113
  * Connected third-party resource provider tokens (AuthZ) keyed by provider name.
114
114
  * Single source of truth for all post-login third-party API permissions.
115
115
  */
116
- resources?: Record<string, ConnectedResource>;
116
+ resources?: Record<string, ConnectedResource> | undefined;
117
117
  /** Unique unified user ID across linked accounts */
118
- userId?: string;
118
+ userId?: string | undefined;
119
119
  /** Primary user email */
120
- email?: string;
120
+ email?: string | undefined;
121
121
  /**
122
122
  * Optional primary access token or custom session token identifier.
123
123
  */
124
- token?: string;
124
+ token?: string | undefined;
125
125
  /** Optional current active auth provider for this session turn */
126
- provider?: string;
126
+ provider?: string | undefined;
127
127
  /**
128
128
  * Optional raw session token response data from provider.
129
129
  */
130
- raw?: TRaw;
130
+ raw?: TRaw | undefined;
131
131
  }
132
132
  /**
133
133
  * Provider metadata passed to session strategy.
@@ -427,6 +427,25 @@ interface ResourceStorage {
427
427
  interface ResourceHandler {
428
428
  resourceStorage?: ResourceStorage;
429
429
  }
430
+ /**
431
+ * Interface for persistent linked account storage across user sessions.
432
+ *
433
+ * @public
434
+ */
435
+ interface AccountStorage {
436
+ saveAccount(userId: string, provider: string, account: LinkedAccount): Promise<void>;
437
+ getAccount(userId: string, provider: string): Promise<LinkedAccount | null>;
438
+ getUserAccounts(userId: string): Promise<Record<string, LinkedAccount>>;
439
+ deleteAccount(userId: string, provider: string): Promise<void>;
440
+ }
441
+ /**
442
+ * Account handler configuration.
443
+ *
444
+ * @public
445
+ */
446
+ interface AccountHandler {
447
+ accountStorage?: AccountStorage;
448
+ }
430
449
  /**
431
450
  * Session handler for OAuth authentication.
432
451
  *
@@ -658,6 +677,776 @@ interface IProvider {
658
677
  * @example ['openid', 'email', 'profile'] or ['read:user', 'user:email']
659
678
  */
660
679
  authScopes?: string[];
680
+ /**
681
+ * Default OAuth scopes requested when not explicitly specified in ProviderConfig.
682
+ */
683
+ defaultScopes?: string[];
684
+ }
685
+
686
+ /**
687
+ * Standardized user identity representation across all identity providers
688
+ * (Self-Managed Database, AWS Cognito, Auth0, Okta, Firebase, etc.).
689
+ *
690
+ * @public
691
+ */
692
+ interface UserIdentity {
693
+ /** Unique user identifier (UUID, Sub, Auth0 user_id, Okta id) */
694
+ id: string;
695
+ /** Primary unique lookup identifier (email or username) */
696
+ identifier: string;
697
+ /** Associated email address if available */
698
+ email?: string | undefined;
699
+ /** Username of the account if available */
700
+ username?: string | undefined;
701
+ /** Whether the email address has been verified by the identity provider */
702
+ emailVerified?: boolean | undefined;
703
+ /** Unix timestamp in milliseconds when user was created */
704
+ createdAt?: number | undefined;
705
+ /** Unix timestamp in milliseconds when user was last updated */
706
+ updatedAt?: number | undefined;
707
+ /** Custom user metadata or profile attributes */
708
+ metadata?: Record<string, unknown> | undefined;
709
+ /** Identity provider name (e.g. "self-managed", "cognito", "auth0", "okta") */
710
+ provider?: string | undefined;
711
+ }
712
+ /**
713
+ * Standardized token response from an identity provider.
714
+ *
715
+ * @public
716
+ */
717
+ interface IdentityTokens {
718
+ /** OAuth / IdP Access Token (JWT or opaque token) */
719
+ accessToken?: string | undefined;
720
+ /** OpenID Connect ID Token containing user claims */
721
+ idToken?: string | undefined;
722
+ /** Refresh token for renewing expired credentials */
723
+ refreshToken?: string | undefined;
724
+ /** Token type (usually "Bearer") */
725
+ tokenType?: string | undefined;
726
+ /** Token expiration time in seconds */
727
+ expiresIn?: number | undefined;
728
+ /** Raw response object returned directly by the provider */
729
+ raw?: Record<string, unknown> | undefined;
730
+ }
731
+ /**
732
+ * Result of user authentication through an identity provider.
733
+ *
734
+ * @public
735
+ */
736
+ interface IdentityAuthResult {
737
+ /** Authenticated user profile */
738
+ user: UserIdentity;
739
+ /** Optional tokens issued by the identity provider */
740
+ tokens?: IdentityTokens | undefined;
741
+ }
742
+ /**
743
+ * Parameters for requesting a password reset (forgot password).
744
+ *
745
+ * @public
746
+ */
747
+ interface ForgotPasswordParams {
748
+ /** Username or email of the account requesting a password reset */
749
+ identifier: string;
750
+ /** Optional custom client metadata or redirect URL */
751
+ metadata?: Record<string, unknown> | undefined;
752
+ }
753
+ /**
754
+ * Result of a password reset request.
755
+ *
756
+ * @public
757
+ */
758
+ interface ForgotPasswordResult {
759
+ /** Whether the password reset request was accepted */
760
+ success: boolean;
761
+ /** Delivery destination description (e.g. masked email: a***@example.com or phone) */
762
+ deliveryMedium?: string | undefined;
763
+ /** Optional message or status code from provider */
764
+ message?: string | undefined;
765
+ }
766
+ /**
767
+ * Parameters for confirming a password reset with a confirmation code or token.
768
+ *
769
+ * @public
770
+ */
771
+ interface ConfirmPasswordResetParams {
772
+ /** Username or email of the account */
773
+ identifier: string;
774
+ /** Verification code (e.g. 6-digit OTP from email/SMS) or reset token */
775
+ confirmationCode: string;
776
+ /** New plaintext password */
777
+ newPassword: string;
778
+ }
779
+ /**
780
+ * Parameters for confirming user registration with a verification code.
781
+ *
782
+ * @public
783
+ */
784
+ interface ConfirmSignUpParams {
785
+ /** Username or email of the account to confirm */
786
+ identifier: string;
787
+ /** Verification code (e.g. 6-digit OTP from email/SMS) */
788
+ confirmationCode: string;
789
+ }
790
+ /**
791
+ * Parameters for resending a sign up confirmation code.
792
+ *
793
+ * @public
794
+ */
795
+ interface ResendConfirmationCodeParams {
796
+ /** Username or email of the account */
797
+ identifier: string;
798
+ }
799
+ /**
800
+ * Result of resending a sign up confirmation code.
801
+ *
802
+ * @public
803
+ */
804
+ interface ResendConfirmationCodeResult {
805
+ /** True if code was dispatched */
806
+ success: boolean;
807
+ /** Delivery medium (e.g. 'EMAIL' or 'SMS') */
808
+ deliveryMedium?: string | undefined;
809
+ /** Obscured destination */
810
+ destination?: string | undefined;
811
+ }
812
+ /**
813
+ * Unified interface for Identity Providers in Lixa.
814
+ *
815
+ * @remarks
816
+ * Implement this interface to create custom identity providers (e.g. Supabase Auth,
817
+ * Firebase Auth, Keycloak, or proprietary enterprise directories).
818
+ *
819
+ * Built-in extensions for AWS Cognito, Auth0, and Okta are available in `@vunexa/lixa-extensions`.
820
+ *
821
+ * @public
822
+ */
823
+ interface IIdentityProvider {
824
+ /**
825
+ * Unique name of the identity provider.
826
+ * Examples: 'self-managed', 'cognito', 'auth0', 'okta'
827
+ */
828
+ readonly name: string;
829
+ /**
830
+ * Registers a new user with the identity provider.
831
+ *
832
+ * @param params - User registration details (identifier, password, email, username, metadata)
833
+ * @returns Created user identity
834
+ */
835
+ signUp(params: SignUpParams): Promise<UserIdentity>;
836
+ /**
837
+ * Authenticates a user with credentials.
838
+ *
839
+ * @param params - Sign in credentials (identifier, password)
840
+ * @returns Authenticated user identity and optional provider tokens
841
+ */
842
+ signIn(params: SignInParams): Promise<IdentityAuthResult>;
843
+ /**
844
+ * Verifies credentials without necessarily creating a full session.
845
+ *
846
+ * @param params - Verification parameters
847
+ * @returns User identity if credentials are valid, null otherwise
848
+ */
849
+ verifyCredentials?(params: VerifyCredentialsParams): Promise<UserIdentity | null>;
850
+ /**
851
+ * Changes a user's password.
852
+ *
853
+ * @param params - Old password, new password, and user identifier
854
+ * @returns True if password was successfully updated
855
+ */
856
+ changePassword?(params: ChangePasswordParams): Promise<boolean>;
857
+ /**
858
+ * Requests a password reset (forgot password flow).
859
+ *
860
+ * @param params - Forgot password parameters
861
+ */
862
+ forgotPassword?(params: ForgotPasswordParams): Promise<ForgotPasswordResult>;
863
+ /**
864
+ * Confirms password reset with verification code and new password.
865
+ *
866
+ * @param params - Confirm password reset parameters
867
+ */
868
+ confirmPasswordReset?(params: ConfirmPasswordResetParams): Promise<boolean>;
869
+ /**
870
+ * Confirms user registration using a verification code.
871
+ *
872
+ * @param params - Confirm sign up parameters
873
+ */
874
+ confirmSignUp?(params: ConfirmSignUpParams): Promise<boolean>;
875
+ /**
876
+ * Resends the sign up confirmation code.
877
+ *
878
+ * @param params - Resend confirmation code parameters
879
+ */
880
+ resendConfirmationCode?(params: ResendConfirmationCodeParams): Promise<ResendConfirmationCodeResult>;
881
+ /**
882
+ * Retrieves a user by their unique ID.
883
+ *
884
+ * @param id - Unique user ID
885
+ */
886
+ getUserById?(id: string): Promise<UserIdentity | null>;
887
+ /**
888
+ * Retrieves a user by their identifier (email or username).
889
+ *
890
+ * @param identifier - Username or email string
891
+ */
892
+ getUserByIdentifier?(identifier: string): Promise<UserIdentity | null>;
893
+ /**
894
+ * Deletes a user account.
895
+ *
896
+ * @param id - Unique user ID
897
+ */
898
+ deleteUser?(id: string): Promise<void>;
899
+ }
900
+ /**
901
+ * Configuration options for Identity Providers in LixaConfig.
902
+ *
903
+ * @public
904
+ */
905
+ type IdentityConfig = IIdentityProvider | ({
906
+ provider?: "self-managed";
907
+ } & CredentialsConfig);
908
+
909
+ /**
910
+ * User credentials entity representing stored account login information.
911
+ *
912
+ * @public
913
+ */
914
+ interface UserCredentials {
915
+ /** Unique user identifier (UUID or Nanoid) */
916
+ id: string;
917
+ /** Primary unique lookup identifier (normalized lowercase username or email) */
918
+ identifier: string;
919
+ /** Username of the account */
920
+ username?: string | undefined;
921
+ /** Associated email address */
922
+ email?: string | undefined;
923
+ /** Securely hashed password string (e.g. Scrypt, Argon2, PBKDF2, Bcrypt) */
924
+ passwordHash: string;
925
+ /** Unix timestamp in milliseconds when user credentials were created */
926
+ createdAt: number;
927
+ /** Unix timestamp in milliseconds when user credentials were last updated */
928
+ updatedAt: number;
929
+ /** Optional custom user metadata or profile attributes */
930
+ metadata?: Record<string, unknown> | undefined;
931
+ }
932
+ /**
933
+ * Storage interface for managing user credentials.
934
+ *
935
+ * @remarks
936
+ * Implement this interface to persist credentials in custom databases
937
+ * (e.g. PostgreSQL, MySQL, SQLite, MongoDB, DynamoDB) or use provided adapters
938
+ * (PrismaCredentialsStorage, DrizzleCredentialsStorage).
939
+ *
940
+ * @public
941
+ */
942
+ interface CredentialsStorage {
943
+ /**
944
+ * Persists a new user credential record.
945
+ *
946
+ * @param user - User credentials entity to save
947
+ */
948
+ saveUser(user: UserCredentials): Promise<void>;
949
+ /**
950
+ * Retrieves user credentials by normalized identifier (username or email).
951
+ *
952
+ * @param identifier - Normalized identifier string
953
+ * @returns UserCredentials record or null if not found
954
+ */
955
+ findUserByIdentifier(identifier: string): Promise<UserCredentials | null>;
956
+ /**
957
+ * Retrieves user credentials by unique user ID.
958
+ *
959
+ * @param id - Unique user ID
960
+ * @returns UserCredentials record or null if not found
961
+ */
962
+ findUserById(id: string): Promise<UserCredentials | null>;
963
+ /**
964
+ * Updates the password hash for a user by user ID.
965
+ *
966
+ * @param id - Unique user ID
967
+ * @param newPasswordHash - Newly computed password hash
968
+ */
969
+ updatePassword(id: string, newPasswordHash: string): Promise<void>;
970
+ /**
971
+ * Optional helper to delete a user by user ID.
972
+ *
973
+ * @param id - Unique user ID
974
+ */
975
+ deleteUser?(id: string): Promise<void>;
976
+ /**
977
+ * Optional helper to find user directly by username.
978
+ *
979
+ * @param username - Username string
980
+ */
981
+ findUserByUsername?(username: string): Promise<UserCredentials | null>;
982
+ }
983
+ /**
984
+ * Interface for password hashing and verification algorithms.
985
+ *
986
+ * @remarks
987
+ * Lixa defaults to ScryptPasswordHasher (Node.js crypto.scrypt, 0 dependencies).
988
+ * Implement this interface to use custom algorithms (e.g. bcrypt, argon2, pbkdf2).
989
+ *
990
+ * @public
991
+ */
992
+ interface IPasswordHasher {
993
+ /**
994
+ * Computes a secure cryptographic hash for a plaintext password.
995
+ *
996
+ * @param password - Plaintext password
997
+ * @returns Formatted hash string containing salt and algorithm parameters
998
+ */
999
+ hash(password: string): Promise<string>;
1000
+ /**
1001
+ * Verifies a plaintext password against a stored hash string.
1002
+ * Must use constant-time comparison to prevent timing attacks.
1003
+ *
1004
+ * @param password - Plaintext password to verify
1005
+ * @param hash - Stored hash string
1006
+ * @returns True if password matches hash, false otherwise
1007
+ */
1008
+ verify(password: string, hash: string): Promise<boolean>;
1009
+ }
1010
+ /**
1011
+ * Configuration options for password validation rules.
1012
+ *
1013
+ * @public
1014
+ */
1015
+ interface PasswordPolicyConfig {
1016
+ /**
1017
+ * Minimum password length in characters.
1018
+ *
1019
+ * @default 8
1020
+ */
1021
+ minLength?: number | undefined;
1022
+ /**
1023
+ * Maximum password length in characters to prevent hashing DoS attacks.
1024
+ *
1025
+ * @default 128
1026
+ */
1027
+ maxLength?: number | undefined;
1028
+ /**
1029
+ * Require at least one uppercase letter [A-Z].
1030
+ *
1031
+ * @default false
1032
+ */
1033
+ requireUppercase?: boolean | undefined;
1034
+ /**
1035
+ * Require at least one lowercase letter [a-z].
1036
+ *
1037
+ * @default false
1038
+ */
1039
+ requireLowercase?: boolean | undefined;
1040
+ /**
1041
+ * Require at least one numeric digit [0-9].
1042
+ *
1043
+ * @default false
1044
+ */
1045
+ requireNumbers?: boolean | undefined;
1046
+ /**
1047
+ * Require at least one special symbol character.
1048
+ *
1049
+ * @default false
1050
+ */
1051
+ requireSpecialChars?: boolean | undefined;
1052
+ /**
1053
+ * Optional custom validator function for enterprise or custom rules.
1054
+ * Return `true` if valid, or `false` / custom error message string if invalid.
1055
+ */
1056
+ customValidator?: ((password: string) => boolean | string | Promise<boolean | string>) | undefined;
1057
+ }
1058
+ /**
1059
+ * Result of password policy validation.
1060
+ *
1061
+ * @public
1062
+ */
1063
+ interface PasswordPolicyResult {
1064
+ /** Whether the password satisfied all configured rules */
1065
+ valid: boolean;
1066
+ /** List of human-readable error descriptions if validation failed */
1067
+ errors: string[];
1068
+ }
1069
+ /**
1070
+ * Configuration options for Credentials authentication in Lixa.
1071
+ *
1072
+ * @public
1073
+ */
1074
+ interface CredentialsConfig {
1075
+ /**
1076
+ * Explicitly enable or disable credentials authentication.
1077
+ *
1078
+ * @default true
1079
+ */
1080
+ enabled?: boolean | undefined;
1081
+ /**
1082
+ * Custom storage implementation for persisting user credentials.
1083
+ * Defaults to LocalCredentialsStorage (in-memory, suitable for dev & testing).
1084
+ */
1085
+ storage?: CredentialsStorage | undefined;
1086
+ /**
1087
+ * Custom password hashing strategy.
1088
+ * Defaults to ScryptPasswordHasher (Node.js crypto.scrypt).
1089
+ */
1090
+ hasher?: IPasswordHasher | undefined;
1091
+ /**
1092
+ * Password strength policy configuration.
1093
+ */
1094
+ policy?: PasswordPolicyConfig | undefined;
1095
+ /**
1096
+ * Supported identifier types for registration and sign-in:
1097
+ * - 'email': Identifier must be a valid email format
1098
+ * - 'username': Identifier can be any username string
1099
+ * - 'both': Automatically detect email or username
1100
+ *
1101
+ * @default 'both'
1102
+ */
1103
+ identifierType?: ("email" | "username" | "both") | undefined;
1104
+ /**
1105
+ * Whether a username is strictly required during registration (signUp).
1106
+ *
1107
+ * @default false
1108
+ */
1109
+ requireUsername?: boolean | undefined;
1110
+ /**
1111
+ * Whether a valid email address is strictly required during registration (signUp).
1112
+ *
1113
+ * @default false
1114
+ */
1115
+ requireEmail?: boolean | undefined;
1116
+ /**
1117
+ * Whether to perform dummy hash verification on unknown users to mitigate timing attacks.
1118
+ *
1119
+ * @default true
1120
+ */
1121
+ timingAttackProtection?: boolean | undefined;
1122
+ /**
1123
+ * Whether to automatically generate and save a session upon successful registration (signUp).
1124
+ *
1125
+ * @default true
1126
+ */
1127
+ autoCreateSessionOnSignUp?: boolean | undefined;
1128
+ /**
1129
+ * Session expiration time in seconds for credentials-generated sessions.
1130
+ *
1131
+ * @default 86400 (24 hours)
1132
+ */
1133
+ sessionTtlSeconds?: number | undefined;
1134
+ }
1135
+ /**
1136
+ * Parameters for user registration (signUp).
1137
+ *
1138
+ * @public
1139
+ */
1140
+ interface SignUpParams {
1141
+ /** Username for the user (can be used directly instead of identifier) */
1142
+ username?: string | undefined;
1143
+ /** Primary identifier (username or email) */
1144
+ identifier?: string | undefined;
1145
+ /** Plaintext password */
1146
+ password: string;
1147
+ /** Optional explicit email address */
1148
+ email?: string | undefined;
1149
+ /** Optional custom user metadata */
1150
+ metadata?: Record<string, unknown> | undefined;
1151
+ }
1152
+ /**
1153
+ * Result of user registration (signUp).
1154
+ *
1155
+ * @public
1156
+ */
1157
+ interface SignUpResult<TSession = Session, TUser = UserIdentity> {
1158
+ /** Created user profile / credentials (with passwordHash omitted for safety) */
1159
+ user: TUser;
1160
+ /** Created session ID if autoCreateSessionOnSignUp is enabled */
1161
+ sessionId?: string | undefined;
1162
+ /** Created session object if autoCreateSessionOnSignUp is enabled */
1163
+ session?: TSession | undefined;
1164
+ }
1165
+ /**
1166
+ * Parameters for user authentication (signIn).
1167
+ *
1168
+ * @public
1169
+ */
1170
+ interface SignInParams {
1171
+ /** Username or email of the account */
1172
+ username?: string | undefined;
1173
+ /** Primary identifier (username or email) */
1174
+ identifier?: string | undefined;
1175
+ /** Plaintext password */
1176
+ password: string;
1177
+ }
1178
+ /**
1179
+ * Result of user authentication (signIn).
1180
+ *
1181
+ * @public
1182
+ */
1183
+ interface SignInResult<TSession = Session, TUser = UserIdentity> {
1184
+ /** Authenticated user profile / credentials (with passwordHash omitted for safety) */
1185
+ user: TUser;
1186
+ /** Active session ID */
1187
+ sessionId: string;
1188
+ /** Active session object */
1189
+ session: TSession;
1190
+ }
1191
+ /**
1192
+ * Parameters for raw credential verification without session creation.
1193
+ *
1194
+ * @public
1195
+ */
1196
+ interface VerifyCredentialsParams {
1197
+ /** Username or email of the account */
1198
+ username?: string | undefined;
1199
+ /** Primary identifier (username or email) */
1200
+ identifier?: string | undefined;
1201
+ /** Plaintext password */
1202
+ password: string;
1203
+ }
1204
+ /**
1205
+ * Parameters for changing a user password.
1206
+ *
1207
+ * @public
1208
+ */
1209
+ interface ChangePasswordParams {
1210
+ /** Username (optional if identifier or userId is provided) */
1211
+ username?: string | undefined;
1212
+ /** Primary identifier (optional if username or userId is provided) */
1213
+ identifier?: string | undefined;
1214
+ /** Unique user ID (optional if identifier or username is provided) */
1215
+ userId?: string | undefined;
1216
+ /** Current plaintext password */
1217
+ oldPassword: string;
1218
+ /** New plaintext password */
1219
+ newPassword: string;
1220
+ }
1221
+
1222
+ /**
1223
+ * Options for Scrypt password hashing.
1224
+ *
1225
+ * @public
1226
+ */
1227
+ interface ScryptHasherOptions {
1228
+ /** CPU/memory cost parameter (must be power of 2). Default: 16384 (2^14) */
1229
+ cost?: number;
1230
+ /** Block size parameter. Default: 8 */
1231
+ blockSize?: number;
1232
+ /** Parallelization parameter. Default: 1 */
1233
+ parallelization?: number;
1234
+ /** Salt length in bytes. Default: 16 */
1235
+ saltLength?: number;
1236
+ /** Derived key length in bytes. Default: 64 */
1237
+ keyLength?: number;
1238
+ /** Max memory allocated in bytes. Default: 32MB */
1239
+ maxmem?: number;
1240
+ }
1241
+ /**
1242
+ * Default secure password hasher utilizing Node.js native `crypto.scrypt`.
1243
+ *
1244
+ * @remarks
1245
+ * Produces PHC-formatted strings: `$scrypt$N=16384,r=8,p=1$<saltHex>$<keyHex>`.
1246
+ * Verification uses constant-time `crypto.timingSafeEqual` to prevent timing attacks.
1247
+ *
1248
+ * @public
1249
+ */
1250
+ declare class ScryptPasswordHasher implements IPasswordHasher {
1251
+ private readonly cost;
1252
+ private readonly blockSize;
1253
+ private readonly parallelization;
1254
+ private readonly saltLength;
1255
+ private readonly keyLength;
1256
+ private readonly maxmem;
1257
+ constructor(options?: ScryptHasherOptions);
1258
+ /**
1259
+ * Hashes a plaintext password using Scrypt.
1260
+ *
1261
+ * @param password - Plaintext password
1262
+ * @returns Formatted Scrypt hash string
1263
+ */
1264
+ hash(password: string): Promise<string>;
1265
+ /**
1266
+ * Verifies a password against a stored Scrypt hash.
1267
+ *
1268
+ * @param password - Plaintext password
1269
+ * @param hash - Formatted Scrypt hash string
1270
+ * @returns True if password matches hash
1271
+ */
1272
+ verify(password: string, hash: string): Promise<boolean>;
1273
+ private deriveKey;
1274
+ }
1275
+ /**
1276
+ * Options for PBKDF2 password hashing.
1277
+ *
1278
+ * @public
1279
+ */
1280
+ interface Pbkdf2HasherOptions {
1281
+ /** Iteration count. Default: 100000 */
1282
+ iterations?: number;
1283
+ /** HMAC digest algorithm. Default: 'sha512' */
1284
+ digest?: string;
1285
+ /** Salt length in bytes. Default: 16 */
1286
+ saltLength?: number;
1287
+ /** Derived key length in bytes. Default: 64 */
1288
+ keyLength?: number;
1289
+ }
1290
+ /**
1291
+ * Alternative password hasher using Node.js native `crypto.pbkdf2`.
1292
+ *
1293
+ * @remarks
1294
+ * Produces PHC-formatted strings: `$pbkdf2$i=100000,d=sha512$<saltHex>$<keyHex>`.
1295
+ *
1296
+ * @public
1297
+ */
1298
+ declare class Pbkdf2PasswordHasher implements IPasswordHasher {
1299
+ private readonly iterations;
1300
+ private readonly digest;
1301
+ private readonly saltLength;
1302
+ private readonly keyLength;
1303
+ constructor(options?: Pbkdf2HasherOptions);
1304
+ hash(password: string): Promise<string>;
1305
+ verify(password: string, hash: string): Promise<boolean>;
1306
+ private deriveKey;
1307
+ }
1308
+
1309
+ /**
1310
+ * Validates a plaintext password against configured password policy rules.
1311
+ *
1312
+ * @param password - Plaintext password to evaluate
1313
+ * @param policy - Optional custom policy configuration
1314
+ * @returns PasswordPolicyResult containing boolean valid flag and error messages
1315
+ *
1316
+ * @public
1317
+ */
1318
+ declare function validatePasswordPolicy(password: string, policy?: PasswordPolicyConfig): Promise<PasswordPolicyResult>;
1319
+
1320
+ /**
1321
+ * In-memory credentials storage for development, testing, and isolated environments.
1322
+ *
1323
+ * @remarks
1324
+ * Uses instance-isolated Maps to prevent state leakage across tests or Lixa instances.
1325
+ *
1326
+ * @public
1327
+ */
1328
+ declare class LocalCredentialsStorage implements CredentialsStorage {
1329
+ private usersById;
1330
+ private identifierToId;
1331
+ saveUser(user: UserCredentials): Promise<void>;
1332
+ findUserByIdentifier(identifier: string): Promise<UserCredentials | null>;
1333
+ findUserById(id: string): Promise<UserCredentials | null>;
1334
+ updatePassword(id: string, newPasswordHash: string): Promise<void>;
1335
+ deleteUser(id: string): Promise<void>;
1336
+ clear(): void;
1337
+ }
1338
+
1339
+ /**
1340
+ * Coordinates user registration, authentication, password verification, policy enforcement,
1341
+ * and timing attack protection.
1342
+ *
1343
+ * @public
1344
+ */
1345
+ declare class CredentialsManager {
1346
+ private readonly storage;
1347
+ private readonly hasher;
1348
+ private readonly policy;
1349
+ private readonly identifierType;
1350
+ private readonly requireUsername;
1351
+ private readonly requireEmail;
1352
+ private readonly timingAttackProtection;
1353
+ private dummyHash;
1354
+ constructor(config?: CredentialsConfig);
1355
+ private initDummyHash;
1356
+ /**
1357
+ * Normalizes an identifier string.
1358
+ */
1359
+ private normalizeIdentifier;
1360
+ /**
1361
+ * Validates identifier format based on configured identifierType.
1362
+ */
1363
+ private validateIdentifierFormat;
1364
+ /**
1365
+ * Registers a new user with password hashing and policy enforcement.
1366
+ *
1367
+ * @param params - Registration parameters
1368
+ * @returns Created user credentials without password hash
1369
+ */
1370
+ signUp(params: SignUpParams): Promise<Omit<UserCredentials, "passwordHash">>;
1371
+ /**
1372
+ * Verifies credentials against storage with timing attack protection.
1373
+ *
1374
+ * @param params - Verification parameters
1375
+ * @returns User credentials without password hash, or null if verification fails
1376
+ */
1377
+ verifyCredentials(params: VerifyCredentialsParams): Promise<Omit<UserCredentials, "passwordHash"> | null>;
1378
+ /**
1379
+ * Changes a user's password with old password verification and new password policy enforcement.
1380
+ *
1381
+ * @param params - Change password parameters
1382
+ * @returns True if password was successfully updated
1383
+ */
1384
+ changePassword(params: ChangePasswordParams): Promise<boolean>;
1385
+ /**
1386
+ * Finds a user by ID and returns safe user data.
1387
+ */
1388
+ getUserById(id: string): Promise<Omit<UserCredentials, "passwordHash"> | null>;
1389
+ /**
1390
+ * Finds a user by identifier and returns safe user data.
1391
+ */
1392
+ getUserByIdentifier(identifier: string): Promise<Omit<UserCredentials, "passwordHash"> | null>;
1393
+ /**
1394
+ * Gets the underlying storage instance.
1395
+ */
1396
+ getStorage(): CredentialsStorage;
1397
+ /**
1398
+ * Gets the underlying hasher instance.
1399
+ */
1400
+ getHasher(): IPasswordHasher;
1401
+ }
1402
+
1403
+ /**
1404
+ * Self-Managed Identity Provider implementation for Lixa.
1405
+ *
1406
+ * @remarks
1407
+ * Backed by custom database storage (Prisma, Drizzle, PostgreSQL, SQLite, MongoDB)
1408
+ * or local in-memory storage, with cryptographic password hashing (Scrypt, Argon2, PBKDF2)
1409
+ * and configurable password policy enforcement.
1410
+ *
1411
+ * @public
1412
+ */
1413
+ declare class SelfManagedIdentityProvider implements IIdentityProvider {
1414
+ readonly name: string;
1415
+ private readonly manager;
1416
+ constructor(configOrManager?: CredentialsConfig | CredentialsManager);
1417
+ private mapUser;
1418
+ /**
1419
+ * Registers a new user.
1420
+ */
1421
+ signUp(params: SignUpParams): Promise<UserIdentity>;
1422
+ /**
1423
+ * Authenticates a user with password.
1424
+ */
1425
+ signIn(params: SignInParams): Promise<IdentityAuthResult>;
1426
+ /**
1427
+ * Verifies credentials without throwing an error if invalid.
1428
+ */
1429
+ verifyCredentials(params: VerifyCredentialsParams): Promise<UserIdentity | null>;
1430
+ /**
1431
+ * Changes a user's password.
1432
+ */
1433
+ changePassword(params: ChangePasswordParams): Promise<boolean>;
1434
+ /**
1435
+ * Retrieves a user by their unique ID.
1436
+ */
1437
+ getUserById(id: string): Promise<UserIdentity | null>;
1438
+ /**
1439
+ * Retrieves a user by their identifier (email or username).
1440
+ */
1441
+ getUserByIdentifier(identifier: string): Promise<UserIdentity | null>;
1442
+ /**
1443
+ * Deletes a user from storage if supported by the storage adapter.
1444
+ */
1445
+ deleteUser(id: string): Promise<void>;
1446
+ /**
1447
+ * Returns the underlying CredentialsManager instance.
1448
+ */
1449
+ getCredentialsManager(): CredentialsManager;
661
1450
  }
662
1451
 
663
1452
  /**
@@ -703,8 +1492,13 @@ type ProviderConfig = {
703
1492
  clientSecret: string;
704
1493
  /** The redirect URI registered with the provider */
705
1494
  redirectUri: string;
706
- /** Array of OAuth scopes to request */
707
- scopes: string[];
1495
+ /** Array of OAuth scopes to request. If omitted, uses provider default identity scopes. */
1496
+ scopes?: string[];
1497
+ /**
1498
+ * Default scopes requested when connecting this provider as a third-party resource (AuthZ).
1499
+ * Used automatically by getResourceAuthUrl() and handleResourceCallback() if not overridden at runtime.
1500
+ */
1501
+ resourceScopes?: string[];
708
1502
  /**
709
1503
  * Set to true to allow non-identity (resource) scopes during primary authentication flow.
710
1504
  * By default (false), Lixa restricts primary AuthN scopes to identity scopes to maintain
@@ -822,6 +1616,18 @@ interface AccountLinkingConfig {
822
1616
  */
823
1617
  requireVerifiedEmail?: boolean;
824
1618
  }
1619
+ /**
1620
+ * Unified storage adapter interface (e.g. Prisma or Drizzle adapter).
1621
+ * When provided to Lixa via config.storage, automatically configures session, state, and resource storage.
1622
+ * @public
1623
+ */
1624
+ interface StorageAdapter {
1625
+ sessionStorage?: any;
1626
+ resourceStorage?: any;
1627
+ stateStorage?: any;
1628
+ credentialsStorage?: any;
1629
+ accountStorage?: any;
1630
+ }
825
1631
  /**
826
1632
  * Main configuration object for Lixa.
827
1633
  * Provides type-safe provider name inference.
@@ -830,14 +1636,50 @@ interface AccountLinkingConfig {
830
1636
  */
831
1637
  interface LixaConfig<TProviders extends Record<string, ProviderConfig> = Record<string, ProviderConfig>> {
832
1638
  /**
833
- * Map of provider names to their configurations.
1639
+ * Map of federated OAuth 2.0 / OIDC provider names to their configurations (Google, GitHub, etc.)
1640
+ * that federate with and work alongside the primary identityProvider.
834
1641
  * Provider names will be available for autocomplete in getAuthUrl() and handleCallback().
835
1642
  */
836
- providers: TProviders;
1643
+ federatedOAuthProviders?: TProviders;
1644
+ /**
1645
+ * Alias for {@link LixaConfig.federatedOAuthProviders}.
1646
+ */
1647
+ providers?: TProviders;
1648
+ /**
1649
+ * Primary Identity Provider configuration (Self-Managed Database, AWS Cognito, Auth0, Okta, or custom IIdentityProvider).
1650
+ *
1651
+ * @example
1652
+ * Self-managed with Prisma:
1653
+ * ```typescript
1654
+ * identityProvider: { storage: prismaAdapter.credentialsStorage }
1655
+ * ```
1656
+ *
1657
+ * @example
1658
+ * AWS Cognito:
1659
+ * ```typescript
1660
+ * identityProvider: new CognitoIdentityProvider({ userPoolId: '...', clientId: '...', region: 'us-east-1' })
1661
+ * ```
1662
+ */
1663
+ identityProvider?: IIdentityProvider | IdentityConfig;
1664
+ /**
1665
+ * Alias for {@link LixaConfig.identityProvider}.
1666
+ */
1667
+ identity?: IIdentityProvider | IdentityConfig;
1668
+ /**
1669
+ * Credentials (username and password) authentication configuration.
1670
+ * Automatically maps to a SelfManagedIdentityProvider.
1671
+ */
1672
+ credentials?: CredentialsConfig;
1673
+ /**
1674
+ * Unified database storage adapter (e.g. createPrismaAdapter or createDrizzleAdapter).
1675
+ * Automatically configures sessionHandler, stateHandler, and resourceHandler.
1676
+ */
1677
+ storage?: StorageAdapter;
837
1678
  /**
838
1679
  * Account linking configuration for multi-SSO user linking.
1680
+ * Pass `true` or `"linkByEmail"` for automatic email-verified linking.
839
1681
  */
840
- accountLinking?: AccountLinkingConfig;
1682
+ accountLinking?: boolean | AccountLinkingMode | AccountLinkingConfig;
841
1683
  /**
842
1684
  * Optional custom state handler.
843
1685
  * Handles state generation and storage during OAuth authorization flow.
@@ -881,7 +1723,30 @@ interface LixaConfig<TProviders extends Record<string, ProviderConfig> = Record<
881
1723
  * If provided, all Lixa logs will be routed through this logger.
882
1724
  */
883
1725
  logger?: LixaLogger;
1726
+ /**
1727
+ * Session cookie name or dynamic resolution function.
1728
+ * Can accept a static string or `(lixa: Lixa, req?: unknown) => string`.
1729
+ * Automatically evaluated live against the instance when getSessionCookieName() is called.
1730
+ */
1731
+ sessionCookieName?: SessionCookieResolver;
884
1732
  }
1733
+ /**
1734
+ * Interface exposing identity information for dynamic session cookie name resolution.
1735
+ * @public
1736
+ */
1737
+ interface LixaCookieContext {
1738
+ /**
1739
+ * Retrieves the currently active identity provider.
1740
+ */
1741
+ getIdentityProvider(): IIdentityProvider | undefined;
1742
+ }
1743
+ /**
1744
+ * Dynamic resolver for session cookie name.
1745
+ * Can be a static string or a dynamic callback receiving the Lixa instance and an optional request context.
1746
+ *
1747
+ * @public
1748
+ */
1749
+ type SessionCookieResolver<TContext extends LixaCookieContext = LixaCookieContext> = string | ((lixa: TContext, req?: unknown) => string);
885
1750
  /**
886
1751
  * Log level for Lixa structured logging.
887
1752
  * @public
@@ -891,7 +1756,7 @@ type LogLevel = "INFO" | "WARN" | "ERROR" | "DEBUG";
891
1756
  * Log context for Lixa structured logging.
892
1757
  * @public
893
1758
  */
894
- type LogContext = "Init" | "Auth" | "Token" | "Session" | "State" | "AccountLinking" | "Resource";
1759
+ type LogContext = "Init" | "Auth" | "Token" | "Session" | "State" | "AccountLinking" | "Resource" | "Credentials" | "Identity";
895
1760
  /**
896
1761
  * Custom logger interface for Lixa.
897
1762
  * @public
@@ -915,7 +1780,7 @@ type SafeLixaConfig<TProviders extends Record<string, ProviderConfig>> = LixaCon
915
1780
  /**
916
1781
  * Type representing the keys of configured providers
917
1782
  */
918
- type ConfiguredProviderKey<T extends LixaConfig<Record<string, ProviderConfig>>> = keyof T['providers'];
1783
+ type ConfiguredProviderKey<TProviders extends Record<string, ProviderConfig>> = keyof TProviders & string;
919
1784
  /**
920
1785
  * A flexible, provider-agnostic OAuth 2.0 and OpenID Connect (OIDC) client library.
921
1786
  *
@@ -968,19 +1833,25 @@ type ConfiguredProviderKey<T extends LixaConfig<Record<string, ProviderConfig>>>
968
1833
  *
969
1834
  * @public
970
1835
  */
971
- declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> = LixaConfig> {
1836
+ declare class Lixa<TProviders extends Record<string, ProviderConfig> = Record<string, ProviderConfig>> {
972
1837
  private static DEFAULT_PROVIDERS;
973
1838
  private static CONFIGURED_PROVIDERS;
974
1839
  private localStateHandler;
975
1840
  private localSessionHandler;
976
1841
  private localResourceHandler;
1842
+ private localAccountHandler;
977
1843
  private userResourceStore;
1844
+ private userAccountStore;
978
1845
  private refreshMutexes;
1846
+ private identityProvider?;
1847
+ private credentialsManager?;
979
1848
  private config;
980
1849
  private stateHandler;
981
1850
  private sessionHandler;
982
1851
  private resourceHandler;
1852
+ private accountHandler;
983
1853
  private debug;
1854
+ private sessionCookieResolver?;
984
1855
  /**
985
1856
  * Creates a new Lixa instance with the provided configuration.
986
1857
  *
@@ -994,7 +1865,7 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
994
1865
  * @throws Error when provider implementation is missing required properties
995
1866
  * @throws Error when provider is not available and no inline implementation is provided
996
1867
  */
997
- constructor(config: TConfig);
1868
+ constructor(config: LixaConfig<TProviders>);
998
1869
  /**
999
1870
  * Validates that a provider configuration has all required credentials.
1000
1871
  *
@@ -1015,7 +1886,7 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1015
1886
  * Structured logging with standardized format and custom logger support.
1016
1887
  *
1017
1888
  * @param level - Log level (INFO, WARN, ERROR, DEBUG)
1018
- * @param context - Context of the log (Init, Auth, Token, Session, State, AccountLinking, Resource)
1889
+ * @param context - Context of the log (Init, Auth, Token, Session, State, AccountLinking, Resource, Credentials)
1019
1890
  * @param message - Log message
1020
1891
  * @param data - Optional data to log
1021
1892
  */
@@ -1035,7 +1906,7 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1035
1906
  * }
1036
1907
  * ```
1037
1908
  */
1038
- isProviderConfigured<T extends string>(provider: T): provider is T & ConfiguredProviderKey<TConfig>;
1909
+ isProviderConfigured<T extends string>(provider: T): provider is T & ConfiguredProviderKey<TProviders>;
1039
1910
  /**
1040
1911
  * Gets a provider implementation by name.
1041
1912
  * Resolution priority: inline custom provider \> default providers \> legacy registry
@@ -1109,7 +1980,9 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1109
1980
  */
1110
1981
  static createConfig<T extends Record<string, ProviderConfig>>(config: LixaConfig<T> & {
1111
1982
  providers: T;
1112
- }): LixaConfig<T>;
1983
+ }): LixaConfig<T> & {
1984
+ providers: T;
1985
+ };
1113
1986
  /**
1114
1987
  * Generates a cryptographically secure random state parameter for OAuth flows.
1115
1988
  *
@@ -1214,7 +2087,7 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1214
2087
  * res.redirect(authUrl);
1215
2088
  * ```
1216
2089
  */
1217
- getAuthUrl(provider: ConfiguredProviderKey<TConfig> | string, state?: string): Promise<string>;
2090
+ getAuthUrl(provider: ConfiguredProviderKey<TProviders> | string, state?: string): Promise<string>;
1218
2091
  /**
1219
2092
  * Restricts primary authentication scopes strictly to AuthN identity scopes unless allowNonAuthScopes is true.
1220
2093
  */
@@ -1238,10 +2111,11 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1238
2111
  * });
1239
2112
  * ```
1240
2113
  */
1241
- handleCallback({ provider, code, state, }: {
1242
- provider: ConfiguredProviderKey<TConfig> | string;
2114
+ handleCallback({ provider, code, state, sessionId, }: {
2115
+ provider: ConfiguredProviderKey<TProviders> | string;
1243
2116
  code: string;
1244
2117
  state?: string;
2118
+ sessionId?: string;
1245
2119
  }): Promise<string>;
1246
2120
  /**
1247
2121
  * Explicitly link a new OAuth provider account to an active session.
@@ -1251,7 +2125,7 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1251
2125
  */
1252
2126
  linkAccount(params: {
1253
2127
  sessionId: string;
1254
- provider: ConfiguredProviderKey<TConfig> | string;
2128
+ provider: ConfiguredProviderKey<TProviders> | string;
1255
2129
  code: string;
1256
2130
  state?: string;
1257
2131
  }): Promise<string>;
@@ -1276,8 +2150,8 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1276
2150
  */
1277
2151
  getResourceAuthUrl(params: {
1278
2152
  sessionId: string;
1279
- provider: ConfiguredProviderKey<TConfig> | string;
1280
- scopes: string[];
2153
+ provider: ConfiguredProviderKey<TProviders> | string;
2154
+ scopes?: string[];
1281
2155
  state?: string;
1282
2156
  prompt?: string;
1283
2157
  extraConfig?: Record<string, string>;
@@ -1288,11 +2162,32 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1288
2162
  */
1289
2163
  handleResourceCallback(params: {
1290
2164
  sessionId: string;
1291
- provider: ConfiguredProviderKey<TConfig> | string;
2165
+ provider: ConfiguredProviderKey<TProviders> | string;
1292
2166
  code: string;
1293
2167
  state?: string;
1294
2168
  scopes?: string[];
1295
2169
  }): Promise<Session>;
2170
+ /**
2171
+ * Retrieves configured default resource scopes for a provider.
2172
+ *
2173
+ * @param provider - Provider name (e.g. 'github', 'google')
2174
+ * @returns Array of configured resource scopes, or undefined if not configured
2175
+ */
2176
+ getResourceScopes(provider: ConfiguredProviderKey<TProviders> | string): string[] | undefined;
2177
+ /**
2178
+ * Returns the resolved session cookie name.
2179
+ * Dynamically reflects any changes to the active identity provider.
2180
+ *
2181
+ * @param req - Optional request object for multi-tenant request-scoped cookie resolution
2182
+ * @returns Resolved session cookie name
2183
+ */
2184
+ getSessionCookieName(req?: unknown): string;
2185
+ /**
2186
+ * Sets or updates the session cookie name or dynamic resolver on this instance.
2187
+ *
2188
+ * @param resolver - Static cookie name or dynamic resolver function
2189
+ */
2190
+ setSessionCookieName(resolver: SessionCookieResolver<Lixa<TProviders>>): void;
1296
2191
  /**
1297
2192
  * Retrieves a connected resource for a specific User ID / Email directly (independent of session IDs).
1298
2193
  * Automatically refreshes expired access tokens if a refresh token is present.
@@ -1347,6 +2242,126 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1347
2242
  */
1348
2243
  deleteSession(sessionId: string): Promise<void>;
1349
2244
  private exchangeCodeForToken;
2245
+ /**
2246
+ * Checks if an identity provider (Self-Managed Database, AWS Cognito, Auth0, Okta, etc.) is configured.
2247
+ *
2248
+ * @returns True if identity provider is configured and available
2249
+ */
2250
+ isIdentityEnabled(): boolean;
2251
+ /**
2252
+ * Checks if credentials / identity authentication is configured and enabled.
2253
+ *
2254
+ * @returns True if credentials / identity authentication is available
2255
+ */
2256
+ isCredentialsEnabled(): boolean;
2257
+ /**
2258
+ * Returns the configured IdentityProvider instance.
2259
+ */
2260
+ getIdentityProvider(): IIdentityProvider | undefined;
2261
+ /**
2262
+ * Dynamically sets or updates the active identity provider (e.g. SelfManaged, Cognito, Auth0, Okta).
2263
+ *
2264
+ * @param provider - Identity provider instance or undefined to disable
2265
+ */
2266
+ setIdentityProvider(provider?: IIdentityProvider): void;
2267
+ /**
2268
+ * Returns the underlying CredentialsManager instance if using Self-Managed identity.
2269
+ */
2270
+ getCredentialsManager(): CredentialsManager | undefined;
2271
+ /**
2272
+ * Registers a new user with the configured identity provider (Self-Managed DB, Cognito, Auth0, Okta).
2273
+ * Automatically creates an active session unless autoCreateSessionOnSignUp is explicitly set to false.
2274
+ *
2275
+ * @param params - Registration parameters (identifier, password, email, username, metadata)
2276
+ * @returns Created user identity and optional active session
2277
+ * @throws WeakPasswordError if password does not meet policy requirements
2278
+ * @throws UserAlreadyExistsError if identifier is already registered
2279
+ * @throws IdentityNotConfiguredError if identity authentication is not configured
2280
+ */
2281
+ signUp(params: SignUpParams): Promise<SignUpResult>;
2282
+ /**
2283
+ * Authenticates a user with credentials via the configured identity provider (Self-Managed DB, Cognito, Auth0, Okta).
2284
+ * Creates an active session and automatically links with existing sessions when AUTO_LINK_BY_VERIFIED_EMAIL is configured.
2285
+ *
2286
+ * @param params - Sign-in parameters (identifier, password)
2287
+ * @returns Authenticated user, session ID, and session object
2288
+ * @throws InvalidCredentialsError if authentication fails
2289
+ * @throws IdentityNotConfiguredError if identity authentication is not configured
2290
+ */
2291
+ signIn(params: SignInParams): Promise<SignInResult>;
2292
+ /**
2293
+ * Verifies username/email and password credentials without generating a session.
2294
+ *
2295
+ * @param params - Verification parameters (identifier, password)
2296
+ * @returns User credentials/identity or null if invalid
2297
+ * @throws IdentityNotConfiguredError if identity auth is not configured
2298
+ */
2299
+ verifyCredentials(params: VerifyCredentialsParams): Promise<UserIdentity | null>;
2300
+ /**
2301
+ * Updates a user's password after verifying the current password and enforcing policy on the new password.
2302
+ *
2303
+ * @param params - Change password parameters (userId/identifier, oldPassword, newPassword)
2304
+ * @returns True if password was updated successfully
2305
+ * @throws UserNotFoundError if user is not found
2306
+ * @throws InvalidCredentialsError if current password is incorrect
2307
+ * @throws WeakPasswordError if new password does not meet policy requirements
2308
+ * @throws IdentityNotConfiguredError if identity auth is not configured
2309
+ */
2310
+ changePassword(params: ChangePasswordParams): Promise<boolean>;
2311
+ /**
2312
+ * Initiates a password reset (forgot password flow) through the configured identity provider.
2313
+ *
2314
+ * @param params - Forgot password parameters (identifier, optional metadata)
2315
+ * @returns ForgotPasswordResult indicating status and delivery medium (email/SMS)
2316
+ * @throws IdentityNotConfiguredError if identity auth is not configured
2317
+ */
2318
+ forgotPassword(params: ForgotPasswordParams): Promise<ForgotPasswordResult>;
2319
+ /**
2320
+ * Confirms a password reset using a verification code / token and sets the new password.
2321
+ *
2322
+ * @param params - Verification code, identifier, and new password
2323
+ * @returns True if password reset was successfully confirmed
2324
+ * @throws IdentityNotConfiguredError if identity auth is not configured
2325
+ */
2326
+ confirmPasswordReset(params: ConfirmPasswordResetParams): Promise<boolean>;
2327
+ /**
2328
+ * Confirms user account registration using a verification code.
2329
+ *
2330
+ * @param params - Verification parameters including identifier and confirmationCode
2331
+ * @returns True if confirmation was successful
2332
+ * @throws IdentityNotConfiguredError if identity auth is not configured
2333
+ * @throws IdentityProviderError if identity provider does not support confirmation
2334
+ */
2335
+ confirmSignUp(params: ConfirmSignUpParams): Promise<boolean>;
2336
+ /**
2337
+ * Resends the sign up confirmation code to the user.
2338
+ *
2339
+ * @param params - Resend parameters including user identifier
2340
+ * @returns Details about the code delivery (medium, destination)
2341
+ * @throws IdentityNotConfiguredError if identity auth is not configured
2342
+ * @throws IdentityProviderError if identity provider does not support resending codes
2343
+ */
2344
+ resendConfirmationCode(params: ResendConfirmationCodeParams): Promise<ResendConfirmationCodeResult>;
2345
+ /**
2346
+ * Retrieves a user by their unique ID from the configured identity provider.
2347
+ *
2348
+ * @param id - Unique user ID
2349
+ * @returns UserIdentity or null if not found
2350
+ */
2351
+ getUserById(id: string): Promise<UserIdentity | null>;
2352
+ /**
2353
+ * Retrieves a user by their identifier (username or email) from the configured identity provider.
2354
+ *
2355
+ * @param identifier - Username or email string
2356
+ * @returns UserIdentity or null if not found
2357
+ */
2358
+ getUserByIdentifier(identifier: string): Promise<UserIdentity | null>;
2359
+ /**
2360
+ * Deletes a user account from the configured identity provider.
2361
+ *
2362
+ * @param id - Unique user ID
2363
+ */
2364
+ deleteUser(id: string): Promise<void>;
1350
2365
  private findProviderByType;
1351
2366
  }
1352
2367
 
@@ -1520,6 +2535,67 @@ declare class AccountUnlinkError extends LixaError {
1520
2535
  declare class RefreshTokenError extends LixaError {
1521
2536
  constructor(message: string, details?: Record<string, unknown>);
1522
2537
  }
2538
+ /**
2539
+ * Thrown when user credentials (username/email and password) are invalid during authentication.
2540
+ *
2541
+ * @public
2542
+ */
2543
+ declare class InvalidCredentialsError extends LixaError {
2544
+ constructor(message?: string, details?: Record<string, unknown>);
2545
+ }
2546
+ /**
2547
+ * Thrown when attempting to register a user with an identifier that already exists.
2548
+ *
2549
+ * @public
2550
+ */
2551
+ declare class UserAlreadyExistsError extends LixaError {
2552
+ constructor(identifier: string, details?: Record<string, unknown>);
2553
+ }
2554
+ /**
2555
+ * Thrown when a user account cannot be found for credential verification or password change.
2556
+ *
2557
+ * @public
2558
+ */
2559
+ declare class UserNotFoundError extends LixaError {
2560
+ constructor(identifierOrId?: string, details?: Record<string, unknown>);
2561
+ }
2562
+ /**
2563
+ * Thrown when a password does not satisfy configured password policy rules.
2564
+ *
2565
+ * @public
2566
+ */
2567
+ declare class WeakPasswordError extends LixaError {
2568
+ readonly validationErrors: string[];
2569
+ constructor(validationErrors?: string[], details?: Record<string, unknown>);
2570
+ }
2571
+ /**
2572
+ * Thrown when credentials operations (signUp, signIn, etc.) are invoked on a Lixa instance
2573
+ * where credentials authentication is not enabled.
2574
+ *
2575
+ * @public
2576
+ */
2577
+ declare class CredentialsNotConfiguredError extends LixaError {
2578
+ constructor(message?: string, details?: Record<string, unknown>);
2579
+ }
2580
+ /**
2581
+ * Thrown when an identity provider operation fails with an upstream provider error.
2582
+ *
2583
+ * @public
2584
+ */
2585
+ declare class IdentityProviderError extends LixaError {
2586
+ readonly provider: string | undefined;
2587
+ readonly statusCode: number | undefined;
2588
+ constructor(message: string, provider?: string, statusCode?: number, details?: Record<string, unknown>);
2589
+ }
2590
+ /**
2591
+ * Thrown when identity operations (signUp, signIn, etc.) are invoked on a Lixa instance
2592
+ * where neither identity nor credentials authentication is enabled.
2593
+ *
2594
+ * @public
2595
+ */
2596
+ declare class IdentityNotConfiguredError extends CredentialsNotConfiguredError {
2597
+ constructor(message?: string, details?: Record<string, unknown>);
2598
+ }
1523
2599
 
1524
2600
  /**
1525
2601
  * Sensible default cookie configuration options.
@@ -1663,4 +2739,48 @@ declare function createStateCookie(state: string, options?: CookieOptions): Cook
1663
2739
  */
1664
2740
  declare function clearStateCookie(options?: CookieOptions): CookiePayload;
1665
2741
 
1666
- export { type AccountLinkingConfig, type AccountLinkingMode, AccountLinkingStrategy, AccountUnlinkError, type ConnectedResource, type CookieOptions, type CookiePayload, DEFAULT_SESSION_COOKIE_NAME, DEFAULT_SESSION_MAX_AGE_SECONDS, DEFAULT_STATE_COOKIE_NAME, DEFAULT_STATE_MAX_AGE_SECONDS, EmailNotVerifiedError, type IProvider, InvalidOAuthCallbackError, InvalidProviderConfigError, InvalidStateError, Lixa, type LixaConfig, LixaError, type LixaLogger, type LogContext, type LogLevel, type OAuthTokenResponse, type ProviderConfig, type ProviderMetadata, ProviderNotConfiguredError, RefreshTokenError, type ResourceHandler, type ResourceStorage, type SafeLixaConfig, type Session, type SessionHandler, SessionNotFoundError, type SessionStorage, type StateData, type StateHandler, type StateStorage, TokenExchangeError, type UserInfo, clearSessionCookie, clearStateCookie, createSessionCookie, createStateCookie, decodeIdToken, determineProviderFromIssuer, extractUserInfo, fetchUserInfo, isProductionEnvironment, serializeCookie };
2742
+ type index$1_ChangePasswordParams = ChangePasswordParams;
2743
+ type index$1_CredentialsConfig = CredentialsConfig;
2744
+ type index$1_CredentialsManager = CredentialsManager;
2745
+ declare const index$1_CredentialsManager: typeof CredentialsManager;
2746
+ type index$1_CredentialsStorage = CredentialsStorage;
2747
+ type index$1_IPasswordHasher = IPasswordHasher;
2748
+ type index$1_LocalCredentialsStorage = LocalCredentialsStorage;
2749
+ declare const index$1_LocalCredentialsStorage: typeof LocalCredentialsStorage;
2750
+ type index$1_PasswordPolicyConfig = PasswordPolicyConfig;
2751
+ type index$1_PasswordPolicyResult = PasswordPolicyResult;
2752
+ type index$1_Pbkdf2HasherOptions = Pbkdf2HasherOptions;
2753
+ type index$1_Pbkdf2PasswordHasher = Pbkdf2PasswordHasher;
2754
+ declare const index$1_Pbkdf2PasswordHasher: typeof Pbkdf2PasswordHasher;
2755
+ type index$1_ScryptHasherOptions = ScryptHasherOptions;
2756
+ type index$1_ScryptPasswordHasher = ScryptPasswordHasher;
2757
+ declare const index$1_ScryptPasswordHasher: typeof ScryptPasswordHasher;
2758
+ type index$1_SignInParams = SignInParams;
2759
+ type index$1_SignInResult<TSession = Session, TUser = UserIdentity> = SignInResult<TSession, TUser>;
2760
+ type index$1_SignUpParams = SignUpParams;
2761
+ type index$1_SignUpResult<TSession = Session, TUser = UserIdentity> = SignUpResult<TSession, TUser>;
2762
+ type index$1_UserCredentials = UserCredentials;
2763
+ type index$1_VerifyCredentialsParams = VerifyCredentialsParams;
2764
+ declare const index$1_validatePasswordPolicy: typeof validatePasswordPolicy;
2765
+ declare namespace index$1 {
2766
+ export { type index$1_ChangePasswordParams as ChangePasswordParams, type index$1_CredentialsConfig as CredentialsConfig, index$1_CredentialsManager as CredentialsManager, type index$1_CredentialsStorage as CredentialsStorage, type index$1_IPasswordHasher as IPasswordHasher, index$1_LocalCredentialsStorage as LocalCredentialsStorage, type index$1_PasswordPolicyConfig as PasswordPolicyConfig, type index$1_PasswordPolicyResult as PasswordPolicyResult, type index$1_Pbkdf2HasherOptions as Pbkdf2HasherOptions, index$1_Pbkdf2PasswordHasher as Pbkdf2PasswordHasher, type index$1_ScryptHasherOptions as ScryptHasherOptions, index$1_ScryptPasswordHasher as ScryptPasswordHasher, type index$1_SignInParams as SignInParams, type index$1_SignInResult as SignInResult, type index$1_SignUpParams as SignUpParams, type index$1_SignUpResult as SignUpResult, type index$1_UserCredentials as UserCredentials, type index$1_VerifyCredentialsParams as VerifyCredentialsParams, index$1_validatePasswordPolicy as validatePasswordPolicy };
2767
+ }
2768
+
2769
+ type index_ConfirmPasswordResetParams = ConfirmPasswordResetParams;
2770
+ type index_ConfirmSignUpParams = ConfirmSignUpParams;
2771
+ type index_ForgotPasswordParams = ForgotPasswordParams;
2772
+ type index_ForgotPasswordResult = ForgotPasswordResult;
2773
+ type index_IIdentityProvider = IIdentityProvider;
2774
+ type index_IdentityAuthResult = IdentityAuthResult;
2775
+ type index_IdentityConfig = IdentityConfig;
2776
+ type index_IdentityTokens = IdentityTokens;
2777
+ type index_ResendConfirmationCodeParams = ResendConfirmationCodeParams;
2778
+ type index_ResendConfirmationCodeResult = ResendConfirmationCodeResult;
2779
+ type index_SelfManagedIdentityProvider = SelfManagedIdentityProvider;
2780
+ declare const index_SelfManagedIdentityProvider: typeof SelfManagedIdentityProvider;
2781
+ type index_UserIdentity = UserIdentity;
2782
+ declare namespace index {
2783
+ export { type index_ConfirmPasswordResetParams as ConfirmPasswordResetParams, type index_ConfirmSignUpParams as ConfirmSignUpParams, type index_ForgotPasswordParams as ForgotPasswordParams, type index_ForgotPasswordResult as ForgotPasswordResult, type index_IIdentityProvider as IIdentityProvider, type index_IdentityAuthResult as IdentityAuthResult, type index_IdentityConfig as IdentityConfig, type index_IdentityTokens as IdentityTokens, type index_ResendConfirmationCodeParams as ResendConfirmationCodeParams, type index_ResendConfirmationCodeResult as ResendConfirmationCodeResult, index_SelfManagedIdentityProvider as SelfManagedIdentityProvider, type index_UserIdentity as UserIdentity };
2784
+ }
2785
+
2786
+ export { type AccountHandler, type AccountLinkingConfig, type AccountLinkingMode, AccountLinkingStrategy, type AccountStorage, AccountUnlinkError, type ChangePasswordParams, type ConfirmPasswordResetParams, type ConfirmSignUpParams, type ConnectedResource, type CookieOptions, type CookiePayload, type CredentialsConfig, CredentialsManager, CredentialsNotConfiguredError, type CredentialsStorage, DEFAULT_SESSION_COOKIE_NAME, DEFAULT_SESSION_MAX_AGE_SECONDS, DEFAULT_STATE_COOKIE_NAME, DEFAULT_STATE_MAX_AGE_SECONDS, EmailNotVerifiedError, type ForgotPasswordParams, type ForgotPasswordResult, type IIdentityProvider, type IPasswordHasher, type IProvider, type IdentityAuthResult, type IdentityConfig, IdentityNotConfiguredError, IdentityProviderError, type IdentityTokens, InvalidCredentialsError, InvalidOAuthCallbackError, InvalidProviderConfigError, InvalidStateError, type LinkedAccount, Lixa, type LixaConfig, type LixaCookieContext, LixaError, type LixaLogger, LocalCredentialsStorage, type LogContext, type LogLevel, type OAuthTokenResponse, type PasswordPolicyConfig, type PasswordPolicyResult, type Pbkdf2HasherOptions, Pbkdf2PasswordHasher, type ProviderConfig, type ProviderMetadata, ProviderNotConfiguredError, RefreshTokenError, type ResendConfirmationCodeParams, type ResendConfirmationCodeResult, type ResourceHandler, type ResourceStorage, type SafeLixaConfig, type ScryptHasherOptions, ScryptPasswordHasher, SelfManagedIdentityProvider, type Session, type SessionCookieResolver, type SessionHandler, SessionNotFoundError, type SessionStorage, type SignInParams, type SignInResult, type SignUpParams, type SignUpResult, type StateData, type StateHandler, type StateStorage, TokenExchangeError, UserAlreadyExistsError, type UserCredentials, type UserIdentity, type UserInfo, UserNotFoundError, type VerifyCredentialsParams, WeakPasswordError, clearSessionCookie, clearStateCookie, createSessionCookie, createStateCookie, index$1 as credentials, decodeIdToken, determineProviderFromIssuer, extractUserInfo, fetchUserInfo, index as identity, isProductionEnvironment, serializeCookie, validatePasswordPolicy };