@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
@@ -7,7 +7,7 @@
7
7
  * Key features:
8
8
  * - OAuth 2.0 authorization code flow with PKCE (RFC 6749, RFC 7636)
9
9
  * - OpenID Connect support
10
- * - Built-in providers available in \@vunexa/lixa-providers
10
+ * - Built-in providers available in \@vunexa/lixa-extensions/providers
11
11
  * - Custom provider support via IProvider interface
12
12
  * - Extensible session management via SessionDao.CreateSession
13
13
  * - Pluggable state and session storage via StateDao and SessionDao
@@ -16,6 +16,15 @@
16
16
  * @packageDocumentation
17
17
  */
18
18
 
19
+ /**
20
+ * Account handler configuration.
21
+ *
22
+ * @public
23
+ */
24
+ export declare interface AccountHandler {
25
+ accountStorage?: AccountStorage;
26
+ }
27
+
19
28
  /**
20
29
  * Account linking settings for Lixa.
21
30
  *
@@ -123,6 +132,18 @@ export declare enum AccountLinkingStrategy {
123
132
  ISOLATED = "ISOLATED"
124
133
  }
125
134
 
135
+ /**
136
+ * Interface for persistent linked account storage across user sessions.
137
+ *
138
+ * @public
139
+ */
140
+ export declare interface AccountStorage {
141
+ saveAccount(userId: string, provider: string, account: LinkedAccount): Promise<void>;
142
+ getAccount(userId: string, provider: string): Promise<LinkedAccount | null>;
143
+ getUserAccounts(userId: string): Promise<Record<string, LinkedAccount>>;
144
+ deleteAccount(userId: string, provider: string): Promise<void>;
145
+ }
146
+
126
147
  /**
127
148
  * Thrown when unlinking an account violates security constraints (e.g. unlinking the only login provider).
128
149
  *
@@ -132,6 +153,24 @@ export declare class AccountUnlinkError extends LixaError {
132
153
  constructor(message: string, details?: Record<string, unknown>);
133
154
  }
134
155
 
156
+ /**
157
+ * Parameters for changing a user password.
158
+ *
159
+ * @public
160
+ */
161
+ export declare interface ChangePasswordParams {
162
+ /** Username (optional if identifier or userId is provided) */
163
+ username?: string | undefined;
164
+ /** Primary identifier (optional if username or userId is provided) */
165
+ identifier?: string | undefined;
166
+ /** Unique user ID (optional if identifier or username is provided) */
167
+ userId?: string | undefined;
168
+ /** Current plaintext password */
169
+ oldPassword: string;
170
+ /** New plaintext password */
171
+ newPassword: string;
172
+ }
173
+
135
174
  /**
136
175
  * Generates an expired session cookie payload to clear the session on logout.
137
176
  *
@@ -161,7 +200,33 @@ export declare function clearStateCookie(options?: CookieOptions): CookiePayload
161
200
  /**
162
201
  * Type representing the keys of configured providers
163
202
  */
164
- declare type ConfiguredProviderKey<T extends LixaConfig<Record<string, ProviderConfig>>> = keyof T['providers'];
203
+ declare type ConfiguredProviderKey<TProviders extends Record<string, ProviderConfig>> = keyof TProviders & string;
204
+
205
+ /**
206
+ * Parameters for confirming a password reset with a confirmation code or token.
207
+ *
208
+ * @public
209
+ */
210
+ export declare interface ConfirmPasswordResetParams {
211
+ /** Username or email of the account */
212
+ identifier: string;
213
+ /** Verification code (e.g. 6-digit OTP from email/SMS) or reset token */
214
+ confirmationCode: string;
215
+ /** New plaintext password */
216
+ newPassword: string;
217
+ }
218
+
219
+ /**
220
+ * Parameters for confirming user registration with a verification code.
221
+ *
222
+ * @public
223
+ */
224
+ export declare interface ConfirmSignUpParams {
225
+ /** Username or email of the account to confirm */
226
+ identifier: string;
227
+ /** Verification code (e.g. 6-digit OTP from email/SMS) */
228
+ confirmationCode: string;
229
+ }
165
230
 
166
231
  /**
167
232
  * Represents a connected resource provider token (e.g. GitHub Repo access, Google Drive)
@@ -271,6 +336,223 @@ export declare function createSessionCookie(sessionId: string, options?: CookieO
271
336
  */
272
337
  export declare function createStateCookie(state: string, options?: CookieOptions): CookiePayload;
273
338
 
