@app-vitals/agent-admin 1.112.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.
Files changed (34) hide show
  1. package/e2e/real/member-agents.real.e2e.ts +8 -4
  2. package/package.json +2 -2
  3. package/prisma/client/browser.ts +2 -2
  4. package/prisma/client/client.ts +2 -2
  5. package/prisma/client/internal/class.ts +7 -7
  6. package/prisma/client/internal/prismaNamespace.ts +39 -39
  7. package/prisma/client/internal/prismaNamespaceBrowser.ts +3 -3
  8. package/prisma/client/models/UserPrefs.ts +1249 -0
  9. package/prisma/client/models.ts +1 -1
  10. package/prisma/schema/schema.prisma +2 -2
  11. package/src/account-member-removal.integration.test.ts +5 -5
  12. package/src/account-members.ts +2 -2
  13. package/src/account-move.integration.test.ts +4 -4
  14. package/src/account-move.ts +1 -1
  15. package/src/admin-boot.ts +15 -6
  16. package/src/admin-extension.ts +10 -1
  17. package/src/admin-ui-agent-members.smoke.test.ts +1 -1
  18. package/src/admin-ui-layout.ts +2 -0
  19. package/src/admin-ui-preferences-pages.ts +79 -0
  20. package/src/admin-ui-preferences.smoke.test.ts +168 -0
  21. package/src/admin-ui-preferences.ts +103 -0
  22. package/src/admin-ui-settings-layout.ts +12 -1
  23. package/src/admin-ui.ts +78 -12
  24. package/src/ensure-account-member.integration.test.ts +1 -1
  25. package/src/member-rows.ts +2 -2
  26. package/src/member-rows.unit.test.ts +2 -2
  27. package/src/test-support/member-id-test-support.ts +1 -1
  28. package/src/timezone-resolver.ts +88 -0
  29. package/src/timezone-resolver.unit.test.ts +127 -0
  30. package/src/user-prefs.integration.test.ts +5 -5
  31. package/src/user-prefs.ts +9 -12
  32. package/prisma/client/models/UserNotificationPrefs.ts +0 -1249
  33. package/src/user-notification-prefs.ts +0 -16
  34. package/src/user-notification-prefs.unit.test.ts +0 -9
package/src/admin-ui.ts CHANGED
@@ -54,8 +54,8 @@ import { registerAdminGithubEnterpriseRoutes } from "./admin-ui-github-enterpris
54
54
  import type { GheOrgs } from "./admin-ui-github-enterprise-pages.ts";
55
55
  import {
56
56
  type GithubUninstallPreviewView,
57
- renderGithubAccessError,
58
57
  MAX_INSTALL_REPOSITORIES,
58
+ renderGithubAccessError,
59
59
  renderGithubOrgsFragment,
60
60
  renderGithubUninstallConfirm,
61
61
  } from "./admin-ui-github-identity-pages.ts";
@@ -98,6 +98,7 @@ import {
98
98
  renderProvisionXappTokenPage,
99
99
  settingsRedirectSection,
100
100
  } from "./admin-ui-pages.ts";
