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

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.cts CHANGED
@@ -103,31 +103,31 @@ interface Session<TRaw = OAuthTokenResponse> {
103
103
  /**
104
104
  * Unique session ID generated by Lixa upon authentication.
105
105
  */
106
- id?: string;
106
+ id?: 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.
@@ -660,6 +660,500 @@ interface IProvider {
660
660
  authScopes?: string[];
661
661
  }
662
662
 
663
+ /**
664
+ * User credentials entity representing stored account login information.
665
+ *
666
+ * @public
667
+ */
668
+ interface UserCredentials {
669
+ /** Unique user identifier (UUID or Nanoid) */
670
+ id: string;
671
+ /** Primary unique lookup identifier (normalized lowercase username or email) */
672
+ identifier: string;
673
+ /** Username of the account */
674
+ username?: string | undefined;
675
+ /** Associated email address */
676
+ email?: string | undefined;
677
+ /** Securely hashed password string (e.g. Scrypt, Argon2, PBKDF2, Bcrypt) */
678
+ passwordHash: string;
679
+ /** Unix timestamp in milliseconds when user credentials were created */
680
+ createdAt: number;
681
+ /** Unix timestamp in milliseconds when user credentials were last updated */
682
+ updatedAt: number;
683
+ /** Optional custom user metadata or profile attributes */
684
+ metadata?: Record<string, unknown> | undefined;
685
+ }
686
+ /**
687
+ * Storage interface for managing user credentials.
688
+ *
689
+ * @remarks
690
+ * Implement this interface to persist credentials in custom databases
691
+ * (e.g. PostgreSQL, MySQL, SQLite, MongoDB, DynamoDB) or use provided adapters
692
+ * (PrismaCredentialsStorage, DrizzleCredentialsStorage).
693
+ *
694
+ * @public
695
+ */
696
+ interface CredentialsStorage {
697
+ /**
698
+ * Persists a new user credential record.
699
+ *
700
+ * @param user - User credentials entity to save
701
+ */
702
+ saveUser(user: UserCredentials): Promise<void>;
703
+ /**
704
+ * Retrieves user credentials by normalized identifier (username or email).
705
+ *
706
+ * @param identifier - Normalized identifier string
707
+ * @returns UserCredentials record or null if not found
708
+ */
709
+ findUserByIdentifier(identifier: string): Promise<UserCredentials | null>;
710
+ /**
711
+ * Retrieves user credentials by unique user ID.
712
+ *
713
+ * @param id - Unique user ID
714
+ * @returns UserCredentials record or null if not found
715
+ */
716
+ findUserById(id: string): Promise<UserCredentials | null>;
717
+ /**
718
+ * Updates the password hash for a user by user ID.
719
+ *
720
+ * @param id - Unique user ID
721
+ * @param newPasswordHash - Newly computed password hash
722
+ */
723
+ updatePassword(id: string, newPasswordHash: string): Promise<void>;
724
+ /**
725
+ * Optional helper to delete a user by user ID.
726
+ *
727
+ * @param id - Unique user ID
728
+ */
729
+ deleteUser?(id: string): Promise<void>;
730
+ /**
731
+ * Optional helper to find user directly by username.
732
+ *
733
+ * @param username - Username string
734
+ */
735
+ findUserByUsername?(username: string): Promise<UserCredentials | null>;
736
+ }
737
+ /**
738
+ * Interface for password hashing and verification algorithms.
739
+ *
740
+ * @remarks
741
+ * Lixa defaults to ScryptPasswordHasher (Node.js crypto.scrypt, 0 dependencies).
742
+ * Implement this interface to use custom algorithms (e.g. bcrypt, argon2, pbkdf2).
743
+ *
744
+ * @public
745
+ */
746
+ interface IPasswordHasher {
747
+ /**
748
+ * Computes a secure cryptographic hash for a plaintext password.
749
+ *
750
+ * @param password - Plaintext password
751
+ * @returns Formatted hash string containing salt and algorithm parameters
752
+ */
753
+ hash(password: string): Promise<string>;
754
+ /**
755
+ * Verifies a plaintext password against a stored hash string.
756
+ * Must use constant-time comparison to prevent timing attacks.
757
+ *
758
+ * @param password - Plaintext password to verify
759
+ * @param hash - Stored hash string
760
+ * @returns True if password matches hash, false otherwise
761
+ */
762
+ verify(password: string, hash: string): Promise<boolean>;
763
+ }
764
+ /**
765
+ * Configuration options for password validation rules.
766
+ *
767
+ * @public
768
+ */
769
+ interface PasswordPolicyConfig {
770
+ /**
771
+ * Minimum password length in characters.
772
+ *
773
+ * @default 8
774
+ */
775
+ minLength?: number | undefined;
776
+ /**
777
+ * Maximum password length in characters to prevent hashing DoS attacks.
778
+ *
779
+ * @default 128
780
+ */
781
+ maxLength?: number | undefined;
782
+ /**
783
+ * Require at least one uppercase letter [A-Z].
784
+ *
785
+ * @default false
786
+ */
787
+ requireUppercase?: boolean | undefined;
788
+ /**
789
+ * Require at least one lowercase letter [a-z].
790
+ *
791
+ * @default false
792
+ */
793
+ requireLowercase?: boolean | undefined;
794
+ /**
795
+ * Require at least one numeric digit [0-9].
796
+ *
797
+ * @default false
798
+ */
799
+ requireNumbers?: boolean | undefined;
800
+ /**
801
+ * Require at least one special symbol character.
802
+ *
803
+ * @default false
804
+ */
805
+ requireSpecialChars?: boolean | undefined;
806
+ /**
807
+ * Optional custom validator function for enterprise or custom rules.
808
+ * Return `true` if valid, or `false` / custom error message string if invalid.
809
+ */
810
+ customValidator?: ((password: string) => boolean | string | Promise<boolean | string>) | undefined;
811
+ }
812
+ /**
813
+ * Result of password policy validation.
814
+ *
815
+ * @public
816
+ */
817
+ interface PasswordPolicyResult {
818
+ /** Whether the password satisfied all configured rules */
819
+ valid: boolean;
820
+ /** List of human-readable error descriptions if validation failed */
821
+ errors: string[];
822
+ }
823
+ /**
824
+ * Configuration options for Credentials authentication in Lixa.
825
+ *
826
+ * @public
827
+ */
828
+ interface CredentialsConfig {
829
+ /**
830
+ * Explicitly enable or disable credentials authentication.
831
+ *
832
+ * @default true
833
+ */
834
+ enabled?: boolean | undefined;
835
+ /**
836
+ * Custom storage implementation for persisting user credentials.
837
+ * Defaults to LocalCredentialsStorage (in-memory, suitable for dev & testing).
838
+ */
839
+ storage?: CredentialsStorage | undefined;
840
+ /**
841
+ * Custom password hashing strategy.
842
+ * Defaults to ScryptPasswordHasher (Node.js crypto.scrypt).
843
+ */
844
+ hasher?: IPasswordHasher | undefined;
845
+ /**
846
+ * Password strength policy configuration.
847
+ */
848
+ policy?: PasswordPolicyConfig | undefined;
849
+ /**
850
+ * Supported identifier types for registration and sign-in:
851
+ * - 'email': Identifier must be a valid email format
852
+ * - 'username': Identifier can be any username string
853
+ * - 'both': Automatically detect email or username
854
+ *
855
+ * @default 'both'
856
+ */
857
+ identifierType?: ("email" | "username" | "both") | undefined;
858
+ /**
859
+ * Whether a username is strictly required during registration (signUp).
860
+ *
861
+ * @default false
862
+ */
863
+ requireUsername?: boolean | undefined;
864
+ /**
865
+ * Whether a valid email address is strictly required during registration (signUp).
866
+ *
867
+ * @default false
868
+ */
869
+ requireEmail?: boolean | undefined;
870
+ /**
871
+ * Whether to perform dummy hash verification on unknown users to mitigate timing attacks.
872
+ *
873
+ * @default true
874
+ */
875
+ timingAttackProtection?: boolean | undefined;
876
+ /**
877
+ * Whether to automatically generate and save a session upon successful registration (signUp).
878
+ *
879
+ * @default true
880
+ */
881
+ autoCreateSessionOnSignUp?: boolean | undefined;
882
+ /**
883
+ * Session expiration time in seconds for credentials-generated sessions.
884
+ *
885
+ * @default 86400 (24 hours)
886
+ */
887
+ sessionTtlSeconds?: number | undefined;
888
+ }
889
+ /**
890
+ * Parameters for user registration (signUp).
891
+ *
892
+ * @public
893
+ */
894
+ interface SignUpParams {
895
+ /** Username for the user (can be used directly instead of identifier) */
896
+ username?: string | undefined;
897
+ /** Primary identifier (username or email) */
898
+ identifier?: string | undefined;
899
+ /** Plaintext password */
900
+ password: string;
901
+ /** Optional explicit email address */
902
+ email?: string | undefined;
903
+ /** Optional custom user metadata */
904
+ metadata?: Record<string, unknown> | undefined;
905
+ }
906
+ /**
907
+ * Result of user registration (signUp).
908
+ *
909
+ * @public
910
+ */
911
+ interface SignUpResult<TSession = Session> {
912
+ /** Created user credentials (with passwordHash omitted for safety) */
913
+ user: Omit<UserCredentials, "passwordHash">;
914
+ /** Created session ID if autoCreateSessionOnSignUp is enabled */
915
+ sessionId?: string | undefined;
916
+ /** Created session object if autoCreateSessionOnSignUp is enabled */
917
+ session?: TSession | undefined;
918
+ }
919
+ /**
920
+ * Parameters for user authentication (signIn).
921
+ *
922
+ * @public
923
+ */
924
+ interface SignInParams {
925
+ /** Username or email of the account */
926
+ username?: string | undefined;
927
+ /** Primary identifier (username or email) */
928
+ identifier?: string | undefined;
929
+ /** Plaintext password */
930
+ password: string;
931
+ }
932
+ /**
933
+ * Result of user authentication (signIn).
934
+ *
935
+ * @public
936
+ */
937
+ interface SignInResult<TSession = Session> {
938
+ /** Authenticated user credentials (with passwordHash omitted for safety) */
939
+ user: Omit<UserCredentials, "passwordHash">;
940
+ /** Active session ID */
941
+ sessionId: string;
942
+ /** Active session object */
943
+ session: TSession;
944
+ }
945
+ /**
946
+ * Parameters for raw credential verification without session creation.
947
+ *
948
+ * @public
949
+ */
950
+ interface VerifyCredentialsParams {
951
+ /** Username or email of the account */
952
+ username?: string | undefined;
953
+ /** Primary identifier (username or email) */
954
+ identifier?: string | undefined;
955
+ /** Plaintext password */
956
+ password: string;
957
+ }
958
+ /**
959
+ * Parameters for changing a user password.
960
+ *
961
+ * @public
962
+ */
963
+ interface ChangePasswordParams {
964
+ /** Username (optional if identifier or userId is provided) */
965
+ username?: string | undefined;
966
+ /** Primary identifier (optional if username or userId is provided) */
967
+ identifier?: string | undefined;
968
+ /** Unique user ID (optional if identifier or username is provided) */
969
+ userId?: string | undefined;
970
+ /** Current plaintext password */
971
+ oldPassword: string;
972
+ /** New plaintext password */
973
+ newPassword: string;
974
+ }
975
+
976
+ /**
977
+ * Options for Scrypt password hashing.
978
+ *
979
+ * @public
980
+ */
981
+ interface ScryptHasherOptions {
982
+ /** CPU/memory cost parameter (must be power of 2). Default: 16384 (2^14) */
983
+ cost?: number;
984
+ /** Block size parameter. Default: 8 */
985
+ blockSize?: number;
986
+ /** Parallelization parameter. Default: 1 */
987
+ parallelization?: number;
988
+ /** Salt length in bytes. Default: 16 */
989
+ saltLength?: number;
990
+ /** Derived key length in bytes. Default: 64 */
991
+ keyLength?: number;
992
+ /** Max memory allocated in bytes. Default: 32MB */
993
+ maxmem?: number;
994
+ }
995
+ /**
996
+ * Default secure password hasher utilizing Node.js native `crypto.scrypt`.
997
+ *
998
+ * @remarks
999
+ * Produces PHC-formatted strings: `$scrypt$N=16384,r=8,p=1$<saltHex>$<keyHex>`.
1000
+ * Verification uses constant-time `crypto.timingSafeEqual` to prevent timing attacks.
1001
+ *
1002
+ * @public
1003
+ */
1004
+ declare class ScryptPasswordHasher implements IPasswordHasher {
1005
+ private readonly cost;
1006
+ private readonly blockSize;
1007
+ private readonly parallelization;
1008
+ private readonly saltLength;
1009
+ private readonly keyLength;
1010
+ private readonly maxmem;
1011
+ constructor(options?: ScryptHasherOptions);
1012
+ /**
1013
+ * Hashes a plaintext password using Scrypt.
1014
+ *
1015
+ * @param password - Plaintext password
1016
+ * @returns Formatted Scrypt hash string
1017
+ */
1018
+ hash(password: string): Promise<string>;
1019
+ /**
1020
+ * Verifies a password against a stored Scrypt hash.
1021
+ *
1022
+ * @param password - Plaintext password
1023
+ * @param hash - Formatted Scrypt hash string
1024
+ * @returns True if password matches hash
1025
+ */
1026
+ verify(password: string, hash: string): Promise<boolean>;
1027
+ private deriveKey;
1028
+ }
1029
+ /**
1030
+ * Options for PBKDF2 password hashing.
1031
+ *
1032
+ * @public
1033
+ */
1034
+ interface Pbkdf2HasherOptions {
1035
+ /** Iteration count. Default: 100000 */
1036
+ iterations?: number;
1037
+ /** HMAC digest algorithm. Default: 'sha512' */
1038
+ digest?: string;
1039
+ /** Salt length in bytes. Default: 16 */
1040
+ saltLength?: number;
1041
+ /** Derived key length in bytes. Default: 64 */
1042
+ keyLength?: number;
1043
+ }
1044
+ /**
1045
+ * Alternative password hasher using Node.js native `crypto.pbkdf2`.
1046
+ *
1047
+ * @remarks
1048
+ * Produces PHC-formatted strings: `$pbkdf2$i=100000,d=sha512$<saltHex>$<keyHex>`.
1049
+ *
1050
+ * @public
1051
+ */
1052
+ declare class Pbkdf2PasswordHasher implements IPasswordHasher {
1053
+ private readonly iterations;
1054
+ private readonly digest;
1055
+ private readonly saltLength;
1056
+ private readonly keyLength;
1057
+ constructor(options?: Pbkdf2HasherOptions);
1058
+ hash(password: string): Promise<string>;
1059
+ verify(password: string, hash: string): Promise<boolean>;
1060
+ private deriveKey;
1061
+ }
1062
+
1063
+ /**
1064
+ * Validates a plaintext password against configured password policy rules.
1065
+ *
1066
+ * @param password - Plaintext password to evaluate
1067
+ * @param policy - Optional custom policy configuration
1068
+ * @returns PasswordPolicyResult containing boolean valid flag and error messages
1069
+ *
1070
+ * @public
1071
+ */
1072
+ declare function validatePasswordPolicy(password: string, policy?: PasswordPolicyConfig): Promise<PasswordPolicyResult>;
1073
+
1074
+ /**
1075
+ * In-memory credentials storage for development, testing, and isolated environments.
1076
+ *
1077
+ * @remarks
1078
+ * Uses instance-isolated Maps to prevent state leakage across tests or Lixa instances.
1079
+ *
1080
+ * @public
1081
+ */
1082
+ declare class LocalCredentialsStorage implements CredentialsStorage {
1083
+ private usersById;
1084
+ private identifierToId;
1085
+ saveUser(user: UserCredentials): Promise<void>;
1086
+ findUserByIdentifier(identifier: string): Promise<UserCredentials | null>;
1087
+ findUserById(id: string): Promise<UserCredentials | null>;
1088
+ updatePassword(id: string, newPasswordHash: string): Promise<void>;
1089
+ deleteUser(id: string): Promise<void>;
1090
+ clear(): void;
1091
+ }
1092
+
1093
+ /**
1094
+ * Coordinates user registration, authentication, password verification, policy enforcement,
1095
+ * and timing attack protection.
1096
+ *
1097
+ * @public
1098
+ */
1099
+ declare class CredentialsManager {
1100
+ private readonly storage;
1101
+ private readonly hasher;
1102
+ private readonly policy;
1103
+ private readonly identifierType;
1104
+ private readonly requireUsername;
1105
+ private readonly requireEmail;
1106
+ private readonly timingAttackProtection;
1107
+ private dummyHash;
1108
+ constructor(config?: CredentialsConfig);
1109
+ private initDummyHash;
1110
+ /**
1111
+ * Normalizes an identifier string.
1112
+ */
1113
+ private normalizeIdentifier;
1114
+ /**
1115
+ * Validates identifier format based on configured identifierType.
1116
+ */
1117
+ private validateIdentifierFormat;
1118
+ /**
1119
+ * Registers a new user with password hashing and policy enforcement.
1120
+ *
1121
+ * @param params - Registration parameters
1122
+ * @returns Created user credentials without password hash
1123
+ */
1124
+ signUp(params: SignUpParams): Promise<Omit<UserCredentials, "passwordHash">>;
1125
+ /**
1126
+ * Verifies credentials against storage with timing attack protection.
1127
+ *
1128
+ * @param params - Verification parameters
1129
+ * @returns User credentials without password hash, or null if verification fails
1130
+ */
1131
+ verifyCredentials(params: VerifyCredentialsParams): Promise<Omit<UserCredentials, "passwordHash"> | null>;
1132
+ /**
1133
+ * Changes a user's password with old password verification and new password policy enforcement.
1134
+ *
1135
+ * @param params - Change password parameters
1136
+ * @returns True if password was successfully updated
1137
+ */
1138
+ changePassword(params: ChangePasswordParams): Promise<boolean>;
1139
+ /**
1140
+ * Finds a user by ID and returns safe user data.
1141
+ */
1142
+ getUserById(id: string): Promise<Omit<UserCredentials, "passwordHash"> | null>;
1143
+ /**
1144
+ * Finds a user by identifier and returns safe user data.
1145
+ */
1146
+ getUserByIdentifier(identifier: string): Promise<Omit<UserCredentials, "passwordHash"> | null>;
1147
+ /**
1148
+ * Gets the underlying storage instance.
1149
+ */
1150
+ getStorage(): CredentialsStorage;
1151
+ /**
1152
+ * Gets the underlying hasher instance.
1153
+ */
1154
+ getHasher(): IPasswordHasher;
1155
+ }
1156
+
663
1157
  /**
664
1158
  * Configuration for an OAuth provider instance.
665
1159
  *
@@ -833,7 +1327,11 @@ interface LixaConfig<TProviders extends Record<string, ProviderConfig> = Record<
833
1327
  * Map of provider names to their configurations.
834
1328
  * Provider names will be available for autocomplete in getAuthUrl() and handleCallback().
835
1329
  */
836
- providers: TProviders;
1330
+ providers?: TProviders;
1331
+ /**
1332
+ * Credentials (username and password) authentication configuration.
1333
+ */
1334
+ credentials?: CredentialsConfig;
837
1335
  /**
838
1336
  * Account linking configuration for multi-SSO user linking.
839
1337
  */
@@ -891,7 +1389,7 @@ type LogLevel = "INFO" | "WARN" | "ERROR" | "DEBUG";
891
1389
  * Log context for Lixa structured logging.
892
1390
  * @public
893
1391
  */
894
- type LogContext = "Init" | "Auth" | "Token" | "Session" | "State" | "AccountLinking" | "Resource";
1392
+ type LogContext = "Init" | "Auth" | "Token" | "Session" | "State" | "AccountLinking" | "Resource" | "Credentials";
895
1393
  /**
896
1394
  * Custom logger interface for Lixa.
897
1395
  * @public
@@ -976,6 +1474,7 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
976
1474
  private localResourceHandler;
977
1475
  private userResourceStore;
978
1476
  private refreshMutexes;
1477
+ private credentialsManager?;
979
1478
  private config;
980
1479
  private stateHandler;
981
1480
  private sessionHandler;
@@ -1015,7 +1514,7 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1015
1514
  * Structured logging with standardized format and custom logger support.
1016
1515
  *
1017
1516
  * @param level - Log level (INFO, WARN, ERROR, DEBUG)
1018
- * @param context - Context of the log (Init, Auth, Token, Session, State, AccountLinking, Resource)
1517
+ * @param context - Context of the log (Init, Auth, Token, Session, State, AccountLinking, Resource, Credentials)
1019
1518
  * @param message - Log message
1020
1519
  * @param data - Optional data to log
1021
1520
  */
@@ -1109,7 +1608,9 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1109
1608
  */
1110
1609
  static createConfig<T extends Record<string, ProviderConfig>>(config: LixaConfig<T> & {
1111
1610
  providers: T;
1112
- }): LixaConfig<T>;
1611
+ }): LixaConfig<T> & {
1612
+ providers: T;
1613
+ };
1113
1614
  /**
1114
1615
  * Generates a cryptographically secure random state parameter for OAuth flows.
1115
1616
  *
@@ -1347,6 +1848,58 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1347
1848
  */