339
+ export declare namespace credentials {
340
+ export {
341
+ UserCredentials,
342
+ CredentialsStorage,
343
+ IPasswordHasher,
344
+ PasswordPolicyConfig,
345
+ PasswordPolicyResult,
346
+ CredentialsConfig,
347
+ SignUpParams,
348
+ SignUpResult,
349
+ SignInParams,
350
+ SignInResult,
351
+ VerifyCredentialsParams,
352
+ ChangePasswordParams,
353
+ ScryptHasherOptions,
354
+ ScryptPasswordHasher,
355
+ Pbkdf2HasherOptions,
356
+ Pbkdf2PasswordHasher,
357
+ validatePasswordPolicy,
358
+ LocalCredentialsStorage,
359
+ CredentialsManager
360
+ }
361
+ }
362
+
363
+ /**
364
+ * Configuration options for Credentials authentication in Lixa.
365
+ *
366
+ * @public
367
+ */
368
+ export declare interface CredentialsConfig {
369
+ /**
370
+ * Explicitly enable or disable credentials authentication.
371
+ *
372
+ * @default true
373
+ */
374
+ enabled?: boolean | undefined;
375
+ /**
376
+ * Custom storage implementation for persisting user credentials.
377
+ * Defaults to LocalCredentialsStorage (in-memory, suitable for dev & testing).
378
+ */
379
+ storage?: CredentialsStorage | undefined;
380
+ /**
381
+ * Custom password hashing strategy.
382
+ * Defaults to ScryptPasswordHasher (Node.js crypto.scrypt).
383
+ */
384
+ hasher?: IPasswordHasher | undefined;
385
+ /**
386
+ * Password strength policy configuration.
387
+ */
388
+ policy?: PasswordPolicyConfig | undefined;
389
+ /**
390
+ * Supported identifier types for registration and sign-in:
391
+ * - 'email': Identifier must be a valid email format
392
+ * - 'username': Identifier can be any username string
393
+ * - 'both': Automatically detect email or username
394
+ *
395
+ * @default 'both'
396
+ */
397
+ identifierType?: ("email" | "username" | "both") | undefined;
398
+ /**
399
+ * Whether a username is strictly required during registration (signUp).
400
+ *
401
+ * @default false
402
+ */
403
+ requireUsername?: boolean | undefined;
404
+ /**
405
+ * Whether a valid email address is strictly required during registration (signUp).
406
+ *
407
+ * @default false
408
+ */
409
+ requireEmail?: boolean | undefined;
410
+ /**
411
+ * Whether to perform dummy hash verification on unknown users to mitigate timing attacks.
412
+ *
413
+ * @default true
414
+ */
415
+ timingAttackProtection?: boolean | undefined;
416
+ /**
417
+ * Whether to automatically generate and save a session upon successful registration (signUp).
418
+ *
419
+ * @default true
420
+ */
421
+ autoCreateSessionOnSignUp?: boolean | undefined;
422
+ /**
423
+ * Session expiration time in seconds for credentials-generated sessions.
424
+ *
425
+ * @default 86400 (24 hours)
426
+ */
427
+ sessionTtlSeconds?: number | undefined;
428
+ }
429
+
430
+ /**
431
+ * Coordinates user registration, authentication, password verification, policy enforcement,
432
+ * and timing attack protection.
433
+ *
434
+ * @public
435
+ */
436
+ export declare class CredentialsManager {
437
+ private readonly storage;
438
+ private readonly hasher;
439
+ private readonly policy;
440
+ private readonly identifierType;
441
+ private readonly requireUsername;
442
+ private readonly requireEmail;
443
+ private readonly timingAttackProtection;
444
+ private dummyHash;
445
+ constructor(config?: CredentialsConfig);
446
+ private initDummyHash;
447
+ /**
448
+ * Normalizes an identifier string.
449
+ */
450
+ private normalizeIdentifier;
451
+ /**
452
+ * Validates identifier format based on configured identifierType.
453
+ */
454
+ private validateIdentifierFormat;
455
+ /**
456
+ * Registers a new user with password hashing and policy enforcement.
457
+ *
458
+ * @param params - Registration parameters
459
+ * @returns Created user credentials without password hash
460
+ */
461
+ signUp(params: SignUpParams): Promise<Omit<UserCredentials, "passwordHash">>;
462
+ /**
463
+ * Verifies credentials against storage with timing attack protection.
464
+ *
465
+ * @param params - Verification parameters
466
+ * @returns User credentials without password hash, or null if verification fails
467
+ */
468
+ verifyCredentials(params: VerifyCredentialsParams): Promise<Omit<UserCredentials, "passwordHash"> | null>;
469
+ /**
470
+ * Changes a user's password with old password verification and new password policy enforcement.
471
+ *
472
+ * @param params - Change password parameters
473
+ * @returns True if password was successfully updated
474
+ */
475
+ changePassword(params: ChangePasswordParams): Promise<boolean>;
476
+ /**
477
+ * Finds a user by ID and returns safe user data.
478
+ */
479
+ getUserById(id: string): Promise<Omit<UserCredentials, "passwordHash"> | null>;
480
+ /**
481
+ * Finds a user by identifier and returns safe user data.
482
+ */
483
+ getUserByIdentifier(identifier: string): Promise<Omit<UserCredentials, "passwordHash"> | null>;
484
+ /**
485
+ * Gets the underlying storage instance.
486
+ */
487
+ getStorage(): CredentialsStorage;
488
+ /**
489
+ * Gets the underlying hasher instance.
490
+ */
491
+ getHasher(): IPasswordHasher;
492
+ }
493
+
494
+ /**
495
+ * Thrown when credentials operations (signUp, signIn, etc.) are invoked on a Lixa instance
496
+ * where credentials authentication is not enabled.
497
+ *
498
+ * @public
499
+ */
500
+ export declare class CredentialsNotConfiguredError extends LixaError {
501
+ constructor(message?: string, details?: Record<string, unknown>);
502
+ }
503
+
504
+ /**
505
+ * Storage interface for managing user credentials.
506
+ *
507
+ * @remarks
508
+ * Implement this interface to persist credentials in custom databases
509
+ * (e.g. PostgreSQL, MySQL, SQLite, MongoDB, DynamoDB) or use provided adapters
510
+ * (PrismaCredentialsStorage, DrizzleCredentialsStorage).
511
+ *
512
+ * @public
513
+ */
514
+ export declare interface CredentialsStorage {
515
+ /**
516
+ * Persists a new user credential record.
517
+ *
518
+ * @param user - User credentials entity to save
519
+ */
520
+ saveUser(user: UserCredentials): Promise<void>;
521
+ /**
522
+ * Retrieves user credentials by normalized identifier (username or email).
523
+ *
524
+ * @param identifier - Normalized identifier string
525
+ * @returns UserCredentials record or null if not found
526
+ */
527
+ findUserByIdentifier(identifier: string): Promise<UserCredentials | null>;
528
+ /**
529
+ * Retrieves user credentials by unique user ID.
530
+ *
531
+ * @param id - Unique user ID
532
+ * @returns UserCredentials record or null if not found
533
+ */
534
+ findUserById(id: string): Promise<UserCredentials | null>;
535
+ /**
536
+ * Updates the password hash for a user by user ID.
537
+ *
538
+ * @param id - Unique user ID
539
+ * @param newPasswordHash - Newly computed password hash
540
+ */
541
+ updatePassword(id: string, newPasswordHash: string): Promise<void>;
542
+ /**
543
+ * Optional helper to delete a user by user ID.
544
+ *
545
+ * @param id - Unique user ID
546
+ */
547
+ deleteUser?(id: string): Promise<void>;
548
+ /**
549
+ * Optional helper to find user directly by username.
550
+ *
551
+ * @param username - Username string
552
+ */
553
+ findUserByUsername?(username: string): Promise<UserCredentials | null>;
554
+ }
555
+
274
556
  /**
275
557
  * Decode JWT ID token to extract user information
276
558
  *
@@ -372,6 +654,209 @@ export declare function extractUserInfo(tokenData: OAuthTokenResponse, providerM
372
654
  */
373
655
  export declare function fetchUserInfo(accessToken: string, userInfoEndpoint: string): Promise<UserInfo>;
374
656
 
