@app-vitals/agent-admin 1.105.0 → 1.106.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.
@@ -0,0 +1,42 @@
1
+ /**
2
+ * admin/src/member-id-stamp.ts
3
+ * Fills memberId on the email-keyed rows that were written before the email had
4
+ * an AccountMember (AgentMember, ChatThreadWatch, PushSubscription,
5
+ * UserNotificationPrefs). Every path that creates an AccountMember calls this
6
+ * with its own transaction client so the record and the stamping commit together.
7
+ */
8
+
9
+ import { normalizeEmail } from "./account-email.ts";
10
+ import type { PrismaTransactionClient } from "./prisma-tx.ts";
11
+
12
+ /** Sets memberId on the email's null rows in all four tables; returns the rows changed. */
13
+ export async function stampMemberId(
14
+ client: PrismaTransactionClient,
15
+ rawEmail: string,
16
+ memberId: string,
17
+ ): Promise<number> {
18
+ const email = {
19
+ equals: normalizeEmail(rawEmail),
20
+ mode: "insensitive",
21
+ } as const;
22
+ const data = { memberId };
23
+ const results = await Promise.all([
24
+ client.agentMember.updateMany({
25
+ where: { email, memberId: null },
26
+ data,
27
+ }),
28
+ client.chatThreadWatch.updateMany({
29
+ where: { userEmail: email, memberId: null },
30
+ data,
31
+ }),
32
+ client.pushSubscription.updateMany({
33
+ where: { userEmail: email, memberId: null },
34
+ data,
35
+ }),
36
+ client.userNotificationPrefs.updateMany({
37
+ where: { userEmail: email, memberId: null },
38
+ data,
39
+ }),
40
+ ]);
41
+ return results.reduce((n, r) => n + r.count, 0);
42
+ }