1348
1849
  deleteSession(sessionId: string): Promise<void>;
1349
1850
  private exchangeCodeForToken;
1851
+ /**
1852
+ * Checks if credentials (username and password) authentication is configured and enabled.
1853
+ *
1854
+ * @returns True if credentials authentication is available
1855
+ */
1856
+ isCredentialsEnabled(): boolean;
1857
+ /**
1858
+ * Returns the underlying CredentialsManager instance if configured.
1859
+ */
1860
+ getCredentialsManager(): CredentialsManager | undefined;
1861
+ /**
1862
+ * Registers a new user with username/email and password.
1863
+ * Automatically enforces password policy, hashes password with Scrypt/configured hasher,
1864
+ * stores credentials, and creates a session (unless autoCreateSessionOnSignUp is false).
1865
+ *
1866
+ * @param params - Registration parameters (identifier, password, email, username, metadata)
1867
+ * @returns Created user (without password hash) and optional active session
1868
+ * @throws WeakPasswordError if password does not meet policy requirements
1869
+ * @throws UserAlreadyExistsError if identifier is already registered
1870
+ * @throws CredentialsNotConfiguredError if credentials auth is not configured
1871
+ */
1872
+ signUp(params: SignUpParams): Promise<SignUpResult>;
1873
+ /**
1874
+ * Authenticates a user with username/email and password.
1875
+ * Performs constant-time verification with timing attack mitigation, and creates an active session.
1876
+ * If account linking is configured with AUTO_LINK_BY_VERIFIED_EMAIL, merges with existing session.
1877
+ *
1878
+ * @param params - Sign-in parameters (identifier, password)
1879
+ * @returns Authenticated user, session ID, and session object
1880
+ * @throws InvalidCredentialsError if authentication fails
1881
+ * @throws CredentialsNotConfiguredError if credentials auth is not configured
1882
+ */
1883
+ signIn(params: SignInParams): Promise<SignInResult>;
1884
+ /**
1885
+ * Verifies username/email and password credentials without generating a session.
1886
+ *
1887
+ * @param params - Verification parameters (identifier, password)
1888
+ * @returns User credentials (without password hash) or null if invalid
1889
+ * @throws CredentialsNotConfiguredError if credentials auth is not configured
1890
+ */
1891
+ verifyCredentials(params: VerifyCredentialsParams): Promise<Omit<UserCredentials, "passwordHash"> | null>;
1892
+ /**
1893
+ * Updates a user's password after verifying the current password and enforcing policy on the new password.
1894
+ *
1895
+ * @param params - Change password parameters (userId/identifier, oldPassword, newPassword)
1896
+ * @returns True if password was updated successfully
1897
+ * @throws UserNotFoundError if user is not found
1898
+ * @throws InvalidCredentialsError if current password is incorrect
1899
+ * @throws WeakPasswordError if new password does not meet policy requirements
1900
+ * @throws CredentialsNotConfiguredError if credentials auth is not configured
1901
+ */
1902
+ changePassword(params: ChangePasswordParams): Promise<boolean>;
1350
1903
  private findProviderByType;
