@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.cjs
CHANGED
|
@@ -64,13 +64,17 @@ __export(index_exports, {
|
|
|
64
64
|
UserInactiveError: () => UserInactiveError,
|
|
65
65
|
UserNotFoundError: () => UserNotFoundError,
|
|
66
66
|
UserNotLoggedInError: () => UserNotLoggedInError,
|
|
67
|
+
addRoleToUser: () => addRoleToUser,
|
|
67
68
|
cleanupExpiredTokens: () => cleanupExpiredTokens,
|
|
68
69
|
createAuthMiddleware: () => createAuthMiddleware,
|
|
69
70
|
createAuthTables: () => createAuthTables,
|
|
70
71
|
createUser: () => createUser,
|
|
71
72
|
dropAuthTables: () => dropAuthTables,
|
|
72
73
|
getAuthTableStats: () => getAuthTableStats,
|
|
74
|
+
getUserRoles: () => getUserRoles,
|
|
73
75
|
isValidEmail: () => isValidEmail,
|
|
76
|
+
removeRoleFromUser: () => removeRoleFromUser,
|
|
77
|
+
setUserRoles: () => setUserRoles,
|
|
74
78
|
validateEmail: () => validateEmail
|
|
75
79
|
});
|
|
76
80
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -2621,6 +2625,44 @@ async function getAuthTableStats(config) {
|
|
|
2621
2625
|
expiredTwoFactorTokens: parseInt(expiredTwoFactorTokensResult.rows[0]?.count || "0")
|
|
2622
2626
|
};
|
|
2623
2627
|
}
|
|
2628
|
+
|
|
2629
|
+
// src/user-roles.ts
|
|
2630
|
+
async function findAccountByIdentifier(queries, identifier) {
|
|
2631
|
+
let account = null;
|
|
2632
|
+
if (identifier.accountId !== void 0) {
|
|
2633
|
+
account = await queries.findAccountById(identifier.accountId);
|
|
2634
|
+
} else if (identifier.email !== void 0) {
|
|
2635
|
+
account = await queries.findAccountByEmail(identifier.email);
|
|
2636
|
+
} else if (identifier.userId !== void 0) {
|
|
2637
|
+
account = await queries.findAccountByUserId(identifier.userId);
|
|
2638
|
+
}
|
|
2639
|
+
if (!account) {
|
|
2640
|
+
throw new UserNotFoundError();
|
|
2641
|
+
}
|
|
2642
|
+
return account;
|
|
2643
|
+
}
|
|
2644
|
+
async function addRoleToUser(config, identifier, role) {
|
|
2645
|
+
const queries = new AuthQueries(config);
|
|
2646
|
+
const account = await findAccountByIdentifier(queries, identifier);
|
|
2647
|
+
const rolemask = account.rolemask | role;
|
|
2648
|
+
await queries.updateAccount(account.id, { rolemask });
|
|
2649
|
+
}
|
|
2650
|
+
async function removeRoleFromUser(config, identifier, role) {
|
|
2651
|
+
const queries = new AuthQueries(config);
|
|
2652
|
+
const account = await findAccountByIdentifier(queries, identifier);
|
|
2653
|
+
const rolemask = account.rolemask & ~role;
|
|
2654
|
+
await queries.updateAccount(account.id, { rolemask });
|
|
2655
|
+
}
|
|
2656
|
+
async function setUserRoles(config, identifier, rolemask) {
|
|
2657
|
+
const queries = new AuthQueries(config);
|
|
2658
|
+
const account = await findAccountByIdentifier(queries, identifier);
|
|
2659
|
+
await queries.updateAccount(account.id, { rolemask });
|
|
2660
|
+
}
|
|
2661
|
+
async function getUserRoles(config, identifier) {
|
|
2662
|
+
const queries = new AuthQueries(config);
|
|
2663
|
+
const account = await findAccountByIdentifier(queries, identifier);
|
|
2664
|
+
return account.rolemask;
|
|
2665
|
+
}
|
|
2624
2666
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2625
2667
|
0 && (module.exports = {
|
|
2626
2668
|
ActivityLogger,
|
|
@@ -2657,13 +2699,17 @@ async function getAuthTableStats(config) {
|
|
|
2657
2699
|
UserInactiveError,
|
|
2658
2700
|
UserNotFoundError,
|
|
2659
2701
|
UserNotLoggedInError,
|
|
2702
|
+
addRoleToUser,
|
|
2660
2703
|
cleanupExpiredTokens,
|
|
2661
2704
|
createAuthMiddleware,
|
|
2662
2705
|
createAuthTables,
|
|
2663
2706
|
createUser,
|
|
2664
2707
|
dropAuthTables,
|
|
2665
2708
|
getAuthTableStats,
|
|
2709
|
+
getUserRoles,
|
|
2666
2710
|
isValidEmail,
|
|
2711
|
+
removeRoleFromUser,
|
|
2712
|
+
setUserRoles,
|
|
2667
2713
|
validateEmail
|
|
2668
2714
|
});
|
|
2669
2715
|
//# sourceMappingURL=index.cjs.map
|