@frigear-nu/users 1.1.2 → 1.1.4

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/dist/module.d.mts +26 -4
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +35 -29
  4. package/dist/runtime/app/components/UserCreateSlideover.vue +2 -1
  5. package/dist/runtime/app/composables/useUserActions.d.ts +1 -1
  6. package/dist/runtime/app/composables/useUserActions.js +6 -3
  7. package/dist/runtime/app/pages/admin-user.vue +14 -5
  8. package/dist/runtime/app/pages/admin.vue +85 -75
  9. package/dist/runtime/app/pages/revert-email-change.d.vue.ts +3 -0
  10. package/dist/runtime/app/pages/revert-email-change.vue +104 -0
  11. package/dist/runtime/app/pages/revert-email-change.vue.d.ts +3 -0
  12. package/dist/runtime/app/pages/verify-email-change.d.vue.ts +3 -0
  13. package/dist/runtime/app/pages/verify-email-change.vue +156 -0
  14. package/dist/runtime/app/pages/verify-email-change.vue.d.ts +3 -0
  15. package/dist/runtime/app/tabs/Overview.vue +51 -53
  16. package/dist/runtime/app/utils/admin-user.d.ts +4 -17
  17. package/dist/runtime/app/widgets/NewUsers.vue +2 -1
  18. package/dist/runtime/app/widgets/NewUsersStat.vue +2 -1
  19. package/dist/runtime/i18n/lang/da.json +46 -3
  20. package/dist/runtime/i18n/lang/en.json +46 -3
  21. package/dist/runtime/server/email-change.d.ts +6 -0
  22. package/dist/runtime/server/email-change.js +10 -0
  23. package/dist/runtime/server/routes/admin/new.get.js +2 -8
  24. package/dist/runtime/server/routes/admin/user-resend.post.js +3 -13
  25. package/dist/runtime/server/routes/admin/user.delete.js +6 -15
  26. package/dist/runtime/server/routes/admin/user.get.js +6 -16
  27. package/dist/runtime/server/routes/admin/user.patch.js +13 -23
  28. package/dist/runtime/server/routes/admin/users.get.js +24 -28
  29. package/dist/runtime/server/routes/admin/users.post.js +12 -13
  30. package/dist/runtime/server/routes/me/email-change-confirm.post.js +44 -0
  31. package/dist/runtime/server/routes/me/email-change-revert.get.js +13 -0
  32. package/dist/runtime/server/routes/me/email-change-revert.post.js +28 -0
  33. package/dist/runtime/server/routes/me/email-change.get.js +22 -0
  34. package/dist/runtime/server/routes/me/{change-email.post.js → email.put.js} +9 -10
  35. package/dist/runtime/server/routes/me/password.put.d.ts +2 -0
  36. package/dist/runtime/server/routes/me/{change-password.post.js → password.put.js} +4 -5
  37. package/dist/runtime/server/routes/me/profile.patch.d.ts +2 -0
  38. package/dist/runtime/server/routes/me/profile.patch.js +22 -0
  39. package/dist/runtime/server/schemas.d.ts +7 -0
  40. package/dist/runtime/server/schemas.js +4 -0
  41. package/dist/runtime/server/user-store.js +5 -3
  42. package/dist/runtime/server/utils/admin.d.ts +15 -3
  43. package/dist/runtime/server/utils/admin.js +16 -15
  44. package/dist/runtime/server/utils/dto.d.ts +19 -0
  45. package/dist/runtime/server/utils/dto.js +22 -0
  46. package/dist/runtime/server/utils/email.d.ts +18 -0
  47. package/dist/runtime/server/utils/email.js +18 -0
  48. package/dist/runtime/utils/api.d.ts +33 -0
  49. package/dist/runtime/utils/api.js +32 -0
  50. package/dist/runtime/utils/index.d.ts +3 -1
  51. package/dist/runtime/utils/index.js +1 -0
  52. package/dist/types.d.mts +1 -1
  53. package/package.json +18 -13
  54. package/dist/runtime/server/routes/me/profile.post.js +0 -17
  55. package/dist/runtime/server/routes/me/revert-email-change.get.js +0 -24
  56. package/dist/runtime/server/routes/me/verify-email-change.get.js +0 -37
  57. /package/dist/runtime/server/routes/me/{change-email.post.d.ts → email-change-confirm.post.d.ts} +0 -0
  58. /package/dist/runtime/server/routes/me/{change-password.post.d.ts → email-change-revert.get.d.ts} +0 -0
  59. /package/dist/runtime/server/routes/me/{profile.post.d.ts → email-change-revert.post.d.ts} +0 -0
  60. /package/dist/runtime/server/routes/me/{revert-email-change.get.d.ts → email-change.get.d.ts} +0 -0
  61. /package/dist/runtime/server/routes/me/{verify-email-change.get.d.ts → email.put.d.ts} +0 -0
