@frigear-nu/users 1.1.4 → 1.2.1
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/module.json +1 -1
- package/dist/module.mjs +4 -2
- package/dist/runtime/admin-menus.js +1 -0
- package/dist/runtime/app/components/UserCreateSlideover.vue +1 -0
- package/dist/runtime/app/composables/useUserActions.d.ts +1 -1
- package/dist/runtime/app/composables/useUserActions.js +1 -0
- package/dist/runtime/app/pages/admin-user.vue +1 -0
- package/dist/runtime/app/pages/admin.vue +1 -0
- package/dist/runtime/app/pages/revert-email-change.vue +1 -0
- package/dist/runtime/app/pages/verify-email-change.vue +1 -0
- package/dist/runtime/app/tabs/Overview.vue +1 -0
- package/dist/runtime/app/widgets/NewUsers.vue +1 -0
- package/dist/runtime/app/widgets/NewUsersStat.vue +1 -0
- package/dist/runtime/server/plugins/users-read-scope.d.ts +2 -0
- package/dist/runtime/server/plugins/users-read-scope.js +6 -0
- package/dist/runtime/server/routes/admin/user.get.js +1 -1
- package/dist/runtime/server/routes/admin/users.get.js +1 -1
- package/dist/runtime/server/utils/admin.d.ts +21 -4
- package/dist/runtime/server/utils/admin.js +14 -7
- package/package.json +11 -11
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addServerImportsDir, hasNuxtModule } from '@nuxt/kit';
|
|
1
|
+
import { defineNuxtModule, createResolver, addServerImportsDir, hasNuxtModule, addServerPlugin } from '@nuxt/kit';
|
|
2
2
|
import { registerTailwindSource, registerLocales, registerDatabaseTable, inlineModuleRuntime, addModulePages, addModuleRoutes, resolvePagePath, addOptionalMenuSource } from '@frigear-nu/module-kit/utils';
|
|
3
3
|
import { setAuthUserStore, addAuthScope } from '@frigear-nu/auth/utils';
|
|
4
4
|
|
|
@@ -93,6 +93,8 @@ const module$1 = defineNuxtModule({
|
|
|
93
93
|
}
|
|
94
94
|
const adminPagePath = withAdmin && withAdminShell ? resolvePagePath(adminOptions.page ?? true, (await import('@frigear-nu/admin/utils')).adminRoute(nuxt, "users")) : void 0;
|
|
95
95
|
if (withAdmin) {
|
|
96
|
+
addAuthScope(nuxt, { name: "users:read", description: "Read the user directory (staff only)" });
|
|
97
|
+
addServerPlugin(resolver.resolve("./runtime/server/plugins/users-read-scope"));
|
|
96
98
|
addModuleRoutes(resolver, [
|
|
97
99
|
{ method: "get", path: "", file: "admin/users.get" },
|
|
98
100
|
{ method: "post", path: "", file: "admin/users.post" },
|
|
@@ -110,7 +112,7 @@ const module$1 = defineNuxtModule({
|
|
|
110
112
|
{ name: "users-admin-user", path: `${adminPagePath.replace(/\/+$/, "")}/:id(\\d+)`, file: "./runtime/app/pages/admin-user.vue" }
|
|
111
113
|
]);
|
|
112
114
|
}
|
|
113
|
-
if (hasNuxtModule("@frigear-nu/widget")) {
|
|
115
|
+
if (withAdminShell && hasNuxtModule("@frigear-nu/widget")) {
|
|
114
116
|
const { extendWidgets, extendTabs } = await import('@frigear-nu/widget/utils');
|
|
115
117
|
extendTabs(nuxt, "admin.users", {
|
|
116
118
|
id: "overview",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { usersApi } from "../../utils/api";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
+
import { $fetch, computed, reactive, useAction, useModuleT } from "#imports";
|
|
4
5
|
defineOptions({ name: "UsersUserCreateSlideover" });
|
|
5
6
|
const props = defineProps({
|
|
6
7
|
roles: { type: Array, required: false }
|
|
@@ -18,7 +18,7 @@ export interface UserMenuOptions {
|
|
|
18
18
|
* `RowMenu` of the list rows and the detail heading, ordered Open, sign-in link, extras, then Delete in its own group.
|
|
19
19
|
*/
|
|
20
20
|
export declare function useUserActions(): {
|
|
21
|
-
listPath: any
|
|
21
|
+
listPath: import("vue").ComputedRef<any>;
|
|
22
22
|
userPath: (id: number) => string;
|
|
23
23
|
create: (options?: {
|
|
24
24
|
roles?: string[];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import UserCreateSlideover from "../components/UserCreateSlideover.vue";
|
|
2
2
|
import { ADMIN_USERS_KEY } from "../utils/admin-user.js";
|
|
3
3
|
import { usersApi } from "../../utils/api.js";
|
|
4
|
+
import { $fetch, computed, navigateTo, refreshNuxtData, useAction, useConfirmDialog, useLocaleLink, useModuleT, useOverlay, useRuntimeConfig } from "#imports";
|
|
4
5
|
export function useUserActions() {
|
|
5
6
|
const t = useModuleT("users");
|
|
6
7
|
const overlay = useOverlay();
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { usersApi } from "../../utils/api";
|
|
3
3
|
import OverviewTab from "../tabs/Overview.vue";
|
|
4
4
|
import { useUserActions } from "../composables/useUserActions";
|
|
5
|
+
import { computed, navigateTo, resolveComponent, useFetch, useModuleT, useRoute } from "#imports";
|
|
5
6
|
defineOptions({ name: "UsersAdminUserPage" });
|
|
6
7
|
const t = useModuleT("users");
|
|
7
8
|
const route = useRoute();
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { usersApi } from "../../utils/api";
|
|
3
3
|
import { ADMIN_USERS_KEY } from "../utils/admin-user";
|
|
4
4
|
import { useUserActions } from "../composables/useUserActions";
|
|
5
|
+
import { computed, emptyCell, h, navigateTo, resolveComponent, useFetch, useFormat, useModuleT, useTableQuery, useTableSort } from "#imports";
|
|
5
6
|
defineOptions({ name: "UsersAdminPage" });
|
|
6
7
|
const t = useModuleT("users");
|
|
7
8
|
const format = useFormat();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { usersApi } from "../../utils/api";
|
|
3
|
+
import { $fetch, computed, ref, useAuthPages, useFetch, useModuleT, useRoute, useRuntimeConfig, useUserSession } from "#imports";
|
|
3
4
|
defineOptions({ name: "UsersRevertEmailChangePage" });
|
|
4
5
|
const t = useModuleT("users.emailChange");
|
|
5
6
|
const route = useRoute();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { usersApi } from "../../utils/api";
|
|
3
|
+
import { $fetch, computed, navigateTo, ref, useAuthPages, useFetch, useModuleT, useRoute, useRuntimeConfig, useUserSession } from "#imports";
|
|
3
4
|
defineOptions({ name: "UsersVerifyEmailChangePage" });
|
|
4
5
|
const t = useModuleT("users.emailChange");
|
|
5
6
|
const route = useRoute();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { usersApi } from "../../utils/api";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
+
import { $fetch, computed, reactive, resolveComponent, useAction, useFormat, useModuleT, watch } from "#imports";
|
|
4
5
|
defineOptions({ name: "UsersAdminOverviewTab" });
|
|
5
6
|
const props = defineProps({
|
|
6
7
|
user: { type: Object, required: true }
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { usersApi } from "../../utils/api";
|
|
3
|
+
import { useFormat, useLazyFetch, useLocaleLink, useModuleT, useRuntimeConfig } from "#imports";
|
|
3
4
|
defineOptions({ name: "UsersNewUsersWidget" });
|
|
4
5
|
const t = useModuleT("users");
|
|
5
6
|
const format = useFormat();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { db, schema } from "@nuxthub/db";
|
|
2
2
|
import { count, eq } from "drizzle-orm";
|
|
3
3
|
export default defineEventHandler(async (event) => {
|
|
4
|
-
const { actor, target } = await loadUsersAdminTarget(event, "view");
|
|
4
|
+
const { actor, target } = await loadUsersAdminTarget(event, "view", { scopes: [USERS_READ_SCOPE] });
|
|
5
5
|
const withRole = usersHaveRoles();
|
|
6
6
|
const targetInfo = usersAdminTargetInfo(target);
|
|
7
7
|
const passkeys = schema.userCredentials ? (await db.select({ total: count() }).from(schema.userCredentials).where(eq(schema.userCredentials.userId, target.id)))[0]?.total ?? 0 : 0;
|
|
@@ -11,7 +11,7 @@ const querySchema = pageQuery({
|
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
export default defineEventHandler(async (event) => {
|
|
14
|
-
const actor = await authorizeUsersAdmin(event, "view");
|
|
14
|
+
const actor = await authorizeUsersAdmin(event, "view", {}, { scopes: [USERS_READ_SCOPE] });
|
|
15
15
|
const query = await getValidatedQuery(event, querySchema.parse);
|
|
16
16
|
const withRole = usersHaveRoles();
|
|
17
17
|
const columns = schema.users;
|
|
@@ -20,6 +20,16 @@ export type UsersAdminContext = {
|
|
|
20
20
|
/** Set to `true` to allow. Denied by default. */
|
|
21
21
|
allowed: boolean;
|
|
22
22
|
};
|
|
23
|
+
/** How a users admin route lets callers in. */
|
|
24
|
+
export type UsersAdminCallerOptions = {
|
|
25
|
+
/**
|
|
26
|
+
* `view` only: also accept API tokens and OAuth access tokens that carry these scopes (`users:read` for the
|
|
27
|
+
* read-only routes). The host policy still runs against the token's user. Without it, a session is required.
|
|
28
|
+
*/
|
|
29
|
+
scopes?: string[];
|
|
30
|
+
};
|
|
31
|
+
/** The scope that lets an API token or OAuth access token read the user directory. Staff only (see the module). */
|
|
32
|
+
export declare const USERS_READ_SCOPE = "users:read";
|
|
23
33
|
export type UsersAdminRolesContext = {
|
|
24
34
|
event: H3Event;
|
|
25
35
|
/** The signed-in user making the request. */
|
|
@@ -29,8 +39,13 @@ export type UsersAdminRolesContext = {
|
|
|
29
39
|
};
|
|
30
40
|
/** Whether another module added a `role` column to `users` (`@frigear-nu/authorization`). */
|
|
31
41
|
export declare const usersHaveRoles: () => boolean;
|
|
32
|
-
/** Whether the host policy
|
|
33
|
-
export declare
|
|
42
|
+
/** Whether the host policy lets `userId` view the users admin: who may hold `users:read`. */
|
|
43
|
+
export declare const isUsersAdminViewer: (event: H3Event, userId: number) => any;
|
|
44
|
+
/**
|
|
45
|
+
* Whether the host policy allows the caller to do `action` (never throws on denial; 401 without a credential). A
|
|
46
|
+
* bearer credential is allowed nothing beyond what `options.scopes` opens up.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isUsersAdminAllowed(event: H3Event, action: UsersAdminAction, details?: Pick<UsersAdminContext, 'input' | 'target'>, options?: UsersAdminCallerOptions): Promise<{
|
|
34
49
|
allowed: any;
|
|
35
50
|
user: any;
|
|
36
51
|
}>;
|
|
@@ -38,7 +53,7 @@ export declare function isUsersAdminAllowed(event: H3Event, action: UsersAdminAc
|
|
|
38
53
|
* Asks the host (the `users:admin:authorize` hook) whether the signed-in user may do `action`; throws 401/403
|
|
39
54
|
* otherwise. The users module knows nothing about roles or staff: that policy is the host's.
|
|
40
55
|
*/
|
|
41
|
-
export declare function authorizeUsersAdmin(event: H3Event, action: UsersAdminAction, details?: Pick<UsersAdminContext, 'input' | 'target'
|
|
56
|
+
export declare function authorizeUsersAdmin(event: H3Event, action: UsersAdminAction, details?: Pick<UsersAdminContext, 'input' | 'target'>, options?: UsersAdminCallerOptions): Promise<any>;
|
|
42
57
|
/**
|
|
43
58
|
* The roles the signed-in user may assign. Defaults to the roles in use; the host narrows/extends it through the
|
|
44
59
|
* `users:admin:roles` hook (e.g. from a role hierarchy and the acting user's own rank).
|
|
@@ -62,10 +77,12 @@ export declare const usersAdminTargetInfo: (user: {
|
|
|
62
77
|
* Loads the user a staff member is acting on (`/api/admin/users/:id/...`) and runs the users admin policy against
|
|
63
78
|
* them (`view` for reads, `update` for changes). For routes added with `extendUsersAdmin`.
|
|
64
79
|
*
|
|
80
|
+
* `options.scopes` lets bearer credentials with those scopes in for `view` (see `UsersAdminCallerOptions`).
|
|
81
|
+
*
|
|
65
82
|
* Authorizes before it looks anything up: 401 without a session, 403 when the host denies `action` outright, then
|
|
66
83
|
* 400 for a malformed id, 404 for an unknown user, and 403 again when the host denies `action` on this target.
|
|
67
84
|
*/
|
|
68
|
-
export declare function loadUsersAdminTarget(event: H3Event, action: Exclude<UsersAdminAction, 'create'
|
|
85
|
+
export declare function loadUsersAdminTarget(event: H3Event, action: Exclude<UsersAdminAction, 'create'>, options?: UsersAdminCallerOptions): Promise<{
|
|
69
86
|
actor: any;
|
|
70
87
|
target: any;
|
|
71
88
|
}>;
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import { db, schema } from "@nuxthub/db";
|
|
2
2
|
import { desc, getTableColumns, inArray } from "drizzle-orm";
|
|
3
3
|
import { intIdParams, notFound } from "@frigear-nu/module-kit/server";
|
|
4
|
+
import { hasScopes } from "@frigear-nu/auth/utils";
|
|
5
|
+
export const USERS_READ_SCOPE = "users:read";
|
|
4
6
|
export const usersHaveRoles = () => "role" in getTableColumns(schema.users);
|
|
5
7
|
const usersAdminGate = definePolicyGate("users:admin:authorize");
|
|
6
8
|
const USERS_ADMIN_DENIED = "You are not allowed to manage users.";
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
+
export const isUsersAdminViewer = (event, userId) => usersAdminGate.isAllowed(event, userId, { action: "view" });
|
|
10
|
+
const requireUsersAdminCaller = (event, action, options) => requireUser(event, action === "view" && options.scopes?.length ? { scopes: options.scopes } : { sessionOnly: true });
|
|
11
|
+
export async function isUsersAdminAllowed(event, action, details = {}, options = {}) {
|
|
12
|
+
const principal = await requireAuth(event);
|
|
13
|
+
const user = principal.user;
|
|
14
|
+
const bearerAllowed = action === "view" && !!options.scopes?.length && hasScopes(principal.scopes, options.scopes);
|
|
15
|
+
if (principal.kind !== "session" && !bearerAllowed) return { allowed: false, user };
|
|
9
16
|
const allowed = await usersAdminGate.isAllowed(event, user.id, { action, ...details });
|
|
10
17
|
return { allowed, user };
|
|
11
18
|
}
|
|
12
|
-
export async function authorizeUsersAdmin(event, action, details = {}) {
|
|
13
|
-
const user = await
|
|
19
|
+
export async function authorizeUsersAdmin(event, action, details = {}, options = {}) {
|
|
20
|
+
const user = await requireUsersAdminCaller(event, action, options);
|
|
14
21
|
await usersAdminGate.assert(event, user.id, USERS_ADMIN_DENIED, { action, ...details });
|
|
15
22
|
return user;
|
|
16
23
|
}
|
|
@@ -44,11 +51,11 @@ export const usersAdminTargetInfo = (user) => ({
|
|
|
44
51
|
email: user.email,
|
|
45
52
|
role: usersHaveRoles() ? user.role : void 0
|
|
46
53
|
});
|
|
47
|
-
export async function loadUsersAdminTarget(event, action) {
|
|
48
|
-
await authorizeUsersAdmin(event, action);
|
|
54
|
+
export async function loadUsersAdminTarget(event, action, options = {}) {
|
|
55
|
+
await authorizeUsersAdmin(event, action, {}, options);
|
|
49
56
|
const { id } = await getValidatedRouterParams(event, intIdParams().parse);
|
|
50
57
|
const target = await db.query.users.findFirst({ where: (t, { eq }) => eq(t.id, id) });
|
|
51
58
|
if (!target) throw notFound("User not found.");
|
|
52
|
-
const actor = await authorizeUsersAdmin(event, action, { target: usersAdminTargetInfo(target), input: {} });
|
|
59
|
+
const actor = await authorizeUsersAdmin(event, action, { target: usersAdminTargetInfo(target), input: {} }, options);
|
|
53
60
|
return { actor, target };
|
|
54
61
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/users",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "The user entity for the main frigear app: the users table, admin user management and self-service profile, email and password changes. Sign-in lives in @frigear-nu/auth.",
|
|
5
5
|
"homepage": "https://docs.frigear.dev/modules/users",
|
|
6
6
|
"repository": {
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"playground"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@frigear-nu/auth": "0.1
|
|
38
|
-
"@frigear-nu/mcp": "0.
|
|
39
|
-
"@frigear-nu/module-kit": "1.
|
|
40
|
-
"@frigear-nu/notify": "0.
|
|
41
|
-
"@frigear-nu/ui": "0.
|
|
37
|
+
"@frigear-nu/auth": "0.2.1",
|
|
38
|
+
"@frigear-nu/mcp": "0.2.0",
|
|
39
|
+
"@frigear-nu/module-kit": "1.2.0",
|
|
40
|
+
"@frigear-nu/notify": "0.2.0",
|
|
41
|
+
"@frigear-nu/ui": "0.2.0",
|
|
42
42
|
"@libsql/client": "^0.18.0",
|
|
43
43
|
"@nuxt/kit": "^4.6.1",
|
|
44
44
|
"drizzle-kit": "^0.31.11",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@frigear-nu/admin": ">=0.0.0",
|
|
51
51
|
"@frigear-nu/email-templates": "0.1.0",
|
|
52
|
-
"@frigear-nu/menu": "0.
|
|
53
|
-
"@frigear-nu/widget": "0.
|
|
52
|
+
"@frigear-nu/menu": "0.2.0",
|
|
53
|
+
"@frigear-nu/widget": "0.2.0",
|
|
54
54
|
"@nuxt/ui": "^4.12.0",
|
|
55
55
|
"@nuxthub/core": "^0.10.8"
|
|
56
56
|
},
|
|
@@ -73,10 +73,10 @@
|
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@electric-sql/pglite": "^0.5.9",
|
|
76
|
-
"@frigear-nu/admin": "0.
|
|
76
|
+
"@frigear-nu/admin": "0.2.0",
|
|
77
77
|
"@frigear-nu/email-templates": "0.1.0",
|
|
78
|
-
"@frigear-nu/menu": "0.
|
|
79
|
-
"@frigear-nu/widget": "0.
|
|
78
|
+
"@frigear-nu/menu": "0.2.0",
|
|
79
|
+
"@frigear-nu/widget": "0.2.0",
|
|
80
80
|
"@nuxt/devtools": "^3.4.2",
|
|
81
81
|
"@nuxt/eslint-config": "^1.17.0",
|
|
82
82
|
"@nuxt/module-builder": "^1.0.3",
|