1351
1904
  }
1352
1905
 
@@ -1520,6 +2073,48 @@ declare class AccountUnlinkError extends LixaError {
1520
2073
  declare class RefreshTokenError extends LixaError {
1521
2074
  constructor(message: string, details?: Record<string, unknown>);
1522
2075
  }
2076
+ /**
2077
+ * Thrown when user credentials (username/email and password) are invalid during authentication.
2078
+ *
2079
+ * @public
2080
+ */
2081
+ declare class InvalidCredentialsError extends LixaError {
2082
+ constructor(message?: string, details?: Record<string, unknown>);
2083
+ }
2084
+ /**
2085
+ * Thrown when attempting to register a user with an identifier that already exists.
2086
+ *
2087
+ * @public
2088
+ */
2089
+ declare class UserAlreadyExistsError extends LixaError {
2090
+ constructor(identifier: string, details?: Record<string, unknown>);
2091
+ }
2092
+ /**
2093
+ * Thrown when a user account cannot be found for credential verification or password change.
2094
+ *
2095
+ * @public
2096
+ */
2097
+ declare class UserNotFoundError extends LixaError {
2098
+ constructor(identifierOrId?: string, details?: Record<string, unknown>);
2099
+ }
2100
+ /**
2101
+ * Thrown when a password does not satisfy configured password policy rules.
2102
+ *
2103
+ * @public
2104
+ */
2105
+ declare class WeakPasswordError extends LixaError {
2106
+ readonly validationErrors: string[];
2107
+ constructor(validationErrors?: string[], details?: Record<string, unknown>);
2108
+ }
2109
+ /**
2110
+ * Thrown when credentials operations (signUp, signIn, etc.) are invoked on a Lixa instance
2111
+ * where credentials authentication is not enabled.
2112
+ *
2113
+ * @public
2114
+ */
2115
+ declare class CredentialsNotConfiguredError extends LixaError {
2116
+ constructor(message?: string, details?: Record<string, unknown>);
2117
+ }
1523
2118
 
1524
2119
  /**
1525
2120
  * Sensible default cookie configuration options.
@@ -1663,4 +2258,31 @@ declare function createStateCookie(state: string, options?: CookieOptions): Cook
1663
2258
  */
1664
2259
  declare function clearStateCookie(options?: CookieOptions): CookiePayload;
1665
2260
 
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 };
2261
+ type index_ChangePasswordParams = ChangePasswordParams;
2262
+ type index_CredentialsConfig = CredentialsConfig;
2263
+ type index_CredentialsManager = CredentialsManager;
2264
+ declare const index_CredentialsManager: typeof CredentialsManager;
2265
+ type index_CredentialsStorage = CredentialsStorage;
2266
+ type index_IPasswordHasher = IPasswordHasher;
2267
+ type index_LocalCredentialsStorage = LocalCredentialsStorage;
2268
+ declare const index_LocalCredentialsStorage: typeof LocalCredentialsStorage;
2269
+ type index_PasswordPolicyConfig = PasswordPolicyConfig;
2270
+ type index_PasswordPolicyResult = PasswordPolicyResult;
2271
+ type index_Pbkdf2HasherOptions = Pbkdf2HasherOptions;
2272
+ type index_Pbkdf2PasswordHasher = Pbkdf2PasswordHasher;
2273
+ declare const index_Pbkdf2PasswordHasher: typeof Pbkdf2PasswordHasher;
2274
+ type index_ScryptHasherOptions = ScryptHasherOptions;
2275
+ type index_ScryptPasswordHasher = ScryptPasswordHasher;
2276
+ declare const index_ScryptPasswordHasher: typeof ScryptPasswordHasher;
2277
+ type index_SignInParams = SignInParams;
2278
+ type index_SignInResult<TSession = Session> = SignInResult<TSession>;
2279
+ type index_SignUpParams = SignUpParams;
2280
+ type index_SignUpResult<TSession = Session> = SignUpResult<TSession>;
2281
+ type index_UserCredentials = UserCredentials;
2282
+ type index_VerifyCredentialsParams = VerifyCredentialsParams;
2283
+ declare const index_validatePasswordPolicy: typeof validatePasswordPolicy;
2284
+ declare namespace index {
2285
+ export { type index_ChangePasswordParams as ChangePasswordParams, type index_CredentialsConfig as CredentialsConfig, index_CredentialsManager as CredentialsManager, type index_CredentialsStorage as CredentialsStorage, type index_IPasswordHasher as IPasswordHasher, index_LocalCredentialsStorage as LocalCredentialsStorage, type index_PasswordPolicyConfig as PasswordPolicyConfig, type index_PasswordPolicyResult as PasswordPolicyResult, type index_Pbkdf2HasherOptions as Pbkdf2HasherOptions, index_Pbkdf2PasswordHasher as Pbkdf2PasswordHasher, type index_ScryptHasherOptions as ScryptHasherOptions, index_ScryptPasswordHasher as ScryptPasswordHasher, type index_SignInParams as SignInParams, type index_SignInResult as SignInResult, type index_SignUpParams as SignUpParams, type index_SignUpResult as SignUpResult, type index_UserCredentials as UserCredentials, type index_VerifyCredentialsParams as VerifyCredentialsParams, index_validatePasswordPolicy as validatePasswordPolicy };
2286
+ }
2287
+
2288
+ export { type AccountLinkingConfig, type AccountLinkingMode, AccountLinkingStrategy, AccountUnlinkError, type ChangePasswordParams, 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 IPasswordHasher, type IProvider, InvalidCredentialsError, InvalidOAuthCallbackError, InvalidProviderConfigError, InvalidStateError, Lixa, type LixaConfig, LixaError, type LixaLogger, LocalCredentialsStorage, type LogContext, type LogLevel, type OAuthTokenResponse, type PasswordPolicyConfig, type PasswordPolicyResult, type Pbkdf2HasherOptions, Pbkdf2PasswordHasher, type ProviderConfig, type ProviderMetadata, ProviderNotConfiguredError, RefreshTokenError, type ResourceHandler, type ResourceStorage, type SafeLixaConfig, type ScryptHasherOptions, ScryptPasswordHasher, type Session, type SessionHandler, SessionNotFoundError, type SessionStorage, type SignInParams, type SignInResult, type SignUpParams, type SignUpResult, type StateData, type StateHandler, type StateStorage, TokenExchangeError, UserAlreadyExistsError, type UserCredentials, type UserInfo, UserNotFoundError, type VerifyCredentialsParams, WeakPasswordError, clearSessionCookie, clearStateCookie, createSessionCookie, createStateCookie, index as credentials, decodeIdToken, determineProviderFromIssuer, extractUserInfo, fetchUserInfo, isProductionEnvironment, serializeCookie, validatePasswordPolicy };