@app-vitals/agent-admin 1.113.0 → 1.113.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/package.json +2 -2
- package/prisma/client/browser.ts +2 -2
- package/prisma/client/client.ts +2 -2
- package/prisma/client/internal/class.ts +7 -7
- package/prisma/client/internal/prismaNamespace.ts +39 -39
- package/prisma/client/internal/prismaNamespaceBrowser.ts +3 -3
- package/prisma/client/models/UserPrefs.ts +1249 -0
- package/prisma/client/models.ts +1 -1
- package/prisma/schema/schema.prisma +2 -2
- package/src/account-member-removal.integration.test.ts +5 -5
- package/src/account-members.ts +2 -2
- package/src/account-move.integration.test.ts +4 -4
- package/src/account-move.ts +1 -1
- package/src/admin-ui-agent-members.smoke.test.ts +1 -1
- package/src/ensure-account-member.integration.test.ts +1 -1
- package/src/member-rows.ts +2 -2
- package/src/member-rows.unit.test.ts +2 -2
- package/src/test-support/member-id-test-support.ts +1 -1
- package/src/user-prefs.integration.test.ts +5 -5
- package/src/user-prefs.ts +9 -12
- package/prisma/client/models/UserNotificationPrefs.ts +0 -1249
- package/src/user-notification-prefs.ts +0 -16
- package/src/user-notification-prefs.unit.test.ts +0 -9
package/prisma/client/models.ts
CHANGED
|
@@ -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/
|
|
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
|
|
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")
|
|
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
|
-
*
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
175
|
+
expect(await prisma.userPrefs.count()).toBe(0);
|
|
176
176
|
});
|
|
177
177
|
});
|
package/src/account-members.ts
CHANGED
|
@@ -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,
|
|
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,
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
327
|
+
await prisma.userPrefs.count({
|
|
328
328
|
where: { memberId: ownerId },
|
|
329
329
|
}),
|
|
330
330
|
).toBe(1);
|
package/src/account-move.ts
CHANGED
|
@@ -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
|
-
*
|
|
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
|
|
@@ -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
|
-
|
|
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.
|
|
28
|
+
await prisma.userPrefs.deleteMany();
|
|
29
29
|
await prisma.chatThreadWatch.deleteMany();
|
|
30
30
|
await prisma.pushSubscription.deleteMany();
|
|
31
31
|
await prisma.agentMember.deleteMany();
|
package/src/member-rows.ts
CHANGED
|
@@ -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,
|
|
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.
|
|
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
|
-
"
|
|
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
|
-
|
|
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.
|
|
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
|
-
*
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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 {
|
|
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<
|
|
50
|
-
return this.prisma.
|
|
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<
|
|
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.
|
|
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:
|
|
81
|
+
Array<{ memberId: string; email: string; prefs: UserPrefs }>
|
|
85
82
|
> {
|
|
86
|
-
const rows = await this.prisma.
|
|
83
|
+
const rows = await this.prisma.userPrefs.findMany({
|
|
87
84
|
where: { autoFollowSessions: true },
|
|
88
85
|
});
|
|
89
86
|
const { principals } = await this.lookup.resolveMany(
|