@@ -0,0 +1,33 @@
1
+ import type { AdminUserDto, ProfileDto } from '../../types.js';
2
+ export type { AdminUserDto, ProfileDto };
3
+ /** The users API: self-service under `/api/users`, staff under `/api/admin/users`. */
4
+ export declare const usersApi: {
5
+ readonly me: {
6
+ /** `PATCH { name, avatar? }`: updates the caller's profile, answers the profile DTO. Session only. */
7
+ readonly profile: "/api/users/me";
8
+ /** `PUT { email }`: changes the caller's email (or emails a confirmation link with `verifyEmailChange`). Session only. */
9
+ readonly email: "/api/users/me/email";
10
+ /** `PUT { currentPassword, newPassword, confirmNewPassword }`: changes the caller's password. Session only. */
11
+ readonly password: "/api/users/me/password";
12
+ };
13
+ /** `GET ?code=`: read-only preview of an email change link (`verifyEmailChange`). */
14
+ readonly emailChange: "/api/users/email-change";
15
+ /** `POST { code }`: confirms an email change; the signed-in owner only. */
16
+ readonly emailChangeConfirm: "/api/users/email-change/confirm";
17
+ /** `GET ?code=` (preview) and `POST { code }` (restore the old address). The code is the proof, no sign-in needed. */
18
+ readonly emailChangeRevert: "/api/users/email-change/revert";
19
+ readonly admin: {
20
+ /** `GET` (paginated list, `useTableQuery` keys plus `role`, `verified`) and `POST` (create, 201). */
21
+ readonly users: "/api/admin/users";
22
+ /** `GET` (detail), `PATCH` (edit) and `DELETE` (204). */
23
+ readonly user: (id: number | string) => string;
24
+ /** `POST`: emails the sign-in link (or the verification email) again. */
25
+ readonly resend: (id: number | string) => string;
26
+ /** `GET`: the newest sign-ups of the last 30 days (dashboard). */
27
+ readonly new: "/api/admin/users/new";
28
+ /** `GET`: `{ total, newUsers, days }` (dashboard). */
29
+ readonly stats: "/api/admin/users/stats";
30
+ /** `GET`: `{ roles }` the caller may assign. */
31
+ readonly roles: "/api/admin/users/roles";
32
+ };
33
+ };
@@ -0,0 +1,32 @@
1
+ const base = "/api/users";
2
+ const adminBase = "/api/admin/users";
3
+ export const usersApi = {
4
+ me: {
5
+ /** `PATCH { name, avatar? }`: updates the caller's profile, answers the profile DTO. Session only. */
6
+ profile: `${base}/me`,
7
+ /** `PUT { email }`: changes the caller's email (or emails a confirmation link with `verifyEmailChange`). Session only. */
8
+ email: `${base}/me/email`,
9
+ /** `PUT { currentPassword, newPassword, confirmNewPassword }`: changes the caller's password. Session only. */
10
+ password: `${base}/me/password`
11
+ },
12
+ /** `GET ?code=`: read-only preview of an email change link (`verifyEmailChange`). */
13
+ emailChange: `${base}/email-change`,
14
+ /** `POST { code }`: confirms an email change; the signed-in owner only. */
15
+ emailChangeConfirm: `${base}/email-change/confirm`,
16
+ /** `GET ?code=` (preview) and `POST { code }` (restore the old address). The code is the proof, no sign-in needed. */
17
+ emailChangeRevert: `${base}/email-change/revert`,
18
+ admin: {
19
+ /** `GET` (paginated list, `useTableQuery` keys plus `role`, `verified`) and `POST` (create, 201). */
20
+ users: adminBase,
21
+ /** `GET` (detail), `PATCH` (edit) and `DELETE` (204). */
22
+ user: (id) => `${adminBase}/${encodeURIComponent(String(id))}`,
23
+ /** `POST`: emails the sign-in link (or the verification email) again. */
24
+ resend: (id) => `${adminBase}/${encodeURIComponent(String(id))}/resend`,
25
+ /** `GET`: the newest sign-ups of the last 30 days (dashboard). */
26
+ new: `${adminBase}/new`,
27
+ /** `GET`: `{ total, newUsers, days }` (dashboard). */
28
+ stats: `${adminBase}/stats`,
29
+ /** `GET`: `{ roles }` the caller may assign. */
30
+ roles: `${adminBase}/roles`
31
+ }
32
+ };
@@ -1,9 +1,11 @@
1
1
  import type { Nuxt } from '@nuxt/schema';
