@eaccess/auth 0.1.2 → 0.1.3
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.cjs +46 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -1
- package/dist/index.d.ts +45 -1
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -548,6 +548,50 @@ declare function createUser(config: AuthConfig, credentials: {
|
|
|
548
548
|
password: string;
|
|
549
549
|
}, userId?: string | number, callback?: TokenCallback): Promise<AuthAccount>;
|
|
550
550
|
|
|
551
|
+
type UserIdentifier = {
|
|
552
|
+
accountId?: number;
|
|
553
|
+
email?: string;
|
|
554
|
+
userId?: string;
|
|
555
|
+
};
|
|
556
|
+
/**
|
|
557
|
+
* Add a role to a user's account.
|
|
558
|
+
* Uses bitwise OR to add role to existing rolemask.
|
|
559
|
+
*
|
|
560
|
+
* @param config - Auth configuration containing database connection
|
|
561
|
+
* @param identifier - Find user by accountId, email, or userId
|
|
562
|
+
* @param role - Role bitmask to add (e.g., AuthRole.Admin)
|
|
563
|
+
* @throws {UserNotFoundError} No account matches the identifier
|
|
564
|
+
*/
|
|
565
|
+
declare function addRoleToUser(config: AuthConfig, identifier: UserIdentifier, role: number): Promise<void>;
|
|
566
|
+
/**
|
|
567
|
+
* Remove a role from a user's account.
|
|
568
|
+
* Uses bitwise operations to remove role from rolemask.
|
|
569
|
+
*
|
|
570
|
+
* @param config - Auth configuration containing database connection
|
|
571
|
+
* @param identifier - Find user by accountId, email, or userId
|
|
572
|
+
* @param role - Role bitmask to remove (e.g., AuthRole.Admin)
|
|
573
|
+
* @throws {UserNotFoundError} No account matches the identifier
|
|
574
|
+
*/
|
|
575
|
+
declare function removeRoleFromUser(config: AuthConfig, identifier: UserIdentifier, role: number): Promise<void>;
|
|
576
|
+
/**
|
|
577
|
+
* Set a user's complete role mask, replacing any existing roles.
|
|
578
|
+
*
|
|
579
|
+
* @param config - Auth configuration containing database connection
|
|
580
|
+
* @param identifier - Find user by accountId, email, or userId
|
|
581
|
+
* @param rolemask - Complete role bitmask to set
|
|
582
|
+
* @throws {UserNotFoundError} No account matches the identifier
|
|
583
|
+
*/
|
|
584
|
+
declare function setUserRoles(config: AuthConfig, identifier: UserIdentifier, rolemask: number): Promise<void>;
|
|
585
|
+
/**
|
|
586
|
+
* Get a user's current role mask.
|
|
587
|
+
*
|
|
588
|
+
* @param config - Auth configuration containing database connection
|
|
589
|
+
* @param identifier - Find user by accountId, email, or userId
|
|
590
|
+
* @returns The user's current role bitmask
|
|
591
|
+
* @throws {UserNotFoundError} No account matches the identifier
|
|
592
|
+
*/
|
|
593
|
+
declare function getUserRoles(config: AuthConfig, identifier: UserIdentifier): Promise<number>;
|
|
594
|
+
|
|
551
595
|
declare class AuthError extends Error {
|
|
552
596
|
constructor(message: string);
|
|
553
597
|
}
|
|
@@ -962,4 +1006,4 @@ declare class AzureProvider extends BaseOAuthProvider {
|
|
|
962
1006
|
protected exchangeCodeForToken(code: string, tokenUrl: string): Promise<string>;
|
|
963
1007
|
}
|
|
964
1008
|
|
|
965
|
-
export { ActivityLogger, type AuthAccount, type AuthActivity, AuthActivityAction, type AuthActivityActionType, type AuthAdminManager, type AuthConfig, type AuthConfirmation, AuthError, type AuthManager$1 as AuthManager, type AuthProvider, type AuthRemember, type AuthReset, AuthRole, type AuthSession, AuthStatus, AzureProvider, type AzureProviderConfig, BaseOAuthProvider, ConfirmationExpiredError, ConfirmationNotFoundError, EmailNotVerifiedError, EmailTakenError, GitHubProvider, type GitHubProviderConfig, GoogleProvider, type GoogleProviderConfig, InvalidBackupCodeError, InvalidEmailError, InvalidPasswordError, InvalidTokenError, InvalidTwoFactorCodeError, type OAuthProvider, type OAuthProviderConfig, type OAuthUserData, OtpProvider, ResetDisabledError, ResetExpiredError, ResetNotFoundError, SecondFactorRequiredError, type TokenCallback, TooManyResetsError, TotpProvider, TwoFactorAlreadyEnabledError, type TwoFactorChallenge, TwoFactorExpiredError, TwoFactorManager, TwoFactorMechanism, type TwoFactorMethod, TwoFactorNotSetupError, TwoFactorSetupIncompleteError, type TwoFactorSetupResult, type TwoFactorToken, UserInactiveError, UserNotFoundError, UserNotLoggedInError, cleanupExpiredTokens, createAuthMiddleware, createAuthTables, createUser, dropAuthTables, getAuthTableStats, isValidEmail, validateEmail };
|
|
1009
|
+
export { ActivityLogger, type AuthAccount, type AuthActivity, AuthActivityAction, type AuthActivityActionType, type AuthAdminManager, type AuthConfig, type AuthConfirmation, AuthError, type AuthManager$1 as AuthManager, type AuthProvider, type AuthRemember, type AuthReset, AuthRole, type AuthSession, AuthStatus, AzureProvider, type AzureProviderConfig, BaseOAuthProvider, ConfirmationExpiredError, ConfirmationNotFoundError, EmailNotVerifiedError, EmailTakenError, GitHubProvider, type GitHubProviderConfig, GoogleProvider, type GoogleProviderConfig, InvalidBackupCodeError, InvalidEmailError, InvalidPasswordError, InvalidTokenError, InvalidTwoFactorCodeError, type OAuthProvider, type OAuthProviderConfig, type OAuthUserData, OtpProvider, ResetDisabledError, ResetExpiredError, ResetNotFoundError, SecondFactorRequiredError, type TokenCallback, TooManyResetsError, TotpProvider, TwoFactorAlreadyEnabledError, type TwoFactorChallenge, TwoFactorExpiredError, TwoFactorManager, TwoFactorMechanism, type TwoFactorMethod, TwoFactorNotSetupError, TwoFactorSetupIncompleteError, type TwoFactorSetupResult, type TwoFactorToken, type UserIdentifier, UserInactiveError, UserNotFoundError, UserNotLoggedInError, addRoleToUser, cleanupExpiredTokens, createAuthMiddleware, createAuthTables, createUser, dropAuthTables, getAuthTableStats, getUserRoles, isValidEmail, removeRoleFromUser, setUserRoles, validateEmail };
|
package/dist/index.d.ts
CHANGED
|
@@ -548,6 +548,50 @@ declare function createUser(config: AuthConfig, credentials: {
|
|
|
548
548
|
password: string;
|
|
549
549
|
}, userId?: string | number, callback?: TokenCallback): Promise<AuthAccount>;
|
|
550
550
|
|
|
551
|
+
type UserIdentifier = {
|
|
552
|
+
accountId?: number;
|
|
553
|
+
email?: string;
|
|
554
|
+
userId?: string;
|
|
555
|
+
};
|
|
556
|
+
/**
|
|
557
|
+
* Add a role to a user's account.
|
|
558
|
+
* Uses bitwise OR to add role to existing rolemask.
|
|
559
|
+
*
|
|
560
|
+
* @param config - Auth configuration containing database connection
|
|
561
|
+
* @param identifier - Find user by accountId, email, or userId
|
|
562
|
+
* @param role - Role bitmask to add (e.g., AuthRole.Admin)
|
|
563
|
+
* @throws {UserNotFoundError} No account matches the identifier
|
|
564
|
+
*/
|
|
565
|
+
declare function addRoleToUser(config: AuthConfig, identifier: UserIdentifier, role: number): Promise<void>;
|
|
566
|
+
/**
|
|
567
|
+
* Remove a role from a user's account.
|
|
568
|
+
* Uses bitwise operations to remove role from rolemask.
|
|
569
|
+
*
|
|
570
|
+
* @param config - Auth configuration containing database connection
|
|
571
|
+
* @param identifier - Find user by accountId, email, or userId
|
|
572
|
+
* @param role - Role bitmask to remove (e.g., AuthRole.Admin)
|
|
573
|
+
* @throws {UserNotFoundError} No account matches the identifier
|
|
574
|
+
*/
|
|
575
|
+
declare function removeRoleFromUser(config: AuthConfig, identifier: UserIdentifier, role: number): Promise<void>;
|
|
576
|
+
/**
|
|
577
|
+
* Set a user's complete role mask, replacing any existing roles.
|
|
578
|
+
*
|
|
579
|
+
* @param config - Auth configuration containing database connection
|
|
580
|
+
* @param identifier - Find user by accountId, email, or userId
|
|
581
|
+
* @param rolemask - Complete role bitmask to set
|
|
582
|
+
* @throws {UserNotFoundError} No account matches the identifier
|
|
583
|
+
*/
|
|
584
|
+
declare function setUserRoles(config: AuthConfig, identifier: UserIdentifier, rolemask: number): Promise<void>;
|
|
585
|
+
/**
|
|
586
|
+
* Get a user's current role mask.
|
|
587
|
+
*
|
|
588
|
+
* @param config - Auth configuration containing database connection
|
|
589
|
+
* @param identifier - Find user by accountId, email, or userId
|
|
590
|
+
* @returns The user's current role bitmask
|
|
591
|
+
* @throws {UserNotFoundError} No account matches the identifier
|
|
592
|
+
*/
|
|
593
|
+
declare function getUserRoles(config: AuthConfig, identifier: UserIdentifier): Promise<number>;
|
|
594
|
+
|
|
551
595
|
declare class AuthError extends Error {
|
|
552
596
|
constructor(message: string);
|
|
553
597
|
}
|
|
@@ -962,4 +1006,4 @@ declare class AzureProvider extends BaseOAuthProvider {
|
|
|
962
1006
|
protected exchangeCodeForToken(code: string, tokenUrl: string): Promise<string>;
|
|
963
1007
|
}
|
|
964
1008
|
|
|
965
|
-
export { ActivityLogger, type AuthAccount, type AuthActivity, AuthActivityAction, type AuthActivityActionType, type AuthAdminManager, type AuthConfig, type AuthConfirmation, AuthError, type AuthManager$1 as AuthManager, type AuthProvider, type AuthRemember, type AuthReset, AuthRole, type AuthSession, AuthStatus, AzureProvider, type AzureProviderConfig, BaseOAuthProvider, ConfirmationExpiredError, ConfirmationNotFoundError, EmailNotVerifiedError, EmailTakenError, GitHubProvider, type GitHubProviderConfig, GoogleProvider, type GoogleProviderConfig, InvalidBackupCodeError, InvalidEmailError, InvalidPasswordError, InvalidTokenError, InvalidTwoFactorCodeError, type OAuthProvider, type OAuthProviderConfig, type OAuthUserData, OtpProvider, ResetDisabledError, ResetExpiredError, ResetNotFoundError, SecondFactorRequiredError, type TokenCallback, TooManyResetsError, TotpProvider, TwoFactorAlreadyEnabledError, type TwoFactorChallenge, TwoFactorExpiredError, TwoFactorManager, TwoFactorMechanism, type TwoFactorMethod, TwoFactorNotSetupError, TwoFactorSetupIncompleteError, type TwoFactorSetupResult, type TwoFactorToken, UserInactiveError, UserNotFoundError, UserNotLoggedInError, cleanupExpiredTokens, createAuthMiddleware, createAuthTables, createUser, dropAuthTables, getAuthTableStats, isValidEmail, validateEmail };
|
|
1009
|
+
export { ActivityLogger, type AuthAccount, type AuthActivity, AuthActivityAction, type AuthActivityActionType, type AuthAdminManager, type AuthConfig, type AuthConfirmation, AuthError, type AuthManager$1 as AuthManager, type AuthProvider, type AuthRemember, type AuthReset, AuthRole, type AuthSession, AuthStatus, AzureProvider, type AzureProviderConfig, BaseOAuthProvider, ConfirmationExpiredError, ConfirmationNotFoundError, EmailNotVerifiedError, EmailTakenError, GitHubProvider, type GitHubProviderConfig, GoogleProvider, type GoogleProviderConfig, InvalidBackupCodeError, InvalidEmailError, InvalidPasswordError, InvalidTokenError, InvalidTwoFactorCodeError, type OAuthProvider, type OAuthProviderConfig, type OAuthUserData, OtpProvider, ResetDisabledError, ResetExpiredError, ResetNotFoundError, SecondFactorRequiredError, type TokenCallback, TooManyResetsError, TotpProvider, TwoFactorAlreadyEnabledError, type TwoFactorChallenge, TwoFactorExpiredError, TwoFactorManager, TwoFactorMechanism, type TwoFactorMethod, TwoFactorNotSetupError, TwoFactorSetupIncompleteError, type TwoFactorSetupResult, type TwoFactorToken, type UserIdentifier, UserInactiveError, UserNotFoundError, UserNotLoggedInError, addRoleToUser, cleanupExpiredTokens, createAuthMiddleware, createAuthTables, createUser, dropAuthTables, getAuthTableStats, getUserRoles, isValidEmail, removeRoleFromUser, setUserRoles, validateEmail };
|
package/dist/index.js
CHANGED
|
@@ -2544,6 +2544,44 @@ async function getAuthTableStats(config) {
|
|
|
2544
2544
|
expiredTwoFactorTokens: parseInt(expiredTwoFactorTokensResult.rows[0]?.count || "0")
|
|
2545
2545
|
};
|
|
2546
2546
|
}
|
|
2547
|
+
|
|
2548
|
+
// src/user-roles.ts
|
|
2549
|
+
async function findAccountByIdentifier(queries, identifier) {
|
|
2550
|
+
let account = null;
|
|
2551
|
+
if (identifier.accountId !== void 0) {
|
|
2552
|
+
account = await queries.findAccountById(identifier.accountId);
|
|
2553
|
+
} else if (identifier.email !== void 0) {
|
|
2554
|
+
account = await queries.findAccountByEmail(identifier.email);
|
|
2555
|
+
} else if (identifier.userId !== void 0) {
|
|
2556
|
+
account = await queries.findAccountByUserId(identifier.userId);
|
|
2557
|
+
}
|
|
2558
|
+
if (!account) {
|
|
2559
|
+
throw new UserNotFoundError();
|
|
2560
|
+
}
|
|
2561
|
+
return account;
|
|
2562
|
+
}
|
|
2563
|
+
async function addRoleToUser(config, identifier, role) {
|
|
2564
|
+
const queries = new AuthQueries(config);
|
|
2565
|
+
const account = await findAccountByIdentifier(queries, identifier);
|
|
2566
|
+
const rolemask = account.rolemask | role;
|
|
2567
|
+
await queries.updateAccount(account.id, { rolemask });
|
|
2568
|
+
}
|
|
2569
|
+
async function removeRoleFromUser(config, identifier, role) {
|
|
2570
|
+
const queries = new AuthQueries(config);
|
|
2571
|
+
const account = await findAccountByIdentifier(queries, identifier);
|
|
2572
|
+
const rolemask = account.rolemask & ~role;
|
|
2573
|
+
await queries.updateAccount(account.id, { rolemask });
|
|
2574
|
+
}
|
|
2575
|
+
async function setUserRoles(config, identifier, rolemask) {
|
|
2576
|
+
const queries = new AuthQueries(config);
|
|
2577
|
+
const account = await findAccountByIdentifier(queries, identifier);
|
|
2578
|
+
await queries.updateAccount(account.id, { rolemask });
|
|
2579
|
+
}
|
|
2580
|
+
async function getUserRoles(config, identifier) {
|
|
2581
|
+
const queries = new AuthQueries(config);
|
|
2582
|
+
const account = await findAccountByIdentifier(queries, identifier);
|
|
2583
|
+
return account.rolemask;
|
|
2584
|
+
}
|
|
2547
2585
|
export {
|
|
2548
2586
|
ActivityLogger,
|
|
2549
2587
|
AuthActivityAction,
|
|
@@ -2579,13 +2617,17 @@ export {
|
|
|
2579
2617
|
UserInactiveError,
|
|
2580
2618
|
UserNotFoundError,
|
|
2581
2619
|
UserNotLoggedInError,
|
|
2620
|
+
addRoleToUser,
|
|
2582
2621
|
cleanupExpiredTokens,
|
|
2583
2622
|
createAuthMiddleware,
|
|
2584
2623
|
createAuthTables,
|
|
2585
2624
|
createUser,
|
|
2586
2625
|
dropAuthTables,
|
|
2587
2626
|
getAuthTableStats,
|
|
2627
|
+
getUserRoles,
|
|
2588
2628
|
isValidEmail,
|
|
2629
|
+
removeRoleFromUser,
|
|
2630
|
+
setUserRoles,
|
|
2589
2631
|
validateEmail
|
|
2590
2632
|
};
|
|
2591
2633
|
//# sourceMappingURL=index.js.map
|