@app-vitals/agent-admin 1.113.0 → 1.114.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.
@@ -35,7 +35,7 @@ export type * from './models/AgentCronRunRequest.ts'
35
35
  export type * from './models/AgentGitHubInstallationsSnapshot.ts'
36
36
  export type * from './models/PushSubscription.ts'
37
37
  export type * from './models/ChatThreadWatch.ts'
38
- export type * from './models/UserNotificationPrefs.ts'
38
+ export type * from './models/UserPrefs.ts'
39
39
  export type * from './models/AgentMarketplace.ts'
40
40
  export type * from './models/GitHubReconcileAudit.ts'
41
41
  export type * from './models/GitHubRepoSnapshot.ts'
@@ -663,7 +663,7 @@ model ChatThreadWatch {
663
663
  // `reminderHourLocal` is validated to be an integer in
664
664
  // [0, 23] at the service layer (session-follow-service.ts), not here — Prisma
665
665
  // has no native CHECK constraint support in this schema style.
666
- model UserNotificationPrefs {
666
+ model UserPrefs {
667
667
  memberId String @id // AccountMember.id
668
668
  timezone String? // IANA zone name, validated in UserPrefsService
669
669
  autoFollowSessions Boolean @default(true)
@@ -672,7 +672,7 @@ model UserNotificationPrefs {
672
672
  createdAt DateTime @default(now())
673
673
  updatedAt DateTime @updatedAt
674
674
 
675
- @@map("UserPrefs") // model rename to UserPrefs is deferred to ACM 4.1
675
+ @@map("UserPrefs")
676
676
  }
677
677
 
678
678
 
@@ -2,7 +2,7 @@
2
2
  * admin/src/account-member-removal.integration.test.ts
3
3
  * AccountMemberService.remove deletes the removed person's access and
4
4
  * notification rows (AgentMember, ChatThreadWatch, PushSubscription,
5
- * UserNotificationPrefs), atomically with the removal. Real Postgres.
5
+ * UserPrefs), atomically with the removal. Real Postgres.
6
6
  *
7
7
  * Requires DATABASE_URL_ADMIN_TEST; skips otherwise.
8
8
  */
@@ -34,7 +34,7 @@ describeOrSkip("AccountMemberService.remove cleanup (integration)", () => {
34
34
  await prisma.pushSubscription.create({
35
35
  data: { endpoint: `ep-${label}`, p256dh: "p", auth: "a", memberId },
36
36
  });
37
- await prisma.userNotificationPrefs.create({ data: { memberId } });
37
+ await prisma.userPrefs.create({ data: { memberId } });
38
38
  }
39
39
 
40
40
  async function rowCounts(memberId: string) {
@@ -42,7 +42,7 @@ describeOrSkip("AccountMemberService.remove cleanup (integration)", () => {
42
42
  prisma.agentMember.count({ where: { memberId } }),
43
43
  prisma.chatThreadWatch.count({ where: { memberId } }),
44
44
  prisma.pushSubscription.count({ where: { memberId } }),
45
- prisma.userNotificationPrefs.count({ where: { memberId } }),
45
+ prisma.userPrefs.count({ where: { memberId } }),
46
46
  ]);
47
47
  }
48
48
 
@@ -55,7 +55,7 @@ describeOrSkip("AccountMemberService.remove cleanup (integration)", () => {
55
55
  beforeEach(async () => {
56
56
  prisma = createAdminPrismaClient(TEST_DB as string);
57
57
  service = new AccountMemberService(prisma);
58
- await prisma.userNotificationPrefs.deleteMany();
58
+ await prisma.userPrefs.deleteMany();
59
59
  await prisma.chatThreadWatch.deleteMany();
60
60
  await prisma.pushSubscription.deleteMany();
61
61
  await prisma.agentMember.deleteMany();
@@ -172,6 +172,6 @@ describeOrSkip("AccountMemberService.remove cleanup (integration)", () => {
172
172
  ).toBe(0);
173
173
  expect(await prisma.chatThreadWatch.count()).toBe(0);
174
174
  expect(await prisma.pushSubscription.count()).toBe(0);
175
- expect(await prisma.userNotificationPrefs.count()).toBe(0);
175
+ expect(await prisma.userPrefs.count()).toBe(0);
176
176
  });
177
177
  });
@@ -50,7 +50,7 @@ export class AccountMemberService {
50
50
  * belongs to any account.
51
51
  *
52
52
  * Null memberId rows for the email (AgentMember, ChatThreadWatch,
53
- * PushSubscription, UserNotificationPrefs) get the new id in the same
53
+ * PushSubscription, UserPrefs) get the new id in the same
54
54
  * transaction.
55
55
  *
56
56
  * @param client - pass a `tx` from `prisma.$transaction` to participate in it.
@@ -74,7 +74,7 @@ export class AccountMemberService {
74
74
 
75
75
  /**
76
76
  * Remove a member and their access and notification rows (AgentMember,
77
- * ChatThreadWatch, PushSubscription, UserNotificationPrefs), matched by
77
+ * ChatThreadWatch, PushSubscription, UserPrefs), matched by
78
78
  * memberId, in one transaction.
79
79
  */
80
80
  async remove(accountId: string, email: string): Promise<void> {
@@ -101,7 +101,7 @@ describeOrSkip("admin account move (integration)", () => {
101
101
 
102
102
  beforeEach(async () => {
103
103
  prisma = createAdminPrismaClient(TEST_DB as string);
104
- await prisma.userNotificationPrefs.deleteMany();
104
+ await prisma.userPrefs.deleteMany();
105
105
  await prisma.chatThreadWatch.deleteMany();
106
106
  await prisma.pushSubscription.deleteMany();
107
107
  await prisma.agentMember.deleteMany();
@@ -175,7 +175,7 @@ describeOrSkip("admin account move (integration)", () => {
175
175
  await prisma.pushSubscription.create({
176
176
  data: { endpoint: "ep-1", p256dh: "p", auth: "a", memberId: ownerId },
177
177
  });
178
- await prisma.userNotificationPrefs.create({ data: { memberId: ownerId } });
178
+ await prisma.userPrefs.create({ data: { memberId: ownerId } });
179
179
  });
180
180
 
181
181
  afterEach(async () => {
@@ -239,7 +239,7 @@ describeOrSkip("admin account move (integration)", () => {
239
239
  await prisma.pushSubscription.count({ where: { memberId: ownerId } }),
240
240
  ).toBe(1);
241
241
  expect(
242
- await prisma.userNotificationPrefs.count({
242
+ await prisma.userPrefs.count({
243
243
  where: { memberId: ownerId },
244
244
  }),
245
245
  ).toBe(1);
@@ -324,7 +324,7 @@ describeOrSkip("admin account move (integration)", () => {
324
324
  expect(await snapshot(prisma)).toEqual(before);
325
325
  // The member rows still point at the same member.
326
326
  expect(
327
- await prisma.userNotificationPrefs.count({
327
+ await prisma.userPrefs.count({
328
328
  where: { memberId: ownerId },
329
329
  }),
330
330
  ).toBe(1);
@@ -5,7 +5,7 @@
5
5
  * between accounts in the admin database, driven by a mapping file kept
6
6
  * outside the repo. Members move in place (same AccountMember.id), so every
7
7
  * row keyed by the member id (AgentMember, ChatThreadWatch, PushSubscription,
8
- * UserNotificationPrefs) keeps pointing at them.
8
+ * UserPrefs) keeps pointing at them.
9
9
  *
10
10
  * planMove() reads only. applyMove() re-plans inside one serializable
11
11
  * transaction and refuses (MoveRefusedError, nothing written) on any unclear
@@ -51,25 +51,37 @@ function emailForm(
51
51
  </form>`;
52
52
  }
53
53
 
54
+ /**
55
+ * One "Edit" popover per member row (owner viewers only): a no-JS
56
+ * `<details>/<summary>` disclosure mirroring the "Sync Manifest" pattern. It
57
+ * holds the role change (owners demote, members promote) and the remove form.
58
+ */
59
+ function renderMemberEditMenu(m: AccountMember): string {
60
+ const roleForm =
61
+ m.role === "owner"
62
+ ? emailForm("members/demote", m.email, "Make member")
63
+ : emailForm("members/promote", m.email, "Make owner");
64
+ const removeForm = emailForm(
65
+ "members/remove",
66
+ m.email,
67
+ "Remove",
68
+ true,
69
+ REMOVE_MEMBER_CONFIRM,
70
+ );
71
+ return `<details style="position:relative;display:inline-block">
72
+ <summary class="btn btn-secondary" style="cursor:pointer;font-size:12px;list-style:none">Edit</summary>
73
+ <div style="position:absolute;right:0;margin-top:6px;background:var(--vos-surface);border:1px solid var(--vos-border);border-radius:6px;padding:12px;box-shadow:0 4px 12px rgba(0,0,0,0.08);z-index:10;min-width:160px;display:flex;flex-direction:column;gap:8px;align-items:flex-start">
74
+ ${roleForm}
75
+ ${removeForm}
76
+ </div>
77
+ </details>`;
78
+ }
79
+
54
80
  function renderMemberRow(m: AccountMember, isOwner: boolean): string {
55
- const actions = isOwner
56
- ? [
57
- m.role === "owner"
58
- ? emailForm("members/demote", m.email, "Demote")
59
- : emailForm("members/promote", m.email, "Make owner"),
60
- emailForm(
61
- "members/remove",
62
- m.email,
63
- "Remove",
64
- true,
65
- REMOVE_MEMBER_CONFIRM,
66
- ),
67
- ].join(" ")
68
- : "";
69
81
  return `<tr>
70
82
  <td>${escapeHtml(m.email)}</td>
71
83
  <td><span class="badge ${m.role === "owner" ? "badge-purple" : "badge-gray"}">${escapeHtml(m.role)}</span></td>
72
- ${isOwner ? `<td style="text-align:right">${actions}</td>` : ""}
84
+ ${isOwner ? `<td style="text-align:right">${renderMemberEditMenu(m)}</td>` : ""}
73
85
  </tr>`;
74
86
  }
75
87
 
@@ -127,7 +139,7 @@ export function renderAccountPage(opts: AccountPageOpts): string {
127
139
  </div>
128
140
  <div class="card">
129
141
  <div class="card-title">Members</div>
130
- <div class="data-table-wrapper">
142
+ <div class="data-table-wrapper"${isOwner ? ' style="overflow:visible"' : ""}>
131
143
  <table class="data-table">
132
144
  <thead><tr><th>Email</th><th>Role</th>${actionTh}</tr></thead>
133
145
  <tbody>${memberRows}</tbody>
@@ -5,6 +5,7 @@
5
5
 
6
6
  import { describe, expect, test } from "bun:test";
7
7
  import {
8
+ REMOVE_MEMBER_CONFIRM,
8
9
  renderAccountPage,
9
10
  renderZeroQuotaNotice,
10
11
  } from "./admin-ui-account-pages.ts";
@@ -72,13 +73,74 @@ describe("renderAccountPage", () => {
72
73
  expect(html).toContain('action="/admin/account/rename"');
73
74
  });
74
75
 
75
- test("remove form confirms that access and notification settings are removed", () => {
76
- expect(render(true)).toContain("notification settings are removed");
76
+ test("owner sees exactly one Edit control per member row", () => {
77
+ const html = render(true);
78
+ expect(html.match(/<summary[^>]*>Edit<\/summary>/g)?.length).toBe(
79
+ members.length,
80
+ );
81
+ });
82
+
83
+ test("member rows have no top-level Demote/Make owner/Remove buttons", () => {
84
+ const outsidePopovers = render(true).replace(
85
+ /<details[\s\S]*?<\/details>/g,
86
+ "",
87
+ );
88
+ expect(outsidePopovers).not.toContain("members/promote");
89
+ expect(outsidePopovers).not.toContain("members/demote");
90
+ expect(outsidePopovers).not.toContain("members/remove");
91
+ expect(outsidePopovers).not.toContain(">Demote<");
92
+ expect(outsidePopovers).not.toContain(">Make owner<");
93
+ expect(outsidePopovers).not.toContain(">Remove<");
94
+ });
95
+
96
+ test("member popover offers Make owner and Remove, not Make member", () => {
97
+ const html = render(true);
98
+ const rowStart = html.indexOf("m@x.com</td>");
99
+ const row = html.slice(rowStart, html.indexOf("</tr>", rowStart));
100
+ expect(row).toContain("<details");
101
+ expect(row).toContain('action="/admin/account/members/promote"');
102
+ expect(row).toContain(">Make owner</button>");
103
+ expect(row).not.toContain("members/demote");
104
+ expect(row).not.toContain(">Make member</button>");
105
+ expect(row).toContain('action="/admin/account/members/remove"');
106
+ expect(row).toContain(">Remove</button>");
107
+ expect(row).toContain("btn-danger");
108
+ });
109
+
110
+ test("owner popover offers Make member and Remove, not Make owner", () => {
111
+ const html = render(true);
112
+ const rowStart = html.indexOf("o@x.com</td>");
113
+ const row = html.slice(rowStart, html.indexOf("</tr>", rowStart));
114
+ expect(row).toContain("<details");
115
+ expect(row).toContain('action="/admin/account/members/demote"');
116
+ expect(row).toContain(">Make member</button>");
117
+ expect(row).not.toContain("members/promote");
118
+ expect(row).not.toContain(">Make owner</button>");
119
+ expect(row).toContain('action="/admin/account/members/remove"');
120
+ expect(row).toContain(">Remove</button>");
121
+ });
122
+
123
+ test("owner members table wrapper does not clip the Edit popover", () => {
124
+ const html = render(true);
125
+ expect(html).toContain(
126
+ '<div class="data-table-wrapper" style="overflow:visible">',
127
+ );
128
+ });
129
+
130
+ test("remove form in the Edit popover confirms REMOVE_MEMBER_CONFIRM", () => {
131
+ const html = render(true);
132
+ expect(html).toContain(
133
+ `onsubmit="return confirm('${REMOVE_MEMBER_CONFIRM}')"`,
134
+ );
135
+ expect(html).toContain("notification settings are removed");
77
136
  });
78
137
 
79
- test("member sees read-only page", () => {
138
+ test("member sees read-only page with no Edit control or actions column", () => {
80
139
  const html = render(false);
81
140
  expect(html).not.toContain('action="/admin/account/');
141
+ expect(html).not.toContain(">Edit</summary>");
142
+ expect(html).not.toContain(">Edit</button>");
143
+ expect(html).not.toContain("<th></th>");
82
144
  expect(html).toContain("m@x.com");
83
145
  });
84
146
 
@@ -232,6 +232,33 @@ describe("/admin/account", () => {
232
232
  ).toBe(400);
233
233
  });
234
234
 
235
+ it("owner page renders one Edit popover per member posting to the role and remove routes", async () => {
236
+ const { app } = setup();
237
+ const body = await (
238
+ await app.request("/admin/account", {
239
+ headers: { "x-test-user-email": "owner@x.com" },
240
+ })
241
+ ).text();
242
+ expect(body.match(/<summary[^>]*>Edit<\/summary>/g)?.length).toBe(2);
243
+ expect(body).toContain('action="/admin/account/members/demote"');
244
+ expect(body).toContain('action="/admin/account/members/promote"');
245
+ expect(body).toContain('action="/admin/account/members/remove"');
246
+ expect(body).toContain(">Make member</button>");
247
+ expect(body).toContain(">Make owner</button>");
248
+ });
249
+
250
+ it("non-owner admin view has no Edit control", async () => {
251
+ const { app } = setup();
252
+ const res = await app.request("/admin/account", {
253
+ headers: { "x-test-user-email": "member@x.com", "x-test-admin": "1" },
254
+ });
255
+ expect(res.status).toBe(200);
256
+ const body = await res.text();
257
+ expect(body).toContain("member@x.com");
258
+ expect(body).not.toContain(">Edit</summary>");
259
+ expect(body).not.toContain(">Edit</button>");
260
+ });
261
+
235
262
  it("member gets 404 on every mutation (ACM-7.2)", async () => {
236
263
  const { app } = setup();
237
264
  for (const [path, fields] of [
@@ -58,7 +58,7 @@ function setup(opts: {
58
58
  agentMember: { updateMany: async () => ({ count: 0 }) },
59
59
  chatThreadWatch: { updateMany: async () => ({ count: 0 }) },
60
60
  pushSubscription: { updateMany: async () => ({ count: 0 }) },
61
- userNotificationPrefs: { updateMany: async () => ({ count: 0 }) },
61
+ userPrefs: { updateMany: async () => ({ count: 0 }) },
62
62
  } as unknown as PrismaTransactionClient;
63
63
 
64
64
  const base = makeMockDeps();
@@ -25,7 +25,7 @@ describeOrSkip("ensureAccountMember (integration)", () => {
25
25
 
26
26
  beforeEach(async () => {
27
27
  prisma = createAdminPrismaClient(TEST_DB as string);
28
- await prisma.userNotificationPrefs.deleteMany();
28
+ await prisma.userPrefs.deleteMany();
29
29
  await prisma.chatThreadWatch.deleteMany();
30
30
  await prisma.pushSubscription.deleteMany();
31
31
  await prisma.agentMember.deleteMany();
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * admin/src/member-rows.ts
3
3
  * Cleanup of the per-user rows keyed on AccountMember.id (AgentMember,
4
- * ChatThreadWatch, PushSubscription, UserNotificationPrefs). Callers that
4
+ * ChatThreadWatch, PushSubscription, UserPrefs). Callers that
5
5
  * delete an AccountMember run this with their own transaction client so the
6
6
  * record and its rows go together.
7
7
  */
@@ -18,7 +18,7 @@ export async function deleteMemberRows(
18
18
  client.agentMember.deleteMany({ where }),
19
19
  client.chatThreadWatch.deleteMany({ where }),
20
20
  client.pushSubscription.deleteMany({ where }),
21
- client.userNotificationPrefs.deleteMany({ where }),
21
+ client.userPrefs.deleteMany({ where }),
22
22
  ]);
23
23
  return results.reduce((n, r) => n + r.count, 0);
24
24
  }
@@ -6,7 +6,7 @@ const TABLES = [
6
6
  "agentMember",
7
7
  "chatThreadWatch",
8
8
  "pushSubscription",
9
- "userNotificationPrefs",
9
+ "userPrefs",
10
10
  ] as const;
11
11
 
12
12
  type Call = { table: string; where: unknown };
@@ -41,7 +41,7 @@ describe("deleteMemberRows", () => {
41
41
  const { client } = fakeClient({
42
42
  agentMember: 1,
43
43
  chatThreadWatch: 1,
44
- userNotificationPrefs: 4,
44
+ userPrefs: 4,
45
45
  });
46
46
  expect(await deleteMemberRows(client, "m1")).toBe(6);
47
47
  });
@@ -8,7 +8,7 @@
8
8
  import type { PrismaClient } from "../../prisma/client/client.ts";
9
9
 
10
10
  export async function resetMemberIdFixture(prisma: PrismaClient) {
11
- await prisma.userNotificationPrefs.deleteMany();
11
+ await prisma.userPrefs.deleteMany();
12
12
  await prisma.chatThreadWatch.deleteMany();
13
13
  await prisma.pushSubscription.deleteMany();
14
14
  await prisma.agentMember.deleteMany();
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * admin/src/user-prefs.integration.test.ts (ACM-4.1)
3
- * UserNotificationPrefs reads and writes by memberId; memberId is the primary key;
3
+ * UserPrefs reads and writes by memberId; memberId is the primary key;
4
4
  * email is resolved through the AccountMember lookup. Rows whose member no longer resolves are skipped.
5
5
  *
6
6
  * Requires DATABASE_URL_ADMIN_TEST; skips otherwise.
@@ -49,7 +49,7 @@ describeOrSkip("UserPrefsService by memberId (integration)", () => {
49
49
  it("upsert updates the existing row instead of duplicating", async () => {
50
50
  await service.upsertByMemberId(aliceId, { reminderHourLocal: 7 });
51
51
  await service.upsertByMemberId(aliceId, { autoFollowSessions: false });
52
- expect(await prisma.userNotificationPrefs.count()).toBe(1);
52
+ expect(await prisma.userPrefs.count()).toBe(1);
53
53
  const row = await service.getByMemberId(aliceId);
54
54
  expect(row?.autoFollowSessions).toBe(false);
55
55
  expect(row?.reminderHourLocal).toBe(7);
@@ -57,13 +57,13 @@ describeOrSkip("UserPrefsService by memberId (integration)", () => {
57
57
 
58
58
  it("upsert for an unknown member id returns null and writes nothing", async () => {
59
59
  expect(await service.upsertByMemberId("nope", {})).toBeNull();
60
- expect(await prisma.userNotificationPrefs.count()).toBe(0);
60
+ expect(await prisma.userPrefs.count()).toBe(0);
61
61
  });
62
62
 
63
63
  it("listAutoFollowers skips unresolvable members and resolves email via the lookup", async () => {
64
64
  await service.upsertByMemberId(aliceId, {});
65
65
  await service.upsertByMemberId(bobId, { autoFollowSessions: false });
66
- await prisma.userNotificationPrefs.create({
66
+ await prisma.userPrefs.create({
67
67
  data: { memberId: "gone-member" },
68
68
  });
69
69
  const followers = await service.listAutoFollowers();
@@ -85,6 +85,6 @@ describeOrSkip("UserPrefsService by memberId (integration)", () => {
85
85
  service.upsertByMemberId(aliceId, { timezone: tz }),
86
86
  ).rejects.toBeInstanceOf(InvalidTimezoneError);
87
87
  }
88
- expect(await prisma.userNotificationPrefs.count()).toBe(0);
88
+ expect(await prisma.userPrefs.count()).toBe(0);
89
89
  });
90
90
  });
package/src/user-prefs.ts CHANGED
@@ -1,17 +1,14 @@
1
1
  /**
2
2
  * admin/src/user-prefs.ts
3
- * UserPrefsService (formerly UserPrefsService, ACM-4.1): per-user preferences
3
+ * UserPrefsService: per-user preferences
4
4
  * read and written by memberId (AccountMember.id), which is the row's primary
5
5
  * key (ACM-5.1 dropped the userEmail column).
6
6
  */
7
7
 
8
- import type {
9
- PrismaClient,
10
- UserNotificationPrefs,
11
- } from "../prisma/client/client.ts";
8
+ import type { PrismaClient, UserPrefs } from "../prisma/client/client.ts";
12
9
  import { PrincipalLookupService } from "./principal-lookup.ts";
13
10
 
14
- export type { UserNotificationPrefs };
11
+ export type { UserPrefs };
15
12
 
16
13
  /** Thrown when a timezone is not a valid IANA zone name. */
17
14
  export class InvalidTimezoneError extends Error {
@@ -46,8 +43,8 @@ export class UserPrefsService {
46
43
  this.lookup = new PrincipalLookupService(prisma);
47
44
  }
48
45
 
49
- async getByMemberId(memberId: string): Promise<UserNotificationPrefs | null> {
50
- return this.prisma.userNotificationPrefs.findFirst({
46
+ async getByMemberId(memberId: string): Promise<UserPrefs | null> {
47
+ return this.prisma.userPrefs.findFirst({
51
48
  where: { memberId },
52
49
  });
53
50
  }
@@ -63,13 +60,13 @@ export class UserPrefsService {
63
60
  async upsertByMemberId(
64
61
  memberId: string,
65
62
  patch: UserPrefsPatch,
66
- ): Promise<UserNotificationPrefs | null> {
63
+ ): Promise<UserPrefs | null> {
67
64
  if (patch.timezone != null && !isValidIanaTimezone(patch.timezone)) {
68
65
  throw new InvalidTimezoneError(patch.timezone);
69
66
  }
70
67
  const { principals } = await this.lookup.resolveMany([memberId]);
71
68
  if (!principals.some((p) => p.type === "user")) return null;
72
- return this.prisma.userNotificationPrefs.upsert({
69
+ return this.prisma.userPrefs.upsert({
73
70
  where: { memberId },
74
71
  create: { memberId, ...patch },
75
72
  update: patch,
@@ -81,9 +78,9 @@ export class UserPrefsService {
81
78
  * lookup. Members that no longer resolve are skipped.
82
79
  */
83
80
  async listAutoFollowers(): Promise<
84
- Array<{ memberId: string; email: string; prefs: UserNotificationPrefs }>
81
+ Array<{ memberId: string; email: string; prefs: UserPrefs }>
85
82
  > {
86
- const rows = await this.prisma.userNotificationPrefs.findMany({
83
+ const rows = await this.prisma.userPrefs.findMany({
87
84
  where: { autoFollowSessions: true },
88
85
  });
89
86
  const { principals } = await this.lookup.resolveMany(