2
2
  import type { TabDefinition, WidgetDefinition } from '@frigear-nu/widget/utils';
3
+ export { usersApi } from './api.js';
4
+ export type { AdminUserDto, ProfileDto } from '../../types.js';
3
5
  export interface UsersAdminExtension {
4
6
  /** Staff routes on the user, mounted at `/api/admin/users/:id/<path>`. Handlers are absolute paths. */
5
7
  routes?: {
6
- method: 'get' | 'post' | 'patch' | 'delete';
8
+ method: 'get' | 'post' | 'put' | 'patch' | 'delete';
7
9
  path: string;
8
10
  handler: string;
9
11
  }[];
@@ -1,4 +1,5 @@
1
1
  import { addServerHandler, hasNuxtModule } from "@nuxt/kit";
2
+ export { usersApi } from "./api.js";
2
3
  export async function extendUsersAdmin(nuxt, extension) {
3
4
  for (const { method, path, handler } of extension.routes ?? []) {
4
5
  addServerHandler({ route: `/api/admin/users/:id/${path}`, method, handler });
package/dist/types.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { default } from './module.mjs'
2
2
 
3
- export { type ModuleOptions, type PublicModuleOptions } from './module.mjs'
3
+ export { type AdminUserDto, type ModuleOptions, type ProfileDto, type PublicModuleOptions } from './module.mjs'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frigear-nu/users",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
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": {
@@ -20,6 +20,11 @@
20
20
  "types": "./dist/runtime/utils/index.d.ts",
21
21
  "import": "./dist/runtime/utils/index.js",
22
22
  "default": "./dist/runtime/utils/index.js"
23
+ },
24
+ "./api": {
25
+ "types": "./dist/runtime/utils/api.d.ts",
26
+ "import": "./dist/runtime/utils/api.js",
27
+ "default": "./dist/runtime/utils/api.js"
23
28
  }
24
29
  },
25
30
  "files": [
@@ -29,11 +34,11 @@
29
34
  "playground"
30
35
  ],
31
36
  "dependencies": {
32
- "@frigear-nu/auth": "0.1.2",
33
- "@frigear-nu/mcp": "0.1.1",
34
- "@frigear-nu/module-kit": "1.1.1",
35
- "@frigear-nu/notify": "0.1.1",
36
- "@frigear-nu/ui": "0.1.1",
37
+ "@frigear-nu/auth": "0.1.4",
38
+ "@frigear-nu/mcp": "0.1.3",
39
+ "@frigear-nu/module-kit": "1.1.3",
40
+ "@frigear-nu/notify": "0.1.3",
41
+ "@frigear-nu/ui": "0.1.3",
37
42
  "@libsql/client": "^0.18.0",
38
43
  "@nuxt/kit": "^4.6.1",
39
44
  "drizzle-kit": "^0.31.11",
@@ -44,9 +49,9 @@
44
49
  "peerDependencies": {
45
50
  "@frigear-nu/admin": ">=0.0.0",
46
51
  "@frigear-nu/email-templates": "0.1.0",
47
- "@frigear-nu/menu": "0.1.1",
48
- "@frigear-nu/widget": "0.1.1",
49
- "@nuxt/ui": "^4.11.2",
52
+ "@frigear-nu/menu": "0.1.3",
53
+ "@frigear-nu/widget": "0.1.3",
54
+ "@nuxt/ui": "^4.12.0",
50
55
  "@nuxthub/core": "^0.10.8"
51
56
  },
52
57
  "peerDependenciesMeta": {
@@ -68,16 +73,16 @@
68
73
  },
69
74
  "devDependencies": {
70
75
  "@electric-sql/pglite": "^0.5.9",
71
- "@frigear-nu/admin": "0.1.1",
76
+ "@frigear-nu/admin": "0.1.3",
72
77
  "@frigear-nu/email-templates": "0.1.0",
73
- "@frigear-nu/menu": "0.1.1",
74
- "@frigear-nu/widget": "0.1.1",
78
+ "@frigear-nu/menu": "0.1.3",
79
+ "@frigear-nu/widget": "0.1.3",
75
80
  "@nuxt/devtools": "^3.4.2",
76
81
  "@nuxt/eslint-config": "^1.17.0",
77
82
  "@nuxt/module-builder": "^1.0.3",
78
83
  "@nuxt/schema": "^4.6.1",
79
84
  "@nuxt/test-utils": "^4.3.2",
80
- "@nuxt/ui": "^4.11.2",
85
+ "@nuxt/ui": "^4.12.0",
81
86
  "@nuxthub/core": "^0.10.8",
82
87
  "@types/node": "^26.6.5",
83
88
  "changelogen": "^0.6.2",
@@ -1,17 +0,0 @@
1
- import { db, schema } from "@nuxthub/db";
2
- import { eq } from "drizzle-orm";
3
- import { z } from "zod";
4
- const bodySchema = z.object({
5
- name: z.string().min(1),
6
- avatar: z.string().optional()
7
- });
8
- export default defineEventHandler(async (event) => {
9
- const user = await requireUser(event, { sessionOnly: true });
10
- const { name, avatar } = await readValidatedBody(event, bodySchema.parse);
11
- const [updated] = await db.update(schema.users).set({ name, avatar }).where(eq(schema.users.id, user.id)).returning();
12
- if (!updated) {
13
- throw createError({ statusCode: 404, statusMessage: "User not found." });
14
- }
15
- await setUserSession(event, { user: mapUserToSession(updated) });
16
- return { id: updated.id };
17
- });
@@ -1,24 +0,0 @@
1
- import { db, schema } from "@nuxthub/db";
2
- import { and, eq, gt, isNotNull, isNull } from "drizzle-orm";
3
- import { z } from "zod";
4
- export default defineEventHandler(async (event) => {
5
- const { code } = await getValidatedQuery(event, z.object({ code: z.string().min(1) }).parse);
6
- const loginPath = useRuntimeConfig(event).public.authentication?.pages?.login || "/";
7
- const now = /* @__PURE__ */ new Date();
8
- const [change] = await db.update(schema.accountEmailChanges).set({ revertedAt: now }).where(and(
9
- eq(schema.accountEmailChanges.revertCode, code),
10
- isNotNull(schema.accountEmailChanges.verifiedAt),
11
- isNull(schema.accountEmailChanges.revertedAt),
12
- gt(schema.accountEmailChanges.revertExpiresAt, now)
13
- )).returning();
14
- if (!change) {
15
- return sendRedirect(event, `${loginPath}?error=email-revert`);
16
- }
17
- const taken = await db.query.users.findFirst({ where: (t, { eq: eq2 }) => eq2(t.email, change.oldEmail) });
18
- if (taken && taken.id !== change.userId) {
19
- return sendRedirect(event, `${loginPath}?error=email-revert`);
20
- }
21
- await db.update(schema.users).set({ email: change.oldEmail }).where(eq(schema.users.id, change.userId));
22
- await clearUserSession(event);
23
- return sendRedirect(event, `${loginPath}?email-reverted=1`);
24
- });
@@ -1,37 +0,0 @@
1
- import { db, schema } from "@nuxthub/db";
2
- import { and, eq, gt, isNull } from "drizzle-orm";
3
- import { z } from "zod";
4
- const REVERT_TTL_DAYS = 7;
5
- export default defineEventHandler(async (event) => {
6
- const { code } = await getValidatedQuery(event, z.object({ code: z.string().min(1) }).parse);
7
- const profilePath = useRuntimeConfig(event).public.users?.profilePath || "/";
8
- const now = /* @__PURE__ */ new Date();
9
- const [change] = await db.update(schema.accountEmailChanges).set({ verifiedAt: now, revertExpiresAt: new Date(now.getTime() + REVERT_TTL_DAYS * 24 * 60 * 60 * 1e3) }).where(and(
10
- eq(schema.accountEmailChanges.code, code),
11
- isNull(schema.accountEmailChanges.verifiedAt),
12
- gt(schema.accountEmailChanges.expiresAt, now)
13
- )).returning();
14
- if (!change) {
15
- return sendRedirect(event, `${profilePath}?error=email-change`);
16
- }
17
- const taken = await db.query.users.findFirst({ where: (t, { eq: eq2 }) => eq2(t.email, change.newEmail) });
18
- if (taken && taken.id !== change.userId) {
19
- return sendRedirect(event, `${profilePath}?error=email-change`);
20
- }
21
- const [user] = await db.update(schema.users).set({ email: change.newEmail, emailVerifiedAt: now }).where(eq(schema.users.id, change.userId)).returning();
22
- if (!user) {
23
- return sendRedirect(event, `${profilePath}?error=email-change`);
24
- }
25
- const session = await getUserSession(event);
26
- if (session.user?.id === user.id) {
27
- await setUserSession(event, { user: mapUserToSession(user) });
28
- }
29
- const revertUrl = new URL(`/auth/revert-email-change?code=${change.revertCode}`, getRequestURL(event).origin).toString();
30
- await dispatchEmailNotification(buildEmailChangedNotification({
31
- to: change.oldEmail,
32
- name: user.name,
33
- newEmail: change.newEmail,
34
- revertUrl
35
- }));
36
- return sendRedirect(event, `${profilePath}?email-changed=1`);
37
- });