657
+ /**
658
+ * Parameters for requesting a password reset (forgot password).
659
+ *
660
+ * @public
661
+ */
662
+ export declare interface ForgotPasswordParams {
663
+ /** Username or email of the account requesting a password reset */
664
+ identifier: string;
665
+ /** Optional custom client metadata or redirect URL */
666
+ metadata?: Record<string, unknown> | undefined;
667
+ }
668
+
669
+ /**
670
+ * Result of a password reset request.
671
+ *
672
+ * @public
673
+ */
674
+ export declare interface ForgotPasswordResult {
675
+ /** Whether the password reset request was accepted */
676
+ success: boolean;
677
+ /** Delivery destination description (e.g. masked email: a***@example.com or phone) */
678
+ deliveryMedium?: string | undefined;
679
+ /** Optional message or status code from provider */
680
+ message?: string | undefined;
681
+ }
682
+
683
+ export declare namespace identity {
684
+ export {
685
+ UserIdentity,
686
+ IdentityTokens,
687
+ IdentityAuthResult,
688
+ ForgotPasswordParams,
689
+ ForgotPasswordResult,
690
+ ConfirmPasswordResetParams,
691
+ ConfirmSignUpParams,
692
+ ResendConfirmationCodeParams,
693
+ ResendConfirmationCodeResult,
694
+ IIdentityProvider,
695
+ IdentityConfig,
696
+ SelfManagedIdentityProvider
697
+ }
698
+ }
699
+
700
+ /**
701
+ * Result of user authentication through an identity provider.
702
+ *
703
+ * @public
704
+ */
705
+ export declare interface IdentityAuthResult {
706
+ /** Authenticated user profile */
707
+ user: UserIdentity;
708
+ /** Optional tokens issued by the identity provider */
709
+ tokens?: IdentityTokens | undefined;
710
+ }
711
+
712
+ /**
713
+ * Configuration options for Identity Providers in LixaConfig.
714
+ *
715
+ * @public
716
+ */
717
+ export declare type IdentityConfig = IIdentityProvider | ({
718
+ provider?: "self-managed";
719
+ } & CredentialsConfig);
720
+
721
+ /**
722
+ * Thrown when identity operations (signUp, signIn, etc.) are invoked on a Lixa instance
723
+ * where neither identity nor credentials authentication is enabled.
724
+ *
725
+ * @public
726
+ */
727
+ export declare class IdentityNotConfiguredError extends CredentialsNotConfiguredError {
728
+ constructor(message?: string, details?: Record<string, unknown>);
729
+ }
730
+
731
+ /**
732
+ * Thrown when an identity provider operation fails with an upstream provider error.
733
+ *
734
+ * @public
735
+ */
736
+ export declare class IdentityProviderError extends LixaError {
737
+ readonly provider: string | undefined;
738
+ readonly statusCode: number | undefined;
739
+ constructor(message: string, provider?: string, statusCode?: number, details?: Record<string, unknown>);
740
+ }
741
+
742
+ /**
743
+ * Standardized token response from an identity provider.
744
+ *
745
+ * @public
746
+ */
747
+ export declare interface IdentityTokens {
748
+ /** OAuth / IdP Access Token (JWT or opaque token) */
749
+ accessToken?: string | undefined;
750
+ /** OpenID Connect ID Token containing user claims */
751
+ idToken?: string | undefined;
752
+ /** Refresh token for renewing expired credentials */
753
+ refreshToken?: string | undefined;
754
+ /** Token type (usually "Bearer") */
755
+ tokenType?: string | undefined;
756
+ /** Token expiration time in seconds */
757
+ expiresIn?: number | undefined;
758
+ /** Raw response object returned directly by the provider */
759
+ raw?: Record<string, unknown> | undefined;
760
+ }
761
+
762
+ /**
763
+ * Unified interface for Identity Providers in Lixa.
764
+ *
765
+ * @remarks
766
+ * Implement this interface to create custom identity providers (e.g. Supabase Auth,
767
+ * Firebase Auth, Keycloak, or proprietary enterprise directories).
768
+ *
769
+ * Built-in extensions for AWS Cognito, Auth0, and Okta are available in `@vunexa/lixa-extensions`.
770
+ *
771
+ * @public
772
+ */
773
+ export declare interface IIdentityProvider {
774
+ /**
775
+ * Unique name of the identity provider.
776
+ * Examples: 'self-managed', 'cognito', 'auth0', 'okta'
777
+ */
778
+ readonly name: string;
779
+ /**
780
+ * Registers a new user with the identity provider.
781
+ *
782
+ * @param params - User registration details (identifier, password, email, username, metadata)
783
+ * @returns Created user identity
784
+ */
785
+ signUp(params: SignUpParams): Promise<UserIdentity>;
786
+ /**
787
+ * Authenticates a user with credentials.
788
+ *
789
+ * @param params - Sign in credentials (identifier, password)
790
+ * @returns Authenticated user identity and optional provider tokens
791
+ */
792
+ signIn(params: SignInParams): Promise<IdentityAuthResult>;
793
+ /**
794
+ * Verifies credentials without necessarily creating a full session.
795
+ *
796
+ * @param params - Verification parameters
797
+ * @returns User identity if credentials are valid, null otherwise
798
+ */
799
+ verifyCredentials?(params: VerifyCredentialsParams): Promise<UserIdentity | null>;
800
+ /**
801
+ * Changes a user's password.
802
+ *
803
+ * @param params - Old password, new password, and user identifier
804
+ * @returns True if password was successfully updated
805
+ */
806
+ changePassword?(params: ChangePasswordParams): Promise<boolean>;
807
+ /**
808
+ * Requests a password reset (forgot password flow).
809
+ *
810
+ * @param params - Forgot password parameters
811
+ */
812
+ forgotPassword?(params: ForgotPasswordParams): Promise<ForgotPasswordResult>;
813
+ /**
814
+ * Confirms password reset with verification code and new password.
815
+ *
816
+ * @param params - Confirm password reset parameters
817
+ */
818
+ confirmPasswordReset?(params: ConfirmPasswordResetParams): Promise<boolean>;
819
+ /**
820
+ * Confirms user registration using a verification code.
821
+ *
822
+ * @param params - Confirm sign up parameters
823
+ */
824
+ confirmSignUp?(params: ConfirmSignUpParams): Promise<boolean>;
825
+ /**
826
+ * Resends the sign up confirmation code.
827
+ *
828
+ * @param params - Resend confirmation code parameters
829
+ */
830
+ resendConfirmationCode?(params: ResendConfirmationCodeParams): Promise<ResendConfirmationCodeResult>;
831
+ /**
832
+ * Retrieves a user by their unique ID.
833
+ *
834
+ * @param id - Unique user ID
835
+ */
836
+ getUserById?(id: string): Promise<UserIdentity | null>;
837
+ /**
838
+ * Retrieves a user by their identifier (email or username).
839
+ *
840
+ * @param identifier - Username or email string
841
+ */
842
+ getUserByIdentifier?(identifier: string): Promise<UserIdentity | null>;
843
+ /**
844
+ * Deletes a user account.
845
+ *
846
+ * @param id - Unique user ID
847
+ */
848
+ deleteUser?(id: string): Promise<void>;
849
+ }
850
+
851
+ /**
852
+ * Thrown when user credentials (username/email and password) are invalid during authentication.
853
+ *
854
+ * @public
855
+ */
856
+ export declare class InvalidCredentialsError extends LixaError {
857
+ constructor(message?: string, details?: Record<string, unknown>);
858
+ }
859
+
375
860
  /**
376
861
  * Thrown when OAuth callback parameters (e.g. authorization code or state) are missing or malformed.
377
862
  *
@@ -399,6 +884,34 @@ export declare class InvalidStateError extends LixaError {
399
884
  constructor(message?: string, details?: Record<string, unknown>);
400
885
  }
401
886
 
887
+ /**
888
+ * Interface for password hashing and verification algorithms.
889
+ *
890
+ * @remarks
891
+ * Lixa defaults to ScryptPasswordHasher (Node.js crypto.scrypt, 0 dependencies).
892
+ * Implement this interface to use custom algorithms (e.g. bcrypt, argon2, pbkdf2).
893
+ *
894
+ * @public
895
+ */
896
+ export declare interface IPasswordHasher {
897
+ /**
898
+ * Computes a secure cryptographic hash for a plaintext password.
899
+ *
900
+ * @param password - Plaintext password
901
+ * @returns Formatted hash string containing salt and algorithm parameters
902
+ */
903
+ hash(password: string): Promise<string>;
904
+ /**
905
+ * Verifies a plaintext password against a stored hash string.
906
+ * Must use constant-time comparison to prevent timing attacks.
907
+ *
908
+ * @param password - Plaintext password to verify
909
+ * @param hash - Stored hash string
910
+ * @returns True if password matches hash, false otherwise
911
+ */
912
+ verify(password: string, hash: string): Promise<boolean>;
913
+ }
914
+
402
915
  /**
403
916
  * Interface for OAuth 2.0 and OpenID Connect provider implementations.
404
917
  *
@@ -537,6 +1050,10 @@ export declare interface IProvider {
537
1050
  * @example ['openid', 'email', 'profile'] or ['read:user', 'user:email']
538
1051
  */
539
1052
  authScopes?: string[];
1053
+ /**
1054
+ * Default OAuth scopes requested when not explicitly specified in ProviderConfig.
1055
+ */
1056
+ defaultScopes?: string[];
540
1057
  }
541
1058
 
542
1059
  /**
@@ -550,7 +1067,7 @@ export declare function isProductionEnvironment(): boolean;
550
1067
  *
551
1068
  * @public
552
1069
  */
