@prsm/auth 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +226 -0
  2. package/index.d.ts +19 -0
  3. package/package.json +76 -0
  4. package/src/__tests__/auth.test.js +1171 -0
  5. package/src/__tests__/impersonation-test-setup.js +208 -0
  6. package/src/__tests__/impersonation.test.js +473 -0
  7. package/src/__tests__/oauth-test-setup.js +136 -0
  8. package/src/__tests__/oauth.test.js +400 -0
  9. package/src/__tests__/prsm.test.js +215 -0
  10. package/src/__tests__/test-setup.js +385 -0
  11. package/src/__tests__/totp.test.js +158 -0
  12. package/src/__tests__/two-factor-test-setup.js +331 -0
  13. package/src/__tests__/two-factor.test.js +396 -0
  14. package/src/activity-logger.js +228 -0
  15. package/src/auth-context.js +120 -0
  16. package/src/auth-functions.js +520 -0
  17. package/src/auth-manager.js +1371 -0
  18. package/src/errors.js +173 -0
  19. package/src/hooks.js +41 -0
  20. package/src/index.js +23 -0
  21. package/src/invalidation.js +166 -0
  22. package/src/middleware.js +33 -0
  23. package/src/providers/azure-provider.js +114 -0
  24. package/src/providers/base-provider.js +152 -0
  25. package/src/providers/github-provider.js +86 -0
  26. package/src/providers/google-provider.js +76 -0
  27. package/src/providers/index.js +4 -0
  28. package/src/queries.js +543 -0
  29. package/src/schema.js +261 -0
  30. package/src/totp.js +221 -0
  31. package/src/two-factor/index.js +3 -0
  32. package/src/two-factor/otp-provider.js +128 -0
  33. package/src/two-factor/totp-provider.js +98 -0
  34. package/src/two-factor/two-factor-manager.js +676 -0
  35. package/src/types.js +399 -0
  36. package/src/user-roles.js +128 -0
  37. package/src/util.js +32 -0
  38. package/types/activity-logger.d.ts +73 -0
  39. package/types/auth-context.d.ts +88 -0
  40. package/types/auth-functions.d.ts +151 -0
  41. package/types/auth-manager.d.ts +365 -0
  42. package/types/errors.d.ts +108 -0
  43. package/types/hooks.d.ts +30 -0
  44. package/types/index.d.ts +13 -0
  45. package/types/invalidation.d.ts +40 -0
  46. package/types/middleware.d.ts +11 -0
  47. package/types/providers/azure-provider.d.ts +35 -0
  48. package/types/providers/base-provider.d.ts +52 -0
  49. package/types/providers/github-provider.d.ts +29 -0
  50. package/types/providers/google-provider.d.ts +29 -0
  51. package/types/providers/index.d.ts +4 -0
  52. package/types/queries.d.ts +287 -0
  53. package/types/schema.d.ts +37 -0
  54. package/types/totp.d.ts +72 -0
  55. package/types/two-factor/index.d.ts +3 -0
  56. package/types/two-factor/otp-provider.d.ts +57 -0
  57. package/types/two-factor/totp-provider.d.ts +58 -0
  58. package/types/two-factor/two-factor-manager.d.ts +191 -0
  59. package/types/types.d.ts +688 -0
  60. package/types/user-roles.d.ts +47 -0
  61. package/types/util.d.ts +3 -0
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Create a requestless auth context for scripts, workers, cron jobs, and admin
3
+ * tasks. The same object doubles as the binding surface for the @prsm/devtools
4
+ * admin panel: it exposes read methods (listAccounts, getAccount, getStats,
5
+ * recent activity, roles) and control actions (role/status/force-logout/etc),
6
+ * all duck-typed so devtools needs no @prsm/auth dependency.
7
+ * @param {AuthConfig} config
8
+ */
9
+ export function createAuthContext(config: AuthConfig): {
10
+ createUser: (credentials: any, userId: any, callback: any) => Promise<import("./types.js").AuthAccount>;
11
+ register: (email: any, password: any, userId: any, callback: any) => Promise<import("./types.js").AuthAccount>;
12
+ deleteUserBy: (identifier: any) => Promise<void>;
13
+ addRoleForUserBy: (identifier: any, role: any) => Promise<void>;
14
+ removeRoleForUserBy: (identifier: any, role: any) => Promise<void>;
15
+ hasRoleForUserBy: (identifier: any, role: any) => Promise<boolean>;
16
+ changePasswordForUserBy: (identifier: any, password: any) => Promise<void>;
17
+ setStatusForUserBy: (identifier: any, status: any) => Promise<void>;
18
+ initiatePasswordResetForUserBy: (identifier: any, expiresAfter: any, callback: any) => Promise<void>;
19
+ resetPassword: (email: any, expiresAfter: any, maxOpenRequests: any, callback: any) => Promise<void>;
20
+ confirmResetPassword: (token: any, password: any) => Promise<{
21
+ accountId: number;
22
+ email: string;
23
+ }>;
24
+ userExistsByEmail: (email: any) => Promise<boolean>;
25
+ forceLogoutForUserBy: (identifier: any) => Promise<{
26
+ accountId: number;
27
+ }>;
28
+ /**
29
+ * @param {{ limit?: number, offset?: number, search?: string }} [opts]
30
+ * @returns {Promise<{ accounts: AuthAccount[], total: number }>}
31
+ */
32
+ listAccounts(opts?: {
33
+ limit?: number;
34
+ offset?: number;
35
+ search?: string;
36
+ }): Promise<{
37
+ accounts: AuthAccount[];
38
+ total: number;
39
+ }>;
40
+ /**
41
+ * @param {UserIdentifier} identifier
42
+ * @returns {Promise<AuthAccount>}
43
+ */
44
+ getAccount(identifier: UserIdentifier): Promise<AuthAccount>;
45
+ /**
46
+ * @param {number} accountId
47
+ */
48
+ getProvidersForAccount: (accountId: number) => Promise<import("./types.js").AuthProvider[]>;
49
+ /**
50
+ * @param {number} accountId
51
+ */
52
+ getTwoFactorMethods: (accountId: number) => Promise<import("./types.js").TwoFactorMethod[]>;
53
+ /**
54
+ * The role name -> bit map devtools renders, defaulting to AuthRole.
55
+ * @returns {Record<string, number>}
56
+ */
57
+ getRoles: () => Record<string, number>;
58
+ /**
59
+ * The status code -> name map devtools renders for account status.
60
+ * @returns {Record<string, number>}
61
+ */
62
+ getStatuses: () => Record<string, number>;
63
+ /**
64
+ * The 2FA mechanism code -> name map devtools renders.
65
+ * @returns {Record<string, number>}
66
+ */
67
+ getMechanisms: () => Record<string, number>;
68
+ /**
69
+ * @returns {Promise<ReturnType<typeof import("./schema.js").getAuthTableStats>>}
70
+ */
71
+ getStats: () => Promise<ReturnType<typeof import("./schema.js").getAuthTableStats>>;
72
+ /**
73
+ * @param {number} [limit]
74
+ * @param {number} [accountId]
75
+ */
76
+ getRecentActivity: (limit?: number, accountId?: number) => Promise<import("./types.js").AuthActivity[]>;
77
+ getActivityStats: () => Promise<{
78
+ totalEntries: number;
79
+ uniqueUsers: number;
80
+ recentLogins: number;
81
+ failedAttempts: number;
82
+ }>;
83
+ };
84
+ export type AuthConfig = import("./types.js").AuthConfig;
85
+ export type TokenCallback = import("./types.js").TokenCallback;
86
+ export type AuthAccount = import("./types.js").AuthAccount;
87
+ export type UserIdentifier = import("./types.js").UserIdentifier;
88
+ export type AuthContext = ReturnType<typeof createAuthContext>;
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Resolve the account for an incoming request via session or remember-me cookie.
3
+ * @param {AuthConfig} config
4
+ * @param {import("http").IncomingMessage} req
5
+ * @param {(req: any, res: any, next: () => void) => void} [sessionMiddleware]
6
+ * @returns {Promise<AuthenticateRequestResult>}
7
+ */
8
+ export function authenticateRequest(config: AuthConfig, req: import("http").IncomingMessage, sessionMiddleware?: (req: any, res: any, next: () => void) => void): Promise<AuthenticateRequestResult>;
9
+ /**
10
+ * Create a new local account. When a callback is provided the account starts
11
+ * unverified and a confirmation token is generated.
12
+ * @param {AuthConfig} config
13
+ * @param {{ email: string, password: string }} credentials
14
+ * @param {string | number} [userId]
15
+ * @param {TokenCallback} [callback]
16
+ * @returns {Promise<AuthAccount>}
17
+ * @throws {EmailTakenError}
18
+ */
19
+ export function createUser(config: AuthConfig, credentials: {
20
+ email: string;
21
+ password: string;
22
+ }, userId?: string | number, callback?: TokenCallback): Promise<AuthAccount>;
23
+ /**
24
+ * Register a new local account. When a callback is provided the account starts
25
+ * unverified and a confirmation token is generated.
26
+ * @param {AuthConfig} config
27
+ * @param {string} email
28
+ * @param {string} password
29
+ * @param {string | number} [userId]
30
+ * @param {TokenCallback} [callback]
31
+ * @returns {Promise<AuthAccount>}
32
+ * @throws {EmailTakenError}
33
+ */
34
+ export function register(config: AuthConfig, email: string, password: string, userId?: string | number, callback?: TokenCallback): Promise<AuthAccount>;
35
+ /**
36
+ * Delete the account matched by the identifier.
37
+ * @param {AuthConfig} config
38
+ * @param {UserIdentifier} identifier
39
+ * @returns {Promise<void>}
40
+ * @throws {UserNotFoundError}
41
+ */
42
+ export function deleteUserBy(config: AuthConfig, identifier: UserIdentifier): Promise<void>;
43
+ /**
44
+ * Add a role bit to the account's rolemask.
45
+ * @param {AuthConfig} config
46
+ * @param {UserIdentifier} identifier
47
+ * @param {number} role
48
+ * @returns {Promise<void>}
49
+ * @throws {UserNotFoundError}
50
+ */
51
+ export function addRoleForUserBy(config: AuthConfig, identifier: UserIdentifier, role: number): Promise<void>;
52
+ /**
53
+ * Remove a role bit from the account's rolemask.
54
+ * @param {AuthConfig} config
55
+ * @param {UserIdentifier} identifier
56
+ * @param {number} role
57
+ * @returns {Promise<void>}
58
+ * @throws {UserNotFoundError}
59
+ */
60
+ export function removeRoleForUserBy(config: AuthConfig, identifier: UserIdentifier, role: number): Promise<void>;
61
+ /**
62
+ * Check whether the account has every bit in the given role mask.
63
+ * @param {AuthConfig} config
64
+ * @param {UserIdentifier} identifier
65
+ * @param {number} role
66
+ * @returns {Promise<boolean>}
67
+ * @throws {UserNotFoundError}
68
+ */
69
+ export function hasRoleForUserBy(config: AuthConfig, identifier: UserIdentifier, role: number): Promise<boolean>;
70
+ /**
71
+ * Change the password for the account matched by the identifier.
72
+ * @param {AuthConfig} config
73
+ * @param {UserIdentifier} identifier
74
+ * @param {string} password
75
+ * @returns {Promise<void>}
76
+ * @throws {UserNotFoundError}
77
+ * @throws {InvalidPasswordError}
78
+ */
79
+ export function changePasswordForUserBy(config: AuthConfig, identifier: UserIdentifier, password: string): Promise<void>;
80
+ /**
81
+ * Set the status code for the account matched by the identifier.
82
+ * @param {AuthConfig} config
83
+ * @param {UserIdentifier} identifier
84
+ * @param {number} status
85
+ * @returns {Promise<void>}
86
+ * @throws {UserNotFoundError}
87
+ */
88
+ export function setStatusForUserBy(config: AuthConfig, identifier: UserIdentifier, status: number): Promise<void>;
89
+ /**
90
+ * Create a password reset token for the account matched by the identifier.
91
+ * @param {AuthConfig} config
92
+ * @param {UserIdentifier} identifier
93
+ * @param {string | number | null} [expiresAfter]
94
+ * @param {TokenCallback} [callback]
95
+ * @returns {Promise<void>}
96
+ * @throws {UserNotFoundError}
97
+ * @throws {EmailNotVerifiedError}
98
+ */
99
+ export function initiatePasswordResetForUserBy(config: AuthConfig, identifier: UserIdentifier, expiresAfter?: string | number | null, callback?: TokenCallback): Promise<void>;
100
+ /**
101
+ * Request a password reset by email, subject to the open-request limit.
102
+ * @param {AuthConfig} config
103
+ * @param {string} email
104
+ * @param {string | number | null} [expiresAfter]
105
+ * @param {number | null} [maxOpenRequests]
106
+ * @param {TokenCallback} [callback]
107
+ * @returns {Promise<void>}
108
+ * @throws {EmailNotVerifiedError}
109
+ * @throws {ResetDisabledError}
110
+ * @throws {TooManyResetsError}
111
+ */
112
+ export function resetPassword(config: AuthConfig, email: string, expiresAfter?: string | number | null, maxOpenRequests?: number | null, callback?: TokenCallback): Promise<void>;
113
+ /**
114
+ * Confirm a password reset token and apply the new password.
115
+ * @param {AuthConfig} config
116
+ * @param {string} token
117
+ * @param {string} password
118
+ * @returns {Promise<{ accountId: number, email: string }>}
119
+ * @throws {ResetNotFoundError}
120
+ * @throws {ResetExpiredError}
121
+ * @throws {UserNotFoundError}
122
+ * @throws {ResetDisabledError}
123
+ * @throws {InvalidPasswordError}
124
+ * @throws {InvalidTokenError}
125
+ */
126
+ export function confirmResetPassword(config: AuthConfig, token: string, password: string): Promise<{
127
+ accountId: number;
128
+ email: string;
129
+ }>;
130
+ /**
131
+ * Check whether an account exists for the given email.
132
+ * @param {AuthConfig} config
133
+ * @param {string} email
134
+ * @returns {Promise<boolean>}
135
+ */
136
+ export function userExistsByEmail(config: AuthConfig, email: string): Promise<boolean>;
137
+ /**
138
+ * Force logout of all sessions for the account matched by the identifier.
139
+ * @param {AuthConfig} config
140
+ * @param {UserIdentifier} identifier
141
+ * @returns {Promise<{ accountId: number }>}
142
+ * @throws {UserNotFoundError}
143
+ */
144
+ export function forceLogoutForUserBy(config: AuthConfig, identifier: UserIdentifier): Promise<{
145
+ accountId: number;
146
+ }>;
147
+ export type AuthConfig = import("./types.js").AuthConfig;
148
+ export type AuthAccount = import("./types.js").AuthAccount;
149
+ export type TokenCallback = import("./types.js").TokenCallback;
150
+ export type UserIdentifier = import("./types.js").UserIdentifier;
151
+ export type AuthenticateRequestResult = import("./types.js").AuthenticateRequestResult;
@@ -0,0 +1,365 @@
1
+ /**
2
+ * @typedef {import("./types.js").AuthConfig} AuthConfig
3
+ * @typedef {import("./types.js").AuthAccount} AuthAccount
4
+ * @typedef {import("./types.js").AuthSession} AuthSession
5
+ * @typedef {import("./types.js").TokenCallback} TokenCallback
6
+ * @typedef {import("./types.js").OAuthProvider} OAuthProvider
7
+ * @typedef {import("./types.js").StartImpersonationOptions} StartImpersonationOptions
8
+ * @typedef {import("./types.js").ImpersonationInfo} ImpersonationInfo
9
+ * @typedef {import("./types.js").ImpersonationActor} ImpersonationActor
10
+ * @typedef {import("./types.js").UserIdentifier} UserIdentifier
11
+ */
12
+ export class AuthManager {
13
+ /**
14
+ * @param {import("express").Request} req
15
+ * @param {import("express").Response} res
16
+ * @param {AuthConfig} config
17
+ */
18
+ constructor(req: import("express").Request, res: import("express").Response, config: AuthConfig);
19
+ req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
20
+ res: import("express").Response<any, Record<string, any>>;
21
+ config: import("./types.js").AuthConfig;
22
+ queries: AuthQueries;
23
+ activityLogger: ActivityLogger;
24
+ providers: {
25
+ github: GitHubProvider;
26
+ google: GoogleProvider;
27
+ azure: AzureProvider;
28
+ };
29
+ twoFactor: TwoFactorManager;
30
+ initializeProviders(): {
31
+ github: GitHubProvider;
32
+ google: GoogleProvider;
33
+ azure: AzureProvider;
34
+ };
35
+ generateAutoUserId(): `${string}-${string}-${string}-${string}-${string}`;
36
+ shouldRequire2FA(account: any): Promise<boolean>;
37
+ validatePassword(password: any): void;
38
+ getRoleMap(): Record<number, string>;
39
+ getStatusMap(): Record<number, string>;
40
+ getAuthAccount(): Promise<import("./types.js").AuthAccount>;
41
+ setRememberCookie(token: any, expires: any): void;
42
+ getRememberToken(): {
43
+ token: any;
44
+ };
45
+ regenerateSession(): Promise<any>;
46
+ /**
47
+ * Resync the current session against the persisted account state.
48
+ * @param {boolean} [force=false]
49
+ * @returns {Promise<void>}
50
+ */
51
+ resyncSession(force?: boolean): Promise<void>;
52
+ /**
53
+ * Restore a session from a valid remember token when not already logged in.
54
+ * @returns {Promise<void>}
55
+ */
56
+ processRememberDirective(): Promise<void>;
57
+ onLoginSuccessful(account: any, remember?: boolean): Promise<any>;
58
+ createRememberDirective(account: any): Promise<string>;
59
+ /**
60
+ * Check if the current user is logged in.
61
+ * @returns {boolean} true if user has an active authenticated session
62
+ */
63
+ isLoggedIn(): boolean;
64
+ /**
65
+ * Authenticate user with email and password, creating a session.
66
+ * @param {string} email
67
+ * @param {string} password
68
+ * @param {boolean} [remember=false]
69
+ * @returns {Promise<void>}
70
+ * @throws {UserNotFoundError} Account with this email doesn't exist
71
+ * @throws {InvalidPasswordError} Password is incorrect
72
+ * @throws {EmailNotVerifiedError} Account exists but email is not verified
73
+ * @throws {UserInactiveError} Account is banned, locked, or otherwise inactive
74
+ * @throws {SecondFactorRequiredError} Two-factor authentication is required
75
+ */
76
+ login(email: string, password: string, remember?: boolean): Promise<void>;
77
+ /**
78
+ * Complete two-factor authentication and log in the user.
79
+ * @returns {Promise<void>}
80
+ * @throws {TwoFactorExpiredError} No pending 2FA state or it has expired
81
+ * @throws {UserNotFoundError} Associated account no longer exists
82
+ */
83
+ completeTwoFactorLogin(): Promise<void>;
84
+ /**
85
+ * Log out the current user, clearing the session and remember tokens.
86
+ * @returns {Promise<void>}
87
+ */
88
+ logout(): Promise<void>;
89
+ /**
90
+ * Register a new account.
91
+ * @param {string} email
92
+ * @param {string} password
93
+ * @param {string|number} [userId] Optional user ID to link; a UUID is generated if omitted
94
+ * @param {TokenCallback} [callback] If provided, account is created unverified and callback receives the confirmation token
95
+ * @returns {Promise<AuthAccount>} The created account record
96
+ * @throws {EmailTakenError} Email is already registered
97
+ * @throws {InvalidPasswordError} Password doesn't meet length requirements
98
+ */
99
+ register(email: string, password: string, userId?: string | number, callback?: TokenCallback): Promise<AuthAccount>;
100
+ createConfirmationToken(account: any, email: any, callback: any): Promise<void>;
101
+ /**
102
+ * Get the current user's account ID.
103
+ * @returns {number|null} Account ID if logged in, null otherwise
104
+ */
105
+ getId(): number | null;
106
+ /**
107
+ * Get the current user's email address.
108
+ * @returns {string|null} Email if logged in, null otherwise
109
+ */
110
+ getEmail(): string | null;
111
+ /**
112
+ * Get the current user's account status.
113
+ * @returns {number|null} Status number if logged in, null otherwise
114
+ */
115
+ getStatus(): number | null;
116
+ /**
117
+ * Check if the current user's email is verified.
118
+ * @returns {boolean|null} true if verified, false if unverified, null if not logged in
119
+ */
120
+ getVerified(): boolean | null;
121
+ /**
122
+ * Check if the current user has a password set.
123
+ * @returns {boolean|null} true if user has a password, false if OAuth-only, null if not logged in
124
+ */
125
+ hasPassword(): boolean | null;
126
+ /**
127
+ * Get human-readable role names for the current user or a specific rolemask.
128
+ * @param {number} [rolemask] Optional rolemask; defaults to the current user's roles
129
+ * @returns {string[]} Array of role names
130
+ */
131
+ getRoleNames(rolemask?: number): string[];
132
+ /**
133
+ * Get the human-readable status name for the current user.
134
+ * @returns {string|null} Status name if logged in, null otherwise
135
+ */
136
+ getStatusName(): string | null;
137
+ /**
138
+ * Check if the current user has a specific role.
139
+ * @param {number} role Role bitmask to check
140
+ * @returns {Promise<boolean>} true if user has the role, false otherwise
141
+ */
142
+ hasRole(role: number): Promise<boolean>;
143
+ /**
144
+ * Check if the current user has admin privileges.
145
+ * @returns {Promise<boolean>} true if user has Admin role, false otherwise
146
+ */
147
+ isAdmin(): Promise<boolean>;
148
+ /**
149
+ * Check if the current user was automatically logged in via remember token.
150
+ * @returns {boolean} true if auto-logged in from a persistent cookie, false otherwise
151
+ */
152
+ isRemembered(): boolean;
153
+ /**
154
+ * Request an email change for the current user, sending a confirmation token.
155
+ * @param {string} newEmail
156
+ * @param {TokenCallback} callback Called with the confirmation token
157
+ * @returns {Promise<void>}
158
+ * @throws {UserNotLoggedInError} User is not logged in
159
+ * @throws {EmailTakenError} New email is already registered
160
+ * @throws {UserNotFoundError} Current user account not found
161
+ * @throws {EmailNotVerifiedError} Current account's email is not verified
162
+ */
163
+ changeEmail(newEmail: string, callback: TokenCallback): Promise<void>;
164
+ /**
165
+ * Confirm an email address using a token from registration or email change.
166
+ * @param {string} token
167
+ * @returns {Promise<string>} The confirmed email address
168
+ * @throws {ConfirmationNotFoundError} Token is invalid or doesn't exist
169
+ * @throws {ConfirmationExpiredError} Token has expired
170
+ * @throws {InvalidTokenError} Token format is invalid
171
+ */
172
+ confirmEmail(token: string): Promise<string>;
173
+ /**
174
+ * Confirm an email address and automatically log in the user.
175
+ * @param {string} token
176
+ * @param {boolean} [remember=false]
177
+ * @returns {Promise<void>}
178
+ * @throws {ConfirmationNotFoundError} Token is invalid or doesn't exist
179
+ * @throws {ConfirmationExpiredError} Token has expired
180
+ * @throws {InvalidTokenError} Token format is invalid
181
+ * @throws {UserNotFoundError} Associated account no longer exists
182
+ * @throws {SecondFactorRequiredError} Two-factor authentication is required
183
+ */
184
+ confirmEmailAndLogin(token: string, remember?: boolean): Promise<void>;
185
+ /**
186
+ * Initiate a password reset for a user, creating a reset token.
187
+ * @param {string} email
188
+ * @param {string|number|null} [expiresAfter=null] Token expiration (default 6h)
189
+ * @param {number|null} [maxOpenRequests=null] Maximum concurrent reset tokens (default 2)
190
+ * @param {TokenCallback} [callback] Called with the reset token
191
+ * @returns {Promise<void>}
192
+ * @throws {EmailNotVerifiedError} Account doesn't exist or email not verified
193
+ * @throws {ResetDisabledError} Account has password reset disabled
194
+ * @throws {TooManyResetsError} Too many active reset requests
195
+ */
196
+ resetPassword(email: string, expiresAfter?: string | number | null, maxOpenRequests?: number | null, callback?: TokenCallback): Promise<void>;
197
+ /**
198
+ * Complete a password reset using a reset token.
199
+ * @param {string} token
200
+ * @param {string} password New password (will be hashed)
201
+ * @param {boolean} [logout=true] Whether to force logout all sessions
202
+ * @returns {Promise<void>}
203
+ * @throws {ResetNotFoundError} Token is invalid or doesn't exist
204
+ * @throws {ResetExpiredError} Token has expired
205
+ * @throws {UserNotFoundError} Associated account no longer exists
206
+ * @throws {ResetDisabledError} Account has password reset disabled
207
+ * @throws {InvalidPasswordError} New password doesn't meet requirements
208
+ * @throws {InvalidTokenError} Token format is invalid
209
+ */
210
+ confirmResetPassword(token: string, password: string, logout?: boolean): Promise<void>;
211
+ /**
212
+ * Verify if a password matches the current user's password.
213
+ * @param {string} password
214
+ * @returns {Promise<boolean>} true if password matches, false otherwise
215
+ * @throws {UserNotLoggedInError} User is not logged in
216
+ * @throws {UserNotFoundError} Current user account not found
217
+ */
218
+ verifyPassword(password: string): Promise<boolean>;
219
+ forceLogoutForAccountById(accountId: any): Promise<void>;
220
+ /**
221
+ * Force logout all other sessions while keeping the current one active.
222
+ * @returns {Promise<void>}
223
+ */
224
+ logoutEverywhereElse(): Promise<void>;
225
+ /**
226
+ * Force logout all sessions including the current one.
227
+ * @returns {Promise<void>}
228
+ */
229
+ logoutEverywhere(): Promise<void>;
230
+ findAccountByIdentifier(identifier: any): Promise<import("./types.js").AuthAccount>;
231
+ /**
232
+ * Create a user account (admin function).
233
+ * @param {{ email: string, password: string }} credentials
234
+ * @param {string|number} [userId]
235
+ * @param {TokenCallback} [callback]
236
+ * @returns {Promise<AuthAccount>}
237
+ */
238
+ createUser(credentials: {
239
+ email: string;
240
+ password: string;
241
+ }, userId?: string | number, callback?: TokenCallback): Promise<AuthAccount>;
242
+ /**
243
+ * Delete a user account by identifier (admin function).
244
+ * @param {UserIdentifier} identifier
245
+ * @returns {Promise<void>}
246
+ */
247
+ deleteUserBy(identifier: UserIdentifier): Promise<void>;
248
+ /**
249
+ * Add a role for a user by identifier (admin function).
250
+ * @param {UserIdentifier} identifier
251
+ * @param {number} role
252
+ * @returns {Promise<void>}
253
+ */
254
+ addRoleForUserBy(identifier: UserIdentifier, role: number): Promise<void>;
255
+ /**
256
+ * Remove a role for a user by identifier (admin function).
257
+ * @param {UserIdentifier} identifier
258
+ * @param {number} role
259
+ * @returns {Promise<void>}
260
+ */
261
+ removeRoleForUserBy(identifier: UserIdentifier, role: number): Promise<void>;
262
+ /**
263
+ * Check whether a user has a role by identifier (admin function).
264
+ * @param {UserIdentifier} identifier
265
+ * @param {number} role
266
+ * @returns {Promise<boolean>}
267
+ */
268
+ hasRoleForUserBy(identifier: UserIdentifier, role: number): Promise<boolean>;
269
+ /**
270
+ * Change a user's password by identifier (admin function).
271
+ * @param {UserIdentifier} identifier
272
+ * @param {string} password
273
+ * @returns {Promise<void>}
274
+ */
275
+ changePasswordForUserBy(identifier: UserIdentifier, password: string): Promise<void>;
276
+ /**
277
+ * Set a user's status by identifier (admin function).
278
+ * @param {UserIdentifier} identifier
279
+ * @param {number} status
280
+ * @returns {Promise<void>}
281
+ */
282
+ setStatusForUserBy(identifier: UserIdentifier, status: number): Promise<void>;
283
+ /**
284
+ * Initiate a password reset for a user by identifier (admin function).
285
+ * @param {UserIdentifier} identifier
286
+ * @param {string|number|null} [expiresAfter]
287
+ * @param {TokenCallback} [callback]
288
+ * @returns {Promise<void>}
289
+ */
290
+ initiatePasswordResetForUserBy(identifier: UserIdentifier, expiresAfter?: string | number | null, callback?: TokenCallback): Promise<void>;
291
+ /**
292
+ * Check whether a user exists by email (admin function).
293
+ * @param {string} email
294
+ * @returns {Promise<boolean>}
295
+ */
296
+ userExistsByEmail(email: string): Promise<boolean>;
297
+ /**
298
+ * Force logout a user by identifier; flags the current session if it is owned by that user.
299
+ * @param {UserIdentifier} identifier
300
+ * @returns {Promise<void>}
301
+ */
302
+ forceLogoutForUserBy(identifier: UserIdentifier): Promise<void>;
303
+ /**
304
+ * Log in as another user (admin function), replacing the current session.
305
+ * @param {UserIdentifier} identifier
306
+ * @returns {Promise<void>}
307
+ * @throws {UserNotFoundError} No account matches the identifier
308
+ */
309
+ loginAsUserBy(identifier: UserIdentifier): Promise<void>;
310
+ /**
311
+ * Check whether the current session is impersonating another user.
312
+ * @returns {boolean}
313
+ */
314
+ isImpersonating(): boolean;
315
+ /**
316
+ * Get the account id of the original (actor) user when impersonating.
317
+ * @returns {number|null} Actor account id when impersonating, null otherwise
318
+ */
319
+ getActorId(): number | null;
320
+ /**
321
+ * Get the email of the original (actor) user when impersonating.
322
+ * @returns {string|null} Actor email when impersonating, null otherwise
323
+ */
324
+ getActorEmail(): string | null;
325
+ /**
326
+ * Get a structured summary of the current impersonation session.
327
+ * @returns {ImpersonationInfo|null} ImpersonationInfo when impersonating, null otherwise
328
+ */
329
+ getImpersonationInfo(): ImpersonationInfo | null;
330
+ /**
331
+ * Begin impersonating another user while preserving the actor identity.
332
+ * @param {UserIdentifier} identifier
333
+ * @param {StartImpersonationOptions} [options={}]
334
+ * @returns {Promise<void>}
335
+ * @throws {UserNotLoggedInError} No active session
336
+ * @throws {ImpersonationDisabledError} config.impersonation.enabled is false
337
+ * @throws {AlreadyImpersonatingError} Another impersonation session is already active
338
+ * @throws {UserNotFoundError} No account matches the identifier
339
+ * @throws {ImpersonationNotAllowedError} canImpersonate returned false, or target is the actor
340
+ */
341
+ startImpersonation(identifier: UserIdentifier, options?: StartImpersonationOptions): Promise<void>;
342
+ /**
343
+ * Stop the current impersonation session and revert to the actor's identity.
344
+ * @returns {Promise<void>}
345
+ * @throws {NotImpersonatingError} No active impersonation session
346
+ */
347
+ stopImpersonation(): Promise<void>;
348
+ stopImpersonationInternal(cause: any): Promise<void>;
349
+ regenerateSessionWith(newAuth: any): Promise<any>;
350
+ }
351
+ export type AuthConfig = import("./types.js").AuthConfig;
352
+ export type AuthAccount = import("./types.js").AuthAccount;
353
+ export type AuthSession = import("./types.js").AuthSession;
354
+ export type TokenCallback = import("./types.js").TokenCallback;
355
+ export type OAuthProvider = import("./types.js").OAuthProvider;
356
+ export type StartImpersonationOptions = import("./types.js").StartImpersonationOptions;
357
+ export type ImpersonationInfo = import("./types.js").ImpersonationInfo;
358
+ export type ImpersonationActor = import("./types.js").ImpersonationActor;
359
+ export type UserIdentifier = import("./types.js").UserIdentifier;
360
+ import { AuthQueries } from "./queries.js";
361
+ import { ActivityLogger } from "./activity-logger.js";
362
+ import { GitHubProvider } from "./providers/index.js";
363
+ import { GoogleProvider } from "./providers/index.js";
364
+ import { AzureProvider } from "./providers/index.js";
365
+ import { TwoFactorManager } from "./two-factor/index.js";