101
+ import { registerAdminPreferencesRoutes } from "./admin-ui-preferences.ts";
101
102
  import {
102
103
  buildSettingsNav,
103
104
  filterSettingsNavForRole,
@@ -208,12 +209,20 @@ import {
208
209
  type SpecialtyTypeResolver,
209
210
  SpecialtyTypes,
210
211
  } from "./specialty-types.ts";
212
+ import {
213
+ createTimezoneResolver,
214
+ DEFAULT_TIMEZONE,
215
+ TIMEZONE_COOKIE,
216
+ } from "./timezone-resolver.ts";
217
+ import type { UserPrefsService } from "./user-prefs.ts";
211
218
 
212
219
  export type AdminUIEnv = {
213
220
  Variables: {
214
221
  userEmail: string;
215
222
  isAdmin: boolean;
216
223
  settingsNav?: SettingsNav;
224
+ /** Display timezone resolved for this request (user, cookie, default). */
225
+ timezone?: string;
217
226
  };
218
227
  };
219
228
 
@@ -590,6 +599,13 @@ export interface AdminUIDeps {
590
599
  * Defaults to "America/Los_Angeles" when absent.
591
600
  */
592
601
  timezone?: string;
602
+ /**
603
+ * Per-user preferences store. When present (with `accountServices`), the
604
+ * display timezone is resolved per request from the user's saved setting,
605
+ * then the browser `tz` cookie, then `timezone`, and Settings > Preferences
606
+ * is registered. Absent: the fixed `timezone` is used for every request.
607
+ */
608
+ userPrefs?: Pick<UserPrefsService, "getTimezone" | "upsertByMemberId">;
593
609
  /**
594
610
  * Extra `?error=` codes (code → message) an extension's routes redirect to
595
611
  * the agent detail page with — merged over the platform's own codes.
@@ -1027,7 +1043,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
1027
1043
  githubAppClient,
1028
1044
  appBaseUrl,
1029
1045
  devAuthEnabled = false,
1030
- timezone = "America/Los_Angeles",
1046
+ timezone: deploymentTimezone,
1031
1047
  chatClient,
1032
1048
  pwaAssetsDir = PWA_ASSETS_DIR,
1033
1049
  appVersion = "0.0.0",
@@ -1041,6 +1057,10 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
1041
1057
  // toggle-render gate and the route-503 gate can't drift.
1042
1058
  const pushEnabled = Boolean(pushService && vapidPublicKey);
1043
1059
 
1060
+ // Fixed display timezone for requests the per-request resolver does not
1061
+ // cover (and the deployment default it falls back to).
1062
+ const timezone = deploymentTimezone ?? DEFAULT_TIMEZONE;
1063
+
1044
1064
  const app = new Hono<AdminUIEnv>();
1045
1065
 
1046
1066
  const requireAuth = createUIAuthMiddleware(sessionSecret, {
@@ -1050,12 +1070,19 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
1050
1070
  });
1051
1071
 
1052
1072
  const accountNavEnabled = accountServices !== undefined;
1073
+ const preferencesEnabled = Boolean(deps.userPrefs && accountServices);
1074
+ const resolveRequestTimezone = createTimezoneResolver({
1075
+ ...(deps.userPrefs ? { userPrefs: deps.userPrefs } : {}),
1076
+ ...(accountServices ? { members: accountServices.members } : {}),
1077
+ deployment: timezone,
1078
+ });
1053
1079
 
1054
1080
  const settingsNav = buildSettingsNav({
1055
1081
  githubEnterprise: Boolean(githubEnterpriseApi),
1056
1082
  templates: Boolean(templateService),
1057
1083
  slackConfigToken: Boolean(slackConfigToken),
1058
1084
  accounts: accountNavEnabled,
1085
+ preferences: preferencesEnabled,
1059
1086
  extraItems: deps.settingsNavItems ?? [],
1060
1087
  });
1061
1088
 
@@ -1092,12 +1119,32 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
1092
1119
  await next();
1093
1120
  });
1094
1121
 
1122
+ // Per-request display timezone: the user's saved setting, then the tz
1123
+ // cookie, then the deployment default. Only when preferences are wired;
1124
+ // otherwise handlers fall back to the fixed timezone.
1125
+ if (preferencesEnabled) {
1126
+ app.use("/admin/*", async (c, next) => {
1127
+ const token = getCookie(c, SESSION_COOKIE);
1128
+ const user = token ? await getSessionUser(token, sessionSecret) : null;
1129
+ c.set(
1130
+ "timezone",
1131
+ await resolveRequestTimezone({
1132
+ email: user?.email,
1133
+ cookie: getCookie(c, TIMEZONE_COOKIE),
1134
+ }),
1135
+ );
1136
+ await next();
1137
+ });
1138
+ }
1139
+ const tzOf = (c: Context<AdminUIEnv>): string => c.var.timezone ?? timezone;
1140
+
1095
1141
  // GHE-1.4: per-request toolbar audience; TOOLBAR_NAV_ITEMS decides visibility.
1096
1142
  if (
1097
1143
  githubEnterpriseApi ||
1098
1144
  templateService ||
1099
1145
  slackConfigToken ||
1100
- accountNavEnabled
1146
+ accountNavEnabled ||
1147
+ preferencesEnabled
1101
1148
  ) {
1102
1149
  app.use("/admin/*", async (c, next) => {
1103
1150
  const token = getCookie(c, SESSION_COOKIE);
@@ -1652,7 +1699,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
1652
1699
  );
1653
1700
  }
1654
1701
  return html(
1655
- renderAgentsPage(agents, c.var.userEmail, c.var.isAdmin, timezone, {
1702
+ renderAgentsPage(agents, c.var.userEmail, c.var.isAdmin, tzOf(c), {
1656
1703
  accountNames,
1657
1704
  queueActivityLinks: deps.queueActivityLinks,
1658
1705
  successMsg,
@@ -2510,7 +2557,12 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
2510
2557
  }
2511
2558
  }
2512
2559
  }
2513
- return html(renderInstallationReposBody(view, { appIdMismatch, timezone }));
2560
+ return html(
2561
+ renderInstallationReposBody(view, {
2562
+ appIdMismatch,
2563
+ timezone: tzOf(c),
2564
+ }),
2565
+ );
2514
2566
  });
2515
2567
 
2516
2568
  // IRM-3.2: the single Sync confirm (over the IRM-3.1 preview) and its apply.
@@ -2528,7 +2580,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
2528
2580
  renderSyncConfirm(
2529
2581
  c.req.param("id") ?? "",
2530
2582
  (await res.json()) as GithubSyncPreviewView,
2531
- timezone,
2583
+ tzOf(c),
2532
2584
  ),
2533
2585
  );
2534
2586
  });
@@ -2598,7 +2650,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
2598
2650
  warnings,
2599
2651
  )
2600
2652
  : [],
2601
- timezone,
2653
+ tzOf(c),
2602
2654
  ),
2603
2655
  );
2604
2656
  },
@@ -2785,7 +2837,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
2785
2837
  userEmail: c.var.userEmail,
2786
2838
  isAdmin: c.var.isAdmin,
2787
2839
  accountId: agent.accountId ?? null,
2788
- timezone,
2840
+ timezone: tzOf(c),
2789
2841
  },
2790
2842
  );
2791
2843
 
@@ -2847,7 +2899,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
2847
2899
  newToken,
2848
2900
  successMsg,
2849
2901
  warning,
2850
- timezone,
2902
+ timezone: tzOf(c),
2851
2903
  extensionCardsHtml: cards.header,
2852
2904
  configurationCardsHtml: cards.configuration,
2853
2905
  queueActivityLinks: deps.queueActivityLinks,
@@ -3859,7 +3911,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
3859
3911
  userEmail: c.var.userEmail,
3860
3912
  isAdmin: c.var.isAdmin,
3861
3913
  accountId: agent.accountId ?? null,
3862
- timezone,
3914
+ timezone: tzOf(c),
3863
3915
  },
3864
3916
  ["configuration"],
3865
3917
  );
@@ -3878,7 +3930,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
3878
3930
  section: "access",
3879
3931
  canManage,
3880
3932
  newToken: rawToken,
3881
- timezone,
3933
+ timezone: tzOf(c),
3882
3934
  extensionCardsHtml: cards.header,
3883
3935
  configurationCardsHtml: cards.configuration,
3884
3936
  queueActivityLinks: deps.queueActivityLinks,
@@ -4696,7 +4748,8 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
4696
4748
  githubEnterpriseApi ||
4697
4749
  templateService ||
4698
4750
  slackConfigToken ||
4699
- accountNavEnabled
4751
+ accountNavEnabled ||
4752
+ preferencesEnabled
4700
4753
  ) {
4701
4754
  app.get("/admin/settings", requireAuth, async (c) => {
4702
4755
  // Admins without an account would 404 on the Account item; skip it.
@@ -4771,6 +4824,19 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
4771
4824
  });
4772
4825
  }
4773
4826
 
4827
+ // ─── Preferences (per-user display timezone) ─────────────────────────────
4828
+
4829
+ if (deps.userPrefs && accountServices) {
4830
+ registerAdminPreferencesRoutes(app, {
4831
+ requireAuth,
4832
+ userPrefs: deps.userPrefs,
4833
+ members: accountServices.members,
4834
+ settingsNav,
4835
+ effectiveTimezone: (c) => c.var.timezone ?? timezone,
4836
+ html,
4837
+ });
4838
+ }
4839
+
4774
4840
  // ─── Account page (SSP-3.2) ───────────────────────────────────────────────
4775
4841
 
4776
4842
  if (accountServices) {
@@ -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();
@@ -0,0 +1,88 @@
1
+ /**
2
+ * admin/src/timezone-resolver.ts
3
+ * Per-request display timezone: the signed-in user's saved setting, then the
4
+ * browser-set `tz` cookie, then the deployment default. An invalid value at
5
+ * any level falls through to the next; nothing here throws.
6
+ */
7
+
8
+ import type { AccountMemberService } from "./account-members.ts";
9
+ import { isValidIanaTimezone, type UserPrefsService } from "./user-prefs.ts";
10
+
11
+ /** Used when neither the user, the cookie nor the deployment supplies a zone. */
12
+ export const DEFAULT_TIMEZONE = "America/Los_Angeles";
13
+
14
+ export const TIMEZONE_COOKIE = "tz";
15
+
16
+ export interface TimezoneSources {
17
+ /** The user's saved setting. */
18
+ user?: string | null;
19
+ /** The browser-reported zone from the tz cookie. */
20
+ cookie?: string | null;
21
+ /** The deployment default (SHIPWRIGHT_ADMIN_TZ). */
22
+ deployment?: string | null;
23
+ }
24
+
25
+ const usable = (tz: string | null | undefined): tz is string =>
26
+ typeof tz === "string" && isValidIanaTimezone(tz);
27
+
28
+ /** First valid of user, cookie, deployment; else the built-in default. */
29
+ export function resolveTimezone(src: TimezoneSources): string {
30
+ for (const tz of [src.user, src.cookie, src.deployment]) {
31
+ if (usable(tz)) return tz;
32
+ }
33
+ return DEFAULT_TIMEZONE;
34
+ }
35
+
36
+ /** The decoded tz cookie from a Cookie header, if present and well-formed. */
37
+ export function parseTzCookie(header: string | null | undefined) {
38
+ if (!header) return undefined;
39
+ for (const part of header.split(";")) {
40
+ const eq = part.indexOf("=");
41
+ if (eq < 0 || part.slice(0, eq).trim() !== TIMEZONE_COOKIE) continue;
42
+ try {
43
+ return decodeURIComponent(part.slice(eq + 1).trim());
44
+ } catch {
45
+ return undefined;
46
+ }
47
+ }
48
+ return undefined;
49
+ }
50
+
51
+ export interface TimezoneResolverDeps {
52
+ userPrefs?: Pick<UserPrefsService, "getTimezone">;
53
+ members?: Pick<AccountMemberService, "getByEmail">;
54
+ /** Deployment default; invalid or absent falls to DEFAULT_TIMEZONE. */
55
+ deployment?: string | null;
56
+ }
57
+
58
+ export type TimezoneResolver = (input: {
59
+ email?: string | undefined;
60
+ cookie?: string | undefined;
61
+ }) => Promise<string>;
62
+
63
+ /** Async resolver that looks up the user's saved setting by signed-in email. */
64
+ export function createTimezoneResolver(
65
+ deps: TimezoneResolverDeps,
66
+ ): TimezoneResolver {
67
+ return async ({ email, cookie }) => {
68
+ let user: string | null = null;
69
+ if (email && deps.userPrefs && deps.members) {
70
+ try {
71
+ const member = await deps.members.getByEmail(email);
72
+ if (member) user = await deps.userPrefs.getTimezone(member.id);
73
+ } catch {
74
+ // a failed lookup falls through to the cookie
75
+ }
76
+ }
77
+ return resolveTimezone({ user, cookie, deployment: deps.deployment });
78
+ };
79
+ }
80
+
81
+ /**
82
+ * Small inline script: records the browser's IANA zone in the tz cookie (one
83
+ * year, site-wide). The resolver ignores the cookie when the user has a saved
84
+ * setting, so it is safe to set unconditionally.
85
+ */
86
+ export function tzCookieScript(): string {
87
+ return `<script>(function(){try{var z=Intl.DateTimeFormat().resolvedOptions().timeZone;if(!z)return;var e=encodeURIComponent(z);if(document.cookie.split("; ").indexOf("tz="+e)>=0)return;document.cookie="tz="+e+"; path=/; max-age=31536000; SameSite=Lax"}catch(_){}})();</script>`;
88
+ }
@@ -0,0 +1,127 @@
1
+ /**
2
+ * admin/src/timezone-resolver.unit.test.ts
3
+ * Per-request display timezone: user setting, then tz cookie, then deployment
4
+ * default; an invalid value at any level falls through.
5
+ */
6
+
7
+ import { describe, expect, it } from "bun:test";
8
+ import {
9
+ createTimezoneResolver,
10
+ DEFAULT_TIMEZONE,
11
+ parseTzCookie,
12
+ resolveTimezone,
13
+ tzCookieScript,
14
+ } from "./timezone-resolver.ts";
15
+
16
+ describe("resolveTimezone", () => {
17
+ it("prefers the user setting", () => {
18
+ expect(
19
+ resolveTimezone({
20
+ user: "Europe/Paris",
21
+ cookie: "Asia/Tokyo",
22
+ deployment: "UTC",
23
+ }),
24
+ ).toBe("Europe/Paris");
25
+ });
26
+
27
+ it("uses the cookie when there is no user setting", () => {
28
+ expect(
29
+ resolveTimezone({ user: null, cookie: "Asia/Tokyo", deployment: "UTC" }),
30
+ ).toBe("Asia/Tokyo");
31
+ });
32
+
33
+ it("uses the deployment default when neither is set", () => {
34
+ expect(resolveTimezone({ deployment: "UTC" })).toBe("UTC");
35
+ });
36
+
37
+ it("falls back to the built-in default last", () => {
38
+ expect(resolveTimezone({})).toBe(DEFAULT_TIMEZONE);
39
+ expect(DEFAULT_TIMEZONE).toBe("America/Los_Angeles");
40
+ });
41
+
42
+ it("falls through an invalid user setting to the cookie", () => {
43
+ expect(resolveTimezone({ user: "Not/AZone", cookie: "Asia/Tokyo" })).toBe(
44
+ "Asia/Tokyo",
45
+ );
46
+ });
47
+
48
+ it("falls through an invalid cookie to the deployment default", () => {
49
+ expect(resolveTimezone({ cookie: "bogus", deployment: "UTC" })).toBe("UTC");
50
+ });
51
+
52
+ it("falls through an invalid deployment default without throwing", () => {
53
+ expect(resolveTimezone({ user: "x", cookie: "y", deployment: "z" })).toBe(
54
+ DEFAULT_TIMEZONE,
55
+ );
56
+ });
57
+ });
58
+
59
+ describe("parseTzCookie", () => {
60
+ it("reads and decodes the tz cookie", () => {
61
+ expect(parseTzCookie("a=1; tz=America%2FChicago; b=2")).toBe(
62
+ "America/Chicago",
63
+ );
64
+ });
65
+ it("returns undefined when absent or malformed", () => {
66
+ expect(parseTzCookie(undefined)).toBeUndefined();
67
+ expect(parseTzCookie("a=1")).toBeUndefined();
68
+ expect(parseTzCookie("tz=%E0%A4%A")).toBeUndefined();
69
+ });
70
+ });
71
+
72
+ describe("createTimezoneResolver", () => {
73
+ const members = {
74
+ getByEmail: async (e: string) =>
75
+ e === "m@acme.com" ? ({ id: "mem-1" } as never) : null,
76
+ };
77
+
78
+ it("resolves the stored setting by the member's id", async () => {
79
+ const resolve = createTimezoneResolver({
80
+ userPrefs: { getTimezone: async (id) => (id === "mem-1" ? "UTC" : null) },
81
+ members,
82
+ deployment: "Asia/Tokyo",
83
+ });
84
+ expect(await resolve({ email: "m@acme.com", cookie: "Europe/Paris" })).toBe(
85
+ "UTC",
86
+ );
87
+ });
88
+
89
+ it("uses the cookie for a member with nothing saved", async () => {
90
+ const resolve = createTimezoneResolver({
91
+ userPrefs: { getTimezone: async () => null },
92
+ members,
93
+ });
94
+ expect(await resolve({ email: "m@acme.com", cookie: "Europe/Paris" })).toBe(
95
+ "Europe/Paris",
96
+ );
97
+ });
98
+
99
+ it("falls through when the lookup throws or the email is unknown", async () => {
100
+ const boom = createTimezoneResolver({
101
+ userPrefs: {
102
+ getTimezone: async () => {
103
+ throw new Error("db down");
104
+ },
105
+ },
106
+ members,
107
+ deployment: "UTC",
108
+ });
109
+ expect(await boom({ email: "m@acme.com" })).toBe("UTC");
110
+ expect(await boom({ email: "nobody@acme.com" })).toBe("UTC");
111
+ expect(await boom({})).toBe("UTC");
112
+ });
113
+
114
+ it("works with no stores at all", async () => {
115
+ const resolve = createTimezoneResolver({});
116
+ expect(await resolve({ cookie: "UTC" })).toBe("UTC");
117
+ });
118
+ });
119
+
120
+ describe("tzCookieScript", () => {
121
+ it("is a script tag that sets the tz cookie from Intl", () => {
122
+ const s = tzCookieScript();
123
+ expect(s.startsWith("<script>")).toBe(true);
124
+ expect(s).toContain("resolvedOptions().timeZone");
125
+ expect(s).toContain("tz=");
126
+ });
127
+ });
@@ -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(