553
- declare interface LinkedAccount {
1070
+ export declare interface LinkedAccount {
554
1071
  /** The provider identifier (e.g. 'github', 'google') */
555
1072
  provider: string;
556
1073
  /** Provider user ID if available */
@@ -617,19 +1134,25 @@ declare interface LinkedAccount {
617
1134
  *
618
1135
  * @public
619
1136
  */
620
- export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> = LixaConfig> {
1137
+ export declare class Lixa<TProviders extends Record<string, ProviderConfig> = Record<string, ProviderConfig>> {
621
1138
  private static DEFAULT_PROVIDERS;
622
1139
  private static CONFIGURED_PROVIDERS;
623
1140
  private localStateHandler;
624
1141
  private localSessionHandler;
625
1142
  private localResourceHandler;
1143
+ private localAccountHandler;
626
1144
  private userResourceStore;
1145
+ private userAccountStore;
627
1146
  private refreshMutexes;
1147
+ private identityProvider?;
1148
+ private credentialsManager?;
628
1149
  private config;
629
1150
  private stateHandler;
630
1151
  private sessionHandler;
631
1152
  private resourceHandler;
1153
+ private accountHandler;
632
1154
  private debug;
1155
+ private sessionCookieResolver?;
633
1156
  /**
634
1157
  * Creates a new Lixa instance with the provided configuration.
635
1158
  *
@@ -643,7 +1166,7 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
643
1166
  * @throws Error when provider implementation is missing required properties
644
1167
  * @throws Error when provider is not available and no inline implementation is provided
645
1168
  */
646
- constructor(config: TConfig);
1169
+ constructor(config: LixaConfig<TProviders>);
647
1170
  /**
648
1171
  * Validates that a provider configuration has all required credentials.
649
1172
  *
@@ -664,7 +1187,7 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
664
1187
  * Structured logging with standardized format and custom logger support.
665
1188
  *
666
1189
  * @param level - Log level (INFO, WARN, ERROR, DEBUG)
667
- * @param context - Context of the log (Init, Auth, Token, Session, State, AccountLinking, Resource)
1190
+ * @param context - Context of the log (Init, Auth, Token, Session, State, AccountLinking, Resource, Credentials)
668
1191
  * @param message - Log message
669
1192
  * @param data - Optional data to log
670
1193
  */
@@ -684,7 +1207,7 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
684
1207
  * }
685
1208
  * ```
686
1209
  */
687
- isProviderConfigured<T extends string>(provider: T): provider is T & ConfiguredProviderKey<TConfig>;
1210
+ isProviderConfigured<T extends string>(provider: T): provider is T & ConfiguredProviderKey<TProviders>;
688
1211
  /**
689
1212
  * Gets a provider implementation by name.
690
1213
  * Resolution priority: inline custom provider \> default providers \> legacy registry
@@ -758,7 +1281,9 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
758
1281
  */
759
1282
  static createConfig<T extends Record<string, ProviderConfig>>(config: LixaConfig<T> & {
760
1283
  providers: T;
761
- }): LixaConfig<T>;
1284
+ }): LixaConfig<T> & {
1285
+ providers: T;
1286
+ };
762
1287
  /**
763
1288
  * Generates a cryptographically secure random state parameter for OAuth flows.
764
1289
  *
@@ -863,7 +1388,7 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
863
1388
  * res.redirect(authUrl);
864
1389
  * ```
865
1390
  */
866
- getAuthUrl(provider: ConfiguredProviderKey<TConfig> | string, state?: string): Promise<string>;
1391
+ getAuthUrl(provider: ConfiguredProviderKey<TProviders> | string, state?: string): Promise<string>;
867
1392
  /**
868
1393
  * Restricts primary authentication scopes strictly to AuthN identity scopes unless allowNonAuthScopes is true.
869
1394
  */
@@ -887,10 +1412,11 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
887
1412
  * });
888
1413
  * ```
889
1414
  */
890
- handleCallback({ provider, code, state, }: {
891
- provider: ConfiguredProviderKey<TConfig> | string;
1415
+ handleCallback({ provider, code, state, sessionId, }: {
1416
+ provider: ConfiguredProviderKey<TProviders> | string;
892
1417
  code: string;
893
1418
  state?: string;
1419
+ sessionId?: string;
894
1420
  }): Promise<string>;
895
1421
  /**
896
1422
  * Explicitly link a new OAuth provider account to an active session.
@@ -900,7 +1426,7 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
900
1426
  */
901
1427
  linkAccount(params: {
902
1428
  sessionId: string;
903
- provider: ConfiguredProviderKey<TConfig> | string;
1429
+ provider: ConfiguredProviderKey<TProviders> | string;
904
1430
  code: string;
905
1431
  state?: string;
906
1432
  }): Promise<string>;
@@ -925,8 +1451,8 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
925
1451
  */
926
1452
  getResourceAuthUrl(params: {
927
1453
  sessionId: string;
928
- provider: ConfiguredProviderKey<TConfig> | string;
929
- scopes: string[];
1454
+ provider: ConfiguredProviderKey<TProviders> | string;
1455
+ scopes?: string[];
930
1456
  state?: string;
931
1457
  prompt?: string;
932
1458
  extraConfig?: Record<string, string>;
@@ -937,11 +1463,32 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
937
1463
  */
938
1464
  handleResourceCallback(params: {
939
1465
  sessionId: string;
940
- provider: ConfiguredProviderKey<TConfig> | string;
1466
+ provider: ConfiguredProviderKey<TProviders> | string;
941
1467
  code: string;
942
1468
  state?: string;
943
1469
  scopes?: string[];
944
1470
  }): Promise<Session>;
1471
+ /**
1472
+ * Retrieves configured default resource scopes for a provider.
1473
+ *
1474
+ * @param provider - Provider name (e.g. 'github', 'google')
1475
+ * @returns Array of configured resource scopes, or undefined if not configured
1476
+ */
1477
+ getResourceScopes(provider: ConfiguredProviderKey<TProviders> | string): string[] | undefined;
1478
+ /**
1479
+ * Returns the resolved session cookie name.
1480
+ * Dynamically reflects any changes to the active identity provider.
1481
+ *
1482
+ * @param req - Optional request object for multi-tenant request-scoped cookie resolution
1483
+ * @returns Resolved session cookie name
1484
+ */
1485
+ getSessionCookieName(req?: unknown): string;
1486
+ /**
1487
+ * Sets or updates the session cookie name or dynamic resolver on this instance.
1488
+ *
1489
+ * @param resolver - Static cookie name or dynamic resolver function
1490
+ */
1491
+ setSessionCookieName(resolver: SessionCookieResolver<Lixa<TProviders>>): void;
945
1492
  /**
946
1493
  * Retrieves a connected resource for a specific User ID / Email directly (independent of session IDs).
947
1494
  * Automatically refreshes expired access tokens if a refresh token is present.
@@ -996,10 +1543,130 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
996
1543
  */
997
1544
  deleteSession(sessionId: string): Promise<void>;
998
1545
  private exchangeCodeForToken;
999
- private findProviderByType;
1000
- }
1001
-
1002
- /**
1546
+ /**
1547
+ * Checks if an identity provider (Self-Managed Database, AWS Cognito, Auth0, Okta, etc.) is configured.
1548
+ *
1549
+ * @returns True if identity provider is configured and available
1550
+ */
1551
+ isIdentityEnabled(): boolean;
1552
+ /**
1553
+ * Checks if credentials / identity authentication is configured and enabled.
1554
+ *
1555
+ * @returns True if credentials / identity authentication is available
1556
+ */
1557
+ isCredentialsEnabled(): boolean;
1558
+ /**
1559
+ * Returns the configured IdentityProvider instance.
1560
+ */
1561
+ getIdentityProvider(): IIdentityProvider | undefined;
1562
+ /**
1563
+ * Dynamically sets or updates the active identity provider (e.g. SelfManaged, Cognito, Auth0, Okta).
1564
+ *
1565
+ * @param provider - Identity provider instance or undefined to disable
1566
+ */
1567
+ setIdentityProvider(provider?: IIdentityProvider): void;
1568
+ /**
1569
+ * Returns the underlying CredentialsManager instance if using Self-Managed identity.
1570
+ */
1571
+ getCredentialsManager(): CredentialsManager | undefined;
1572
+ /**
1573
+ * Registers a new user with the configured identity provider (Self-Managed DB, Cognito, Auth0, Okta).
1574
+ * Automatically creates an active session unless autoCreateSessionOnSignUp is explicitly set to false.
1575
+ *
1576
+ * @param params - Registration parameters (identifier, password, email, username, metadata)
1577
+ * @returns Created user identity and optional active session
1578
+ * @throws WeakPasswordError if password does not meet policy requirements
1579
+ * @throws UserAlreadyExistsError if identifier is already registered
1580
+ * @throws IdentityNotConfiguredError if identity authentication is not configured
1581
+ */
1582
+ signUp(params: SignUpParams): Promise<SignUpResult>;
1583
+ /**
1584
+ * Authenticates a user with credentials via the configured identity provider (Self-Managed DB, Cognito, Auth0, Okta).
1585
+ * Creates an active session and automatically links with existing sessions when AUTO_LINK_BY_VERIFIED_EMAIL is configured.
1586
+ *
1587
+ * @param params - Sign-in parameters (identifier, password)
1588
+ * @returns Authenticated user, session ID, and session object
1589
+ * @throws InvalidCredentialsError if authentication fails
1590
+ * @throws IdentityNotConfiguredError if identity authentication is not configured
1591
+ */
1592
+ signIn(params: SignInParams): Promise<SignInResult>;
1593
+ /**
1594
+ * Verifies username/email and password credentials without generating a session.
1595
+ *
1596
+ * @param params - Verification parameters (identifier, password)
1597
+ * @returns User credentials/identity or null if invalid
1598
+ * @throws IdentityNotConfiguredError if identity auth is not configured
1599
+ */
1600
+ verifyCredentials(params: VerifyCredentialsParams): Promise<UserIdentity | null>;
1601
+ /**
1602
+ * Updates a user's password after verifying the current password and enforcing policy on the new password.
1603
+ *
1604
+ * @param params - Change password parameters (userId/identifier, oldPassword, newPassword)
1605
+ * @returns True if password was updated successfully
1606
+ * @throws UserNotFoundError if user is not found
1607
+ * @throws InvalidCredentialsError if current password is incorrect
1608
+ * @throws WeakPasswordError if new password does not meet policy requirements
1609
+ * @throws IdentityNotConfiguredError if identity auth is not configured
1610
+ */
1611
+ changePassword(params: ChangePasswordParams): Promise<boolean>;
1612
+ /**
1613
+ * Initiates a password reset (forgot password flow) through the configured identity provider.
1614
+ *
1615
+ * @param params - Forgot password parameters (identifier, optional metadata)
1616
+ * @returns ForgotPasswordResult indicating status and delivery medium (email/SMS)
1617
+ * @throws IdentityNotConfiguredError if identity auth is not configured
1618
+ */
1619
+ forgotPassword(params: ForgotPasswordParams): Promise<ForgotPasswordResult>;
1620
+ /**
1621
+ * Confirms a password reset using a verification code / token and sets the new password.
1622
+ *
1623
+ * @param params - Verification code, identifier, and new password
1624
+ * @returns True if password reset was successfully confirmed
1625
+ * @throws IdentityNotConfiguredError if identity auth is not configured
1626
+ */
1627
+ confirmPasswordReset(params: ConfirmPasswordResetParams): Promise<boolean>;
1628
+ /**
1629
+ * Confirms user account registration using a verification code.
1630
+ *
1631
+ * @param params - Verification parameters including identifier and confirmationCode
1632
+ * @returns True if confirmation was successful
1633
+ * @throws IdentityNotConfiguredError if identity auth is not configured
1634
+ * @throws IdentityProviderError if identity provider does not support confirmation
1635
+ */
1636
+ confirmSignUp(params: ConfirmSignUpParams): Promise<boolean>;
1637
+ /**
1638
+ * Resends the sign up confirmation code to the user.
1639
+ *
1640
+ * @param params - Resend parameters including user identifier
1641
+ * @returns Details about the code delivery (medium, destination)
1642
+ * @throws IdentityNotConfiguredError if identity auth is not configured
1643
+ * @throws IdentityProviderError if identity provider does not support resending codes
1644
+ */
1645
+ resendConfirmationCode(params: ResendConfirmationCodeParams): Promise<ResendConfirmationCodeResult>;
1646
+ /**
1647
+ * Retrieves a user by their unique ID from the configured identity provider.
1648
+ *
1649
+ * @param id - Unique user ID
1650
+ * @returns UserIdentity or null if not found
1651
+ */
1652
+ getUserById(id: string): Promise<UserIdentity | null>;
1653
+ /**
1654
+ * Retrieves a user by their identifier (username or email) from the configured identity provider.
1655
+ *
1656
+ * @param identifier - Username or email string
1657
+ * @returns UserIdentity or null if not found
1658
+ */
1659
+ getUserByIdentifier(identifier: string): Promise<UserIdentity | null>;
1660
+ /**
1661
+ * Deletes a user account from the configured identity provider.
1662
+ *
1663
+ * @param id - Unique user ID
1664
+ */
1665
+ deleteUser(id: string): Promise<void>;
1666
+ private findProviderByType;
1667
+ }
1668
+
1669
+ /**
1003
1670
  * Main configuration object for Lixa.
1004
1671
  * Provides type-safe provider name inference.
1005
1672
  *
@@ -1007,14 +1674,50 @@ export declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConf
1007
1674
  */
1008
1675
  export declare interface LixaConfig<TProviders extends Record<string, ProviderConfig> = Record<string, ProviderConfig>> {
1009
1676
  /**
1010
- * Map of provider names to their configurations.
1677
+ * Map of federated OAuth 2.0 / OIDC provider names to their configurations (Google, GitHub, etc.)
1678
+ * that federate with and work alongside the primary identityProvider.
1011
1679
  * Provider names will be available for autocomplete in getAuthUrl() and handleCallback().
1012
1680
  */
1013
- providers: TProviders;
1681
+ federatedOAuthProviders?: TProviders;
1682
+ /**
1683
+ * Alias for {@link LixaConfig.federatedOAuthProviders}.
1684
+ */
1685
+ providers?: TProviders;
1686
+ /**
1687
+ * Primary Identity Provider configuration (Self-Managed Database, AWS Cognito, Auth0, Okta, or custom IIdentityProvider).
1688
+ *
1689
+ * @example
1690
+ * Self-managed with Prisma:
1691
+ * ```typescript
1692
+ * identityProvider: { storage: prismaAdapter.credentialsStorage }
1693
+ * ```
1694
+ *
1695
+ * @example
1696
+ * AWS Cognito:
1697
+ * ```typescript
1698
+ * identityProvider: new CognitoIdentityProvider({ userPoolId: '...', clientId: '...', region: 'us-east-1' })
1699
+ * ```
1700
+ */
1701
+ identityProvider?: IIdentityProvider | IdentityConfig;
1702
+ /**
1703
+ * Alias for {@link LixaConfig.identityProvider}.
1704
+ */
1705
+ identity?: IIdentityProvider | IdentityConfig;
1706
+ /**
1707
+ * Credentials (username and password) authentication configuration.
1708
+ * Automatically maps to a SelfManagedIdentityProvider.
1709
+ */
1710
+ credentials?: CredentialsConfig;
1711
+ /**
1712
+ * Unified database storage adapter (e.g. createPrismaAdapter or createDrizzleAdapter).
1713
+ * Automatically configures sessionHandler, stateHandler, and resourceHandler.
1714
+ */
1715
+ storage?: StorageAdapter;
1014
1716
  /**
1015
1717
  * Account linking configuration for multi-SSO user linking.
1718
+ * Pass `true` or `"linkByEmail"` for automatic email-verified linking.
1016
1719
  */
1017
- accountLinking?: AccountLinkingConfig;
1720
+ accountLinking?: boolean | AccountLinkingMode | AccountLinkingConfig;
1018
1721
  /**
1019
1722
  * Optional custom state handler.
1020
1723
  * Handles state generation and storage during OAuth authorization flow.
@@ -1058,6 +1761,23 @@ export declare interface LixaConfig<TProviders extends Record<string, ProviderCo
1058
1761
  * If provided, all Lixa logs will be routed through this logger.
1059
1762
  */
1060
1763
  logger?: LixaLogger;
1764
+ /**
1765
+ * Session cookie name or dynamic resolution function.
1766
+ * Can accept a static string or `(lixa: Lixa, req?: unknown) => string`.
1767
+ * Automatically evaluated live against the instance when getSessionCookieName() is called.
1768
+ */
1769
+ sessionCookieName?: SessionCookieResolver;
1770
+ }
1771
+
1772
+ /**
1773
+ * Interface exposing identity information for dynamic session cookie name resolution.
1774
+ * @public
1775
+ */
1776
+ export declare interface LixaCookieContext {
1777
+ /**
1778
+ * Retrieves the currently active identity provider.
1779
+ */
1780
+ getIdentityProvider(): IIdentityProvider | undefined;
1061
1781
  }
1062
1782
 
1063
1783
  /**
@@ -1085,11 +1805,30 @@ export declare interface LixaLogger {
1085
1805
  log(level: LogLevel, context: LogContext, message: string, data?: Record<string, unknown>): void;
1086
1806
  }
1087
1807
 
1808
+ /**
1809
+ * In-memory credentials storage for development, testing, and isolated environments.
1810
+ *
1811
+ * @remarks
1812
+ * Uses instance-isolated Maps to prevent state leakage across tests or Lixa instances.
1813
+ *
1814
+ * @public
1815
+ */
1816
+ export declare class LocalCredentialsStorage implements CredentialsStorage {
1817
+ private usersById;
1818
+ private identifierToId;
1819
+ saveUser(user: UserCredentials): Promise<void>;
1820
+ findUserByIdentifier(identifier: string): Promise<UserCredentials | null>;
1821
+ findUserById(id: string): Promise<UserCredentials | null>;
1822
+ updatePassword(id: string, newPasswordHash: string): Promise<void>;
1823
+ deleteUser(id: string): Promise<void>;
1824
+ clear(): void;
1825
+ }
1826
+
1088
1827
  /**
1089
1828
  * Log context for Lixa structured logging.
1090
1829
  * @public
1091
1830
  */
1092
- export declare type LogContext = "Init" | "Auth" | "Token" | "Session" | "State" | "AccountLinking" | "Resource";
1831
+ export declare type LogContext = "Init" | "Auth" | "Token" | "Session" | "State" | "AccountLinking" | "Resource" | "Credentials" | "Identity";
1093
1832
 
1094
1833
  /**
1095
1834
  * Log level for Lixa structured logging.
@@ -1146,6 +1885,102 @@ export declare interface OAuthTokenResponse {
1146
1885
  [key: string]: string | number | boolean | undefined;
1147
1886
  }
1148
1887
 
1888
+ /**
1889
+ * Configuration options for password validation rules.
1890
+ *
1891
+ * @public
1892
+ */
1893
+ export declare interface PasswordPolicyConfig {
1894
+ /**
1895
+ * Minimum password length in characters.
1896
+ *
1897
+ * @default 8
1898
+ */
1899
+ minLength?: number | undefined;
1900
+ /**
1901
+ * Maximum password length in characters to prevent hashing DoS attacks.
1902
+ *
1903
+ * @default 128
1904
+ */
1905
+ maxLength?: number | undefined;
1906
+ /**
1907
+ * Require at least one uppercase letter [A-Z].
1908
+ *
1909
+ * @default false
1910
+ */
1911
+ requireUppercase?: boolean | undefined;
1912
+ /**
1913
+ * Require at least one lowercase letter [a-z].
1914
+ *
1915
+ * @default false
1916
+ */
1917
+ requireLowercase?: boolean | undefined;
1918
+ /**
1919
+ * Require at least one numeric digit [0-9].
1920
+ *
1921
+ * @default false
1922
+ */
1923
+ requireNumbers?: boolean | undefined;
1924
+ /**
1925
+ * Require at least one special symbol character.
1926
+ *
1927
+ * @default false
1928
+ */
1929
+ requireSpecialChars?: boolean | undefined;
1930
+ /**
1931
+ * Optional custom validator function for enterprise or custom rules.
1932
+ * Return `true` if valid, or `false` / custom error message string if invalid.
1933
+ */
1934
+ customValidator?: ((password: string) => boolean | string | Promise<boolean | string>) | undefined;
1935
+ }
1936
+
1937
+ /**
1938
+ * Result of password policy validation.
1939
+ *
1940
+ * @public
1941
+ */
1942
+ export declare interface PasswordPolicyResult {
1943
+ /** Whether the password satisfied all configured rules */
1944
+ valid: boolean;
1945
+ /** List of human-readable error descriptions if validation failed */
1946
+ errors: string[];
1947
+ }
1948
+
1949
+ /**
1950
+ * Options for PBKDF2 password hashing.
1951
+ *
1952
+ * @public
1953
+ */
1954
+ export declare interface Pbkdf2HasherOptions {
1955
+ /** Iteration count. Default: 100000 */
1956
+ iterations?: number;
1957
+ /** HMAC digest algorithm. Default: 'sha512' */
1958
+ digest?: string;
1959
+ /** Salt length in bytes. Default: 16 */
1960
+ saltLength?: number;
1961
+ /** Derived key length in bytes. Default: 64 */
1962
+ keyLength?: number;
1963
+ }
1964
+
1965
+ /**
1966
+ * Alternative password hasher using Node.js native `crypto.pbkdf2`.
1967
+ *
1968
+ * @remarks
1969
+ * Produces PHC-formatted strings: `$pbkdf2$i=100000,d=sha512$<saltHex>$<keyHex>`.
1970
+ *
1971
+ * @public
1972
+ */
1973
+ export declare class Pbkdf2PasswordHasher implements IPasswordHasher {
1974
+ private readonly iterations;
1975
+ private readonly digest;
1976
+ private readonly saltLength;
1977
+ private readonly keyLength;
1978
+ constructor(options?: Pbkdf2HasherOptions);
1979
+ hash(password: string): Promise<string>;
1980
+ verify(password: string, hash: string): Promise<boolean>;
1981
+ private deriveKey;
1982
+ }
1983
+
1149
1984
  /**
1150
1985
  * Configuration for an OAuth provider instance.
1151
1986
  *
@@ -1189,8 +2024,13 @@ export declare type ProviderConfig = {
1189
2024
  clientSecret: string;
1190
2025
  /** The redirect URI registered with the provider */
1191
2026
  redirectUri: string;
1192
- /** Array of OAuth scopes to request */
1193
- scopes: string[];
2027
+ /** Array of OAuth scopes to request. If omitted, uses provider default identity scopes. */
2028
+ scopes?: string[];
2029
+ /**
2030
+ * Default scopes requested when connecting this provider as a third-party resource (AuthZ).
2031
+ * Used automatically by getResourceAuthUrl() and handleResourceCallback() if not overridden at runtime.
2032
+ */
2033
+ resourceScopes?: string[];
1194
2034
  /**
1195
2035
  * Set to true to allow non-identity (resource) scopes during primary authentication flow.
1196
2036
  * By default (false), Lixa restricts primary AuthN scopes to identity scopes to maintain
@@ -1243,6 +2083,30 @@ export declare class RefreshTokenError extends LixaError {
1243
2083
  constructor(message: string, details?: Record<string, unknown>);
1244
2084
  }
1245
2085
 
2086
+ /**
2087
+ * Parameters for resending a sign up confirmation code.
2088
+ *
2089
+ * @public
2090
+ */
2091
+ export declare interface ResendConfirmationCodeParams {
2092
+ /** Username or email of the account */
2093
+ identifier: string;
2094
+ }
2095
+
2096
+ /**
2097
+ * Result of resending a sign up confirmation code.
2098
+ *
2099
+ * @public
2100
+ */
2101
+ export declare interface ResendConfirmationCodeResult {
2102
+ /** True if code was dispatched */
2103
+ success: boolean;
2104
+ /** Delivery medium (e.g. 'EMAIL' or 'SMS') */
2105
+ deliveryMedium?: string | undefined;
2106
+ /** Obscured destination */
2107
+ destination?: string | undefined;
2108
+ }
2109
+
1246
2110
  /**
1247
2111
  * Resource handler configuration.
1248
2112
  *
@@ -1305,6 +2169,110 @@ export declare type SafeLixaConfig<TProviders extends Record<string, ProviderCon
1305
2169
  providers: TProviders;
1306
2170
  };
1307
2171
 
2172
+ /**
2173
+ * Options for Scrypt password hashing.
2174
+ *
2175
+ * @public
2176
+ */
2177
+ export declare interface ScryptHasherOptions {
2178
+ /** CPU/memory cost parameter (must be power of 2). Default: 16384 (2^14) */
2179
+ cost?: number;
2180
+ /** Block size parameter. Default: 8 */
2181
+ blockSize?: number;
2182
+ /** Parallelization parameter. Default: 1 */
2183
+ parallelization?: number;
2184
+ /** Salt length in bytes. Default: 16 */
2185
+ saltLength?: number;
2186
+ /** Derived key length in bytes. Default: 64 */
2187
+ keyLength?: number;
2188
+ /** Max memory allocated in bytes. Default: 32MB */
2189
+ maxmem?: number;
2190
+ }
2191
+
2192
+ /**
2193
+ * Default secure password hasher utilizing Node.js native `crypto.scrypt`.
2194
+ *
2195
+ * @remarks
2196
+ * Produces PHC-formatted strings: `$scrypt$N=16384,r=8,p=1$<saltHex>$<keyHex>`.
2197
+ * Verification uses constant-time `crypto.timingSafeEqual` to prevent timing attacks.
2198
+ *
2199
+ * @public
2200
+ */
2201
+ export declare class ScryptPasswordHasher implements IPasswordHasher {
2202
+ private readonly cost;
2203
+ private readonly blockSize;
2204
+ private readonly parallelization;
2205
+ private readonly saltLength;
2206
+ private readonly keyLength;
2207
+ private readonly maxmem;
2208
+ constructor(options?: ScryptHasherOptions);
2209
+ /**
2210
+ * Hashes a plaintext password using Scrypt.
2211
+ *
2212
+ * @param password - Plaintext password
2213
+ * @returns Formatted Scrypt hash string
2214
+ */
2215
+ hash(password: string): Promise<string>;
2216
+ /**
2217
+ * Verifies a password against a stored Scrypt hash.
2218
+ *
2219
+ * @param password - Plaintext password
2220
+ * @param hash - Formatted Scrypt hash string
2221
+ * @returns True if password matches hash
2222
+ */
2223
+ verify(password: string, hash: string): Promise<boolean>;
2224
+ private deriveKey;
2225
+ }
2226
+
2227
+ /**
2228
+ * Self-Managed Identity Provider implementation for Lixa.
2229
+ *
2230
+ * @remarks
2231
+ * Backed by custom database storage (Prisma, Drizzle, PostgreSQL, SQLite, MongoDB)
2232
+ * or local in-memory storage, with cryptographic password hashing (Scrypt, Argon2, PBKDF2)
2233
+ * and configurable password policy enforcement.
2234
+ *
2235
+ * @public
2236
+ */
2237
+ export declare class SelfManagedIdentityProvider implements IIdentityProvider {
2238
+ readonly name: string;
2239
+ private readonly manager;
2240
+ constructor(configOrManager?: CredentialsConfig | CredentialsManager);
2241
+ private mapUser;
2242
+ /**
2243
+ * Registers a new user.
2244
+ */
2245
+ signUp(params: SignUpParams): Promise<UserIdentity>;
2246
+ /**
2247
+ * Authenticates a user with password.
2248
+ */
2249
+ signIn(params: SignInParams): Promise<IdentityAuthResult>;
2250
+ /**
2251
+ * Verifies credentials without throwing an error if invalid.
2252
+ */
2253
+ verifyCredentials(params: VerifyCredentialsParams): Promise<UserIdentity | null>;
2254
+ /**
2255
+ * Changes a user's password.
2256
+ */
2257
+ changePassword(params: ChangePasswordParams): Promise<boolean>;
2258
+ /**
2259
+ * Retrieves a user by their unique ID.
2260
+ */
2261
+ getUserById(id: string): Promise<UserIdentity | null>;
2262
+ /**
2263
+ * Retrieves a user by their identifier (email or username).
2264
+ */
2265
+ getUserByIdentifier(identifier: string): Promise<UserIdentity | null>;
2266
+ /**
2267
+ * Deletes a user from storage if supported by the storage adapter.
2268
+ */
2269
+ deleteUser(id: string): Promise<void>;
2270
+ /**
2271
+ * Returns the underlying CredentialsManager instance.
2272
+ */
2273
+ getCredentialsManager(): CredentialsManager;
2274
+ }
2275
+
1308
2276
  /**
1309
2277
  * Serializes a cookie name, value, and options into a standard `Set-Cookie` header string.
1310
2278
  *
@@ -1331,35 +2299,43 @@ export declare function serializeCookie(name: string, value: string, options?: C
1331
2299
  */
1332
2300
  export declare interface Session<TRaw = OAuthTokenResponse> {
1333
2301
  /**
1334
- * Unique session ID generated by Lixa upon authentication.
2302
+ * Unique canonical session ID generated by Lixa upon authentication.
1335
2303
  */
1336
- id?: string;
2304
+ sessionId?: string | undefined;
1337
2305
  /**
1338
2306
  * Linked identity provider accounts (AuthN) keyed by provider name.
1339
2307
  * Single source of truth for all authenticated user SSO identities.
1340
2308
  */
1341
- accounts?: Record<string, LinkedAccount>;
2309
+ accounts?: Record<string, LinkedAccount> | undefined;
1342
2310
  /**
1343
2311
  * Connected third-party resource provider tokens (AuthZ) keyed by provider name.
1344
2312
  * Single source of truth for all post-login third-party API permissions.
1345
2313
  */
1346
- resources?: Record<string, ConnectedResource>;
2314
+ resources?: Record<string, ConnectedResource> | undefined;
1347
2315
  /** Unique unified user ID across linked accounts */
1348
- userId?: string;
2316
+ userId?: string | undefined;
1349
2317
  /** Primary user email */
1350
- email?: string;
2318
+ email?: string | undefined;
1351
2319
  /**
1352
2320
  * Optional primary access token or custom session token identifier.
1353
2321
  */
1354
- token?: string;
2322
+ token?: string | undefined;
1355
2323
  /** Optional current active auth provider for this session turn */
1356
- provider?: string;
2324
+ provider?: string | undefined;
1357
2325
  /**
1358
2326
  * Optional raw session token response data from provider.
1359
2327
  */
1360
- raw?: TRaw;
2328
+ raw?: TRaw | undefined;
1361
2329
  }
1362
2330
 
2331
+ /**
2332
+ * Dynamic resolver for session cookie name.
2333
+ * Can be a static string or a dynamic callback receiving the Lixa instance and an optional request context.
2334
+ *
2335
+ * @public
2336
+ */
2337
+ export declare type SessionCookieResolver<TContext extends LixaCookieContext = LixaCookieContext> = string | ((lixa: TContext, req?: unknown) => string);
2338
+
1363
2339
  /**
1364
2340
  * Session handler for OAuth authentication.
1365
2341
  *
@@ -1504,6 +2480,66 @@ export declare interface SessionStorage {
1504
2480
  } | null>;
1505
2481
  }
1506
2482
 
2483
+ /**
2484
+ * Parameters for user authentication (signIn).
2485
+ *
2486
+ * @public
2487
+ */
2488
+ export declare interface SignInParams {
2489
+ /** Username or email of the account */
2490
+ username?: string | undefined;
2491
+ /** Primary identifier (username or email) */
2492
+ identifier?: string | undefined;
2493
+ /** Plaintext password */
2494
+ password: string;
2495
+ }
2496
+
2497
+ /**
2498
+ * Result of user authentication (signIn).
2499
+ *
2500
+ * @public
2501
+ */
2502
+ export declare interface SignInResult<TSession = Session, TUser = UserIdentity> {
2503
+ /** Authenticated user profile / credentials (with passwordHash omitted for safety) */
2504
+ user: TUser;
2505
+ /** Active session ID */
2506
+ sessionId: string;
2507
+ /** Active session object */
2508
+ session: TSession;
2509
+ }
2510
+
2511
+ /**
2512
+ * Parameters for user registration (signUp).
2513
+ *
2514
+ * @public
2515
+ */
2516
+ export declare interface SignUpParams {
2517
+ /** Username for the user (can be used directly instead of identifier) */
2518
+ username?: string | undefined;
2519
+ /** Primary identifier (username or email) */
2520
+ identifier?: string | undefined;
2521
+ /** Plaintext password */
2522
+ password: string;
2523
+ /** Optional explicit email address */
2524
+ email?: string | undefined;
2525
+ /** Optional custom user metadata */
2526
+ metadata?: Record<string, unknown> | undefined;
2527
+ }
2528
+
2529
+ /**
2530
+ * Result of user registration (signUp).
2531
+ *
2532
+ * @public
2533
+ */
2534
+ export declare interface SignUpResult<TSession = Session, TUser = UserIdentity> {
2535
+ /** Created user profile / credentials (with passwordHash omitted for safety) */
2536
+ user: TUser;
2537
+ /** Created session ID if autoCreateSessionOnSignUp is enabled */
2538
+ sessionId?: string | undefined;
2539
+ /** Created session object if autoCreateSessionOnSignUp is enabled */
2540
+ session?: TSession | undefined;
2541
+ }
2542
+
1507
2543
  /**
1508
2544
  * OAuth state data structure.
1509
2545
  *
@@ -1697,6 +2733,19 @@ export declare interface StateStorage {
1697
2733
  deleteState(state: string): Promise<void>;
1698
2734
  }
1699
2735
 
2736
+ /**
2737
+ * Unified storage adapter interface (e.g. Prisma or Drizzle adapter).
2738
+ * When provided to Lixa via config.storage, automatically configures session, state, and resource storage.
2739
+ * @public
2740
+ */
2741
+ declare interface StorageAdapter {
2742
+ sessionStorage?: any;
2743
+ resourceStorage?: any;
2744
+ stateStorage?: any;
2745
+ credentialsStorage?: any;
2746
+ accountStorage?: any;
2747
+ }
2748
+
1700
2749
  /**
1701
2750
  * Thrown when exchanging an authorization code for OAuth tokens fails at the provider endpoint.
1702
2751
  *
@@ -1707,6 +2756,66 @@ export declare class TokenExchangeError extends LixaError {
1707
2756
  constructor(message: string, status?: number, details?: Record<string, unknown>);
1708
2757
  }
1709
2758
 
2759
+ /**
2760
+ * Thrown when attempting to register a user with an identifier that already exists.
2761
+ *
2762
+ * @public
2763
+ */
2764
+ export declare class UserAlreadyExistsError extends LixaError {
2765
+ constructor(identifier: string, details?: Record<string, unknown>);
2766
+ }
2767
+
2768
+ /**
2769
+ * User credentials entity representing stored account login information.
2770
+ *
2771
+ * @public
2772
+ */
2773
+ export declare interface UserCredentials {
2774
+ /** Unique user identifier (UUID or Nanoid) */
2775
+ id: string;
2776
+ /** Primary unique lookup identifier (normalized lowercase username or email) */
2777
+ identifier: string;
2778
+ /** Username of the account */
2779
+ username?: string | undefined;
2780
+ /** Associated email address */
2781
+ email?: string | undefined;
2782
+ /** Securely hashed password string (e.g. Scrypt, Argon2, PBKDF2, Bcrypt) */
2783
+ passwordHash: string;
2784
+ /** Unix timestamp in milliseconds when user credentials were created */
2785
+ createdAt: number;
2786
+ /** Unix timestamp in milliseconds when user credentials were last updated */
2787
+ updatedAt: number;
2788
+ /** Optional custom user metadata or profile attributes */
2789
+ metadata?: Record<string, unknown> | undefined;
2790
+ }
2791
+
2792
+ /**
2793
+ * Standardized user identity representation across all identity providers
2794
+ * (Self-Managed Database, AWS Cognito, Auth0, Okta, Firebase, etc.).
2795
+ *
2796
+ * @public
2797
+ */
2798
+ export declare interface UserIdentity {
2799
+ /** Unique user identifier (UUID, Sub, Auth0 user_id, Okta id) */
2800
+ id: string;
2801
+ /** Primary unique lookup identifier (email or username) */
2802
+ identifier: string;
2803
+ /** Associated email address if available */
2804
+ email?: string | undefined;
2805
+ /** Username of the account if available */
2806
+ username?: string | undefined;
2807
+ /** Whether the email address has been verified by the identity provider */
2808
+ emailVerified?: boolean | undefined;
2809
+ /** Unix timestamp in milliseconds when user was created */
2810
+ createdAt?: number | undefined;
2811
+ /** Unix timestamp in milliseconds when user was last updated */
2812
+ updatedAt?: number | undefined;
2813
+ /** Custom user metadata or profile attributes */
2814
+ metadata?: Record<string, unknown> | undefined;
2815
+ /** Identity provider name (e.g. "self-managed", "cognito", "auth0", "okta") */
2816
+ provider?: string | undefined;
2817
+ }
2818
+
1710
2819
  /**
1711
2820
  * User information extracted from OAuth provider
1712
2821
  *
@@ -1724,4 +2833,48 @@ export declare interface UserInfo {
1724
2833
  iss?: string | undefined;
1725
2834
  }
1726
2835
 
2836
+ /**
2837
+ * Thrown when a user account cannot be found for credential verification or password change.
2838
+ *
2839
+ * @public
2840
+ */
2841
+ export declare class UserNotFoundError extends LixaError {
2842
+ constructor(identifierOrId?: string, details?: Record<string, unknown>);
2843
+ }
2844
+
2845
+ /**
2846
+ * Validates a plaintext password against configured password policy rules.
2847
+ *
2848
+ * @param password - Plaintext password to evaluate
2849
+ * @param policy - Optional custom policy configuration
2850
+ * @returns PasswordPolicyResult containing boolean valid flag and error messages
2851
+ *
2852
+ * @public
2853
+ */
2854
+ export declare function validatePasswordPolicy(password: string, policy?: PasswordPolicyConfig): Promise<PasswordPolicyResult>;
2855
+
2856
+ /**
2857
+ * Parameters for raw credential verification without session creation.
2858
+ *
2859
+ * @public
2860
+ */
2861
+ export declare interface VerifyCredentialsParams {
2862
+ /** Username or email of the account */
2863
+ username?: string | undefined;
2864
+ /** Primary identifier (username or email) */
2865
+ identifier?: string | undefined;
2866
+ /** Plaintext password */
2867
+ password: string;
2868
+ }
2869
+
2870
+ /**
2871
+ * Thrown when a password does not satisfy configured password policy rules.
2872
+ *
2873
+ * @public
2874
+ */
2875
+ export declare class WeakPasswordError extends LixaError {
2876
+ readonly validationErrors: string[];
2877
+ constructor(validationErrors?: string[], details?: Record<string, unknown>);
2878
+ }
2879
+
1727
2880
  export { }