Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add customized notification settings for each user
Marc Seitz25d294b0e5c2
diff --git a/ee/features/access-notifications/lib/report-denied-access-attempt.ts b/ee/features/access-notifications/lib/report-denied-access-attempt.tsindex 2fa7a422..9591beb1 100644--- a/ee/features/access-notifications/lib/report-denied-access-attempt.ts+++ b/ee/features/access-notifications/lib/report-denied-access-attempt.ts@@ -35,23 +35,15 @@ export async function reportDeniedAccessAttempt(const linkName = link.name || `Link #${link.id?.slice(-5)}`;const timestamp = new Date().toLocaleString();- const { immediate } = await dispatchNotification({+ const recipients = await dispatchNotification({teamId: link.teamId,notificationType: "BLOCKED_ACCESS",linkOwnerId: link.ownerId,documentOwnerId,- digestPayload: {- blockedEmail: email,- linkName,- resourceName,- resourceType,- timestamp,- accessType,- },});- if (immediate.length > 0) {- const [to, ...cc] = immediate.map((r) => r.email);+ if (recipients.length > 0) {+ const [to, ...cc] = recipients.map((r) => r.email);await sendBlockedEmailAttemptNotification({to,cc: cc.length > 0 ? cc : undefined,diff --git a/lib/notifications/dispatch.ts b/lib/notifications/dispatch.tsindex 245763e9..77f96670 100644--- a/lib/notifications/dispatch.ts+++ b/lib/notifications/dispatch.ts@@ -1,57 +1,25 @@import type { TeamNotificationType } from "@/lib/zod/schemas/notifications";-import { queueDigestNotifications } from "./queue-digest";import {type NotificationRecipient,resolveRecipients,} from "./resolve-recipients";-export type DispatchResult = {- immediate: NotificationRecipient[];- queued: NotificationRecipient[];-};-export async function dispatchNotification({teamId,notificationType,linkOwnerId,documentOwnerId,- digestPayload,}: {teamId: string;notificationType: TeamNotificationType;linkOwnerId?: string | null;documentOwnerId?: string | null;- digestPayload: Record<string, unknown>;-}): Promise<DispatchResult> {- const recipients = await resolveRecipients({+}): Promise<NotificationRecipient[]> {+ return resolveRecipients({teamId,notificationType,linkOwnerId,documentOwnerId,});-- const immediate: NotificationRecipient[] = [];- const queued: NotificationRecipient[] = [];-- for (const recipient of recipients) {- if (recipient.frequency === "IMMEDIATE") {- immediate.push(recipient);- } else {- queued.push(recipient);- }- }-- if (queued.length > 0) {- await queueDigestNotifications(- queued.map((r) => ({- userId: r.userId,- teamId,- type: notificationType,- payload: digestPayload,- })),- );- }-- return { immediate, queued };}diff --git a/lib/notifications/resolve-recipients.ts b/lib/notifications/resolve-recipients.tsindex 202c678c..dd032b0b 100644--- a/lib/notifications/resolve-recipients.ts+++ b/lib/notifications/resolve-recipients.ts@@ -4,14 +4,14 @@ import prisma from "@/lib/prisma";import {DEFAULT_ADMIN_PREFERENCES,DEFAULT_MEMBER_PREFERENCES,- type TeamNotificationFrequency,+ type TeamNotificationScope,type TeamNotificationType,} from "@/lib/zod/schemas/notifications";export type NotificationRecipient = {userId: string;email: string;- frequency: TeamNotificationFrequency;+ scope: TeamNotificationScope;role: Role;};@@ -62,24 +62,37 @@ export async function resolveRecipients({},});- const prefMap = new Map(preferences.map((p) => [p.userId, p.frequency]));+ const prefMap = new Map(+ preferences.map((p) => [+ p.userId,+ { frequency: p.frequency, scope: p.scope },+ ]),+ );return eligibleMembers.map((member) => {- const storedFrequency = prefMap.get(member.userId);+ const stored = prefMap.get(member.userId);const defaultPrefs =member.role === "MEMBER"? DEFAULT_MEMBER_PREFERENCES: DEFAULT_ADMIN_PREFERENCES;- const frequency = (storedFrequency ??- defaultPrefs[notificationType]) as TeamNotificationFrequency;+ const defaults = defaultPrefs[notificationType];++ const frequency = stored?.frequency ?? defaults.frequency;+ const scope = (stored?.scope ??+ defaults.scope) as TeamNotificationScope;return {userId: member.userId,email: member.user.email!,- frequency,+ enabled: frequency !== "NEVER",+ scope,role: member.role,};})- .filter((r) => r.email && r.frequency !== "NEVER");+ .filter((r) => {+ if (!r.email || !r.enabled) return false;+ if (r.scope === "MINE_ONLY" && !ownerIds.has(r.userId)) return false;+ return true;+ });}diff --git a/lib/swr/use-notification-preferences.ts b/lib/swr/use-notification-preferences.tsindex afaef2b5..b9dc7d0c 100644--- a/lib/swr/use-notification-preferences.ts+++ b/lib/swr/use-notification-preferences.ts@@ -3,12 +3,18 @@ import useSWR from "swr";import type {TeamNotificationFrequency,+ TeamNotificationScope,TeamNotificationType,} from "@/lib/zod/schemas/notifications";import { fetcher } from "@/lib/utils";+export type PreferenceEntry = {+ frequency: TeamNotificationFrequency;+ scope: TeamNotificationScope;+};+interface NotificationPreferencesResponse {- preferences: Record<TeamNotificationType, TeamNotificationFrequency>;+ preferences: Record<TeamNotificationType, PreferenceEntry>;role: string;}@@ -17,17 +23,17 @@ export function useNotificationPreferences() {const teamId = teamInfo?.currentTeam?.id;const { data, error, mutate } = useSWR<NotificationPreferencesResponse>(- teamId- ? `/api/teams/${teamId}/notifications/preferences`- : null,+ teamId ? `/api/teams/${teamId}/notifications/preferences` : null,fetcher,- {- dedupingInterval: 10000,- },+ { dedupingInterval: 10000 },);const updatePreferences = async (- preferences: { type: TeamNotificationType; frequency: TeamNotificationFrequency }[],+ preferences: {+ type: TeamNotificationType;+ frequency: TeamNotificationFrequency;+ scope?: TeamNotificationScope;+ }[],) => {if (!teamId) return;@@ -45,7 +51,13 @@ export function useNotificationPreferences() {}const result = await response.json();- mutate({ ...data, preferences: result.preferences } as NotificationPreferencesResponse, false);+ mutate(+ {+ ...data,+ preferences: result.preferences,+ } as NotificationPreferencesResponse,+ false,+ );return result;};diff --git a/lib/trigger/dataroom-upload-notification.ts b/lib/trigger/dataroom-upload-notification.tsindex 0117761e..20f65b5b 100644--- a/lib/trigger/dataroom-upload-notification.ts+++ b/lib/trigger/dataroom-upload-notification.ts@@ -70,28 +70,21 @@ export const sendDataroomUploadNotificationTask = task({const uploaderEmail = recentUploads[0]?.viewer?.email || null;const linkName = link?.name || `Link #${payload.linkId.slice(-5)}`;- const { immediate } = await dispatchNotification({+ const recipients = await dispatchNotification({teamId: payload.teamId,notificationType: "DATAROOM_UPLOAD",linkOwnerId: link?.ownerId,- digestPayload: {- dataroomId: payload.dataroomId,- dataroomName: dataroom.name,- uploaderEmail,- documentNames,- linkName,- },});- if (immediate.length === 0) {- logger.info("No immediate recipients for upload notification", {+ if (recipients.length === 0) {+ logger.info("No recipients for upload notification", {dataroomId: payload.dataroomId,});return;}- const primaryRecipient = immediate[0];- const ccRecipients = immediate.slice(1).map((r) => r.email);+ const primaryRecipient = recipients[0];+ const ccRecipients = recipients.slice(1).map((r) => r.email);try {const response = await fetch(diff --git a/lib/zod/schemas/notifications.ts b/lib/zod/schemas/notifications.tsindex 3e90c293..ce9972ca 100644--- a/lib/zod/schemas/notifications.ts+++ b/lib/zod/schemas/notifications.ts@@ -49,44 +49,47 @@ export const TeamNotificationType = z.enum([export type TeamNotificationType = z.infer<typeof TeamNotificationType>;export const TEAM_NOTIFICATION_TYPES = TeamNotificationType.options;-export const TeamNotificationFrequency = z.enum([- "IMMEDIATE",- "DAILY",- "WEEKLY",- "NEVER",-]);+export const TeamNotificationFrequency = z.enum(["IMMEDIATE", "NEVER"]);export type TeamNotificationFrequency = z.infer<typeof TeamNotificationFrequency>;-export const TEAM_NOTIFICATION_FREQUENCIES = TeamNotificationFrequency.options;++export const TeamNotificationScope = z.enum(["ALL", "MINE_ONLY"]);+export type TeamNotificationScope = z.infer<typeof TeamNotificationScope>;export const ZNotificationPreferenceSchema = z.object({type: TeamNotificationType,frequency: TeamNotificationFrequency,+ scope: TeamNotificationScope.optional(),});export const ZUpdateNotificationPreferencesSchema = z.object({preferences: z.array(ZNotificationPreferenceSchema).min(1),});+export type NotificationPreferenceDefaults = {+ frequency: TeamNotificationFrequency;+ scope: TeamNotificationScope;+};+export const DEFAULT_ADMIN_PREFERENCES: Record<TeamNotificationType,- TeamNotificationFrequency+ NotificationPreferenceDefaults> = {- DOCUMENT_VIEW: "IMMEDIATE",- DATAROOM_VIEW: "IMMEDIATE",- BLOCKED_ACCESS: "IMMEDIATE",- DATAROOM_UPLOAD: "IMMEDIATE",- CONVERSATION_MESSAGE: "IMMEDIATE",+ DOCUMENT_VIEW: { frequency: "IMMEDIATE", scope: "ALL" },+ DATAROOM_VIEW: { frequency: "IMMEDIATE", scope: "ALL" },+ BLOCKED_ACCESS: { frequency: "IMMEDIATE", scope: "ALL" },+ DATAROOM_UPLOAD: { frequency: "IMMEDIATE", scope: "ALL" },+ CONVERSATION_MESSAGE: { frequency: "IMMEDIATE", scope: "ALL" },};export const DEFAULT_MEMBER_PREFERENCES: Record<TeamNotificationType,- TeamNotificationFrequency+ NotificationPreferenceDefaults> = {- DOCUMENT_VIEW: "IMMEDIATE",- DATAROOM_VIEW: "IMMEDIATE",- BLOCKED_ACCESS: "IMMEDIATE",- DATAROOM_UPLOAD: "IMMEDIATE",- CONVERSATION_MESSAGE: "NEVER",+ DOCUMENT_VIEW: { frequency: "IMMEDIATE", scope: "MINE_ONLY" },+ DATAROOM_VIEW: { frequency: "IMMEDIATE", scope: "MINE_ONLY" },+ BLOCKED_ACCESS: { frequency: "IMMEDIATE", scope: "MINE_ONLY" },+ DATAROOM_UPLOAD: { frequency: "IMMEDIATE", scope: "MINE_ONLY" },+ CONVERSATION_MESSAGE: { frequency: "NEVER", scope: "MINE_ONLY" },};diff --git a/pages/api/jobs/send-notification.ts b/pages/api/jobs/send-notification.tsindex 3b1da63f..f50142fd 100644--- a/pages/api/jobs/send-notification.ts+++ b/pages/api/jobs/send-notification.ts@@ -134,34 +134,22 @@ export default async function handle(: `${locationData.city}, ${locationData.country}`;try {- const { immediate } = await dispatchNotification({+ const recipients = await dispatchNotification({teamId,notificationType,linkOwnerId: view.link?.ownerId,documentOwnerId: view.document?.ownerId,- digestPayload: {- viewId,- viewType: view.viewType,- viewerEmail: view.viewerEmail,- linkId: view.linkId,- linkName,- documentId: view.document?.id,- documentName: view.document?.name,- dataroomId: view.dataroom?.id,- dataroomName: view.dataroom?.name,- locationString: includeLocation ? locationString : undefined,- },});- if (immediate.length === 0) {+ if (recipients.length === 0) {return res.status(200)- .json({ message: "No immediate recipients", viewId });+ .json({ message: "No recipients", viewId });}const teamIsPaused = await isTeamPausedById(teamId);- const primaryRecipient = immediate[0];- const ccRecipients = immediate+ const primaryRecipient = recipients[0];+ const ccRecipients = recipients.slice(1).map((r) => r.email);diff --git a/pages/api/teams/[teamId]/notifications/preferences.ts b/pages/api/teams/[teamId]/notifications/preferences.tsindex 2706e4fe..817107ec 100644--- a/pages/api/teams/[teamId]/notifications/preferences.ts+++ b/pages/api/teams/[teamId]/notifications/preferences.ts@@ -12,9 +12,29 @@ import {TEAM_NOTIFICATION_TYPES,ZUpdateNotificationPreferencesSchema,type TeamNotificationFrequency,+ type TeamNotificationScope,type TeamNotificationType,} from "@/lib/zod/schemas/notifications";+type PreferenceEntry = {+ frequency: TeamNotificationFrequency;+ scope: TeamNotificationScope;+};++function buildPreferencesMap(+ rows: { type: string; frequency: string; scope: string }[],+): Record<string, PreferenceEntry> {+ return Object.fromEntries(+ rows.map((p) => [+ p.type,+ {+ frequency: p.frequency as TeamNotificationFrequency,+ scope: p.scope as TeamNotificationScope,+ },+ ]),+ );+}+export default async function handle(req: NextApiRequest,res: NextApiResponse,@@ -45,7 +65,7 @@ export default async function handle(}if (req.method === "PUT") {- return handlePut(req, res, userId, teamId);+ return handlePut(req, res, userId, teamId, userTeam.role);}return res.status(405).json({ message: "Method Not Allowed" });@@ -63,7 +83,7 @@ async function handleGet() {let preferences = await prisma.notificationPreference.findMany({where: { userId, teamId },- select: { type: true, frequency: true },+ select: { type: true, frequency: true, scope: true },});if (preferences.length < TEAM_NOTIFICATION_TYPES.length) {@@ -77,7 +97,8 @@ async function handleGet(userId,teamId,type,- frequency: defaults[type as TeamNotificationType],+ frequency: defaults[type as TeamNotificationType].frequency,+ scope: defaults[type as TeamNotificationType].scope,}));if (missing.length > 0) {@@ -88,17 +109,13 @@ async function handleGet(preferences = await prisma.notificationPreference.findMany({where: { userId, teamId },- select: { type: true, frequency: true },+ select: { type: true, frequency: true, scope: true },});}}- const preferencesMap = Object.fromEntries(- preferences.map((p) => [p.type, p.frequency as TeamNotificationFrequency]),- );-return res.status(200).json({- preferences: preferencesMap,+ preferences: buildPreferencesMap(preferences),role,});}@@ -108,6 +125,7 @@ async function handlePut(res: NextApiResponse,userId: string,teamId: string,+ role: string,) {const validation = ZUpdateNotificationPreferencesSchema.safeParse(req.body);if (!validation.success) {@@ -117,10 +135,13 @@ async function handlePut(}const { preferences } = validation.data;+ const isMember = role === "MEMBER";await prisma.$transaction(- preferences.map((pref) =>- prisma.notificationPreference.upsert({+ preferences.map((pref) => {+ const scope = isMember ? "MINE_ONLY" : (pref.scope ?? "ALL");++ return prisma.notificationPreference.upsert({where: {userId_teamId_type: {userId,@@ -128,25 +149,25 @@ async function handlePut(type: pref.type,},},- update: { frequency: pref.frequency },+ update: {+ frequency: pref.frequency,+ scope,+ },create: {userId,teamId,type: pref.type,frequency: pref.frequency,+ scope,},- }),- ),+ });+ }),);const updated = await prisma.notificationPreference.findMany({where: { userId, teamId },- select: { type: true, frequency: true },+ select: { type: true, frequency: true, scope: true },});- const preferencesMap = Object.fromEntries(- updated.map((p) => [p.type, p.frequency as TeamNotificationFrequency]),- );-- return res.status(200).json({ preferences: preferencesMap });+ return res.status(200).json({ preferences: buildPreferencesMap(updated) });}diff --git a/pages/settings/notifications.tsx b/pages/settings/notifications.tsxindex 9b2d89c6..6cfaa43e 100644--- a/pages/settings/notifications.tsx+++ b/pages/settings/notifications.tsx@@ -8,9 +8,11 @@ import {} from "lucide-react";import { toast } from "sonner";-import { useNotificationPreferences } from "@/lib/swr/use-notification-preferences";+import {+ useNotificationPreferences,+} from "@/lib/swr/use-notification-preferences";import type {- TeamNotificationFrequency,+ TeamNotificationScope,TeamNotificationType,} from "@/lib/zod/schemas/notifications";@@ -24,19 +26,17 @@ import {SelectTrigger,SelectValue,} from "@/components/ui/select";+import { Switch } from "@/components/ui/switch";-const FREQUENCY_LABELS: Record<TeamNotificationFrequency, string> = {- IMMEDIATE: "Immediate",- DAILY: "Daily digest",- WEEKLY: "Weekly digest",- NEVER: "Off",+const SCOPE_LABELS: Record<TeamNotificationScope, string> = {+ ALL: "All activity",+ MINE_ONLY: "My links only",};type NotificationConfig = {type: TeamNotificationType;title: string;- descriptionAdmin: string;- descriptionMember: string;+ description: string;icon: React.ElementType;};@@ -52,8 +52,7 @@ const NOTIFICATION_CATEGORIES: NotificationCategory[] = [{type: "DOCUMENT_VIEW",title: "Document viewed",- descriptionAdmin: "When someone views any document link",- descriptionMember: "When someone views a document link you own",+ description: "When someone views a document link",icon: EyeIcon,},],@@ -64,19 +63,21 @@ const NOTIFICATION_CATEGORIES: NotificationCategory[] = [{type: "DATAROOM_VIEW",title: "Data room visited",- descriptionAdmin: "When someone visits any data room link",- descriptionMember: "When someone visits a data room link you own",+ description: "When someone visits a data room link",icon: ServerIcon,},{type: "DATAROOM_UPLOAD",title: "File uploaded",- descriptionAdmin:- "When a viewer uploads files to any data room",- descriptionMember:- "When a viewer uploads files to a data room you own",+ description: "When a viewer uploads files to a data room",icon: FileUpIcon,},+ {+ type: "CONVERSATION_MESSAGE",+ title: "New question",+ description: "When a new question is posted in a data room",+ icon: MessageSquareIcon,+ },],},{@@ -85,27 +86,11 @@ const NOTIFICATION_CATEGORIES: NotificationCategory[] = [{type: "BLOCKED_ACCESS",title: "Blocked access attempt",- descriptionAdmin: "When a viewer is denied access to any link",- descriptionMember:- "When a viewer is denied access to a link you own",+ description: "When a viewer is denied access to a link",icon: ShieldAlertIcon,},],},- {- label: "Conversations",- items: [- {- type: "CONVERSATION_MESSAGE",- title: "New message",- descriptionAdmin:- "When a new message is posted in any conversation",- descriptionMember:- "When a new message is posted in your conversations",- icon: MessageSquareIcon,- },- ],- },];export default function NotificationsSettings() {@@ -113,19 +98,34 @@ export default function NotificationsSettings() {useNotificationPreferences();const isMember = role === "MEMBER";+ const isAdminOrManager = role === "ADMIN" || role === "MANAGER";- const handleFrequencyChange = async (+ const handleToggle = async (type: TeamNotificationType,- frequency: TeamNotificationFrequency,+ enabled: boolean,) => {try {- await updatePreferences([{ type, frequency }]);+ await updatePreferences([+ { type, frequency: enabled ? "IMMEDIATE" : "NEVER" },+ ]);toast.success("Notification preference updated");} catch {toast.error("Failed to update notification preference");}};+ const handleScopeChange = async (+ type: TeamNotificationType,+ scope: TeamNotificationScope,+ ) => {+ try {+ await updatePreferences([{ type, frequency: "IMMEDIATE", scope }]);+ toast.success("Notification scope updated");+ } catch {+ toast.error("Failed to update notification scope");+ }+ };+return (<AppLayout><main className="relative mx-2 mb-10 mt-4 space-y-8 overflow-hidden px-1 sm:mx-3 md:mx-5 md:mt-5 lg:mx-7 lg:mt-8 xl:mx-10">@@ -136,8 +136,7 @@ export default function NotificationsSettings() {Notifications</h3><p className="text-sm text-muted-foreground">- Choose how and when you want to be notified about activity in this- team.+ Choose which email notifications you want to receive for this team.</p></div>@@ -146,8 +145,7 @@ export default function NotificationsSettings() {<InfoIcon className="h-4 w-4" /><AlertDescription>As a team member, you'll only receive notifications for- documents and links you own. Admins and managers receive- notifications for all team activity.+ documents and links you own.</AlertDescription></Alert>) : null}@@ -169,17 +167,26 @@ export default function NotificationsSettings() {{category.label}</h4><div className="divide-y rounded-lg border">- {category.items.map((item) => (- <NotificationRow- key={item.type}- item={item}- isMember={isMember}- frequency={preferences?.[item.type] ?? "IMMEDIATE"}- onFrequencyChange={(frequency) =>- handleFrequencyChange(item.type, frequency)- }- />- ))}+ {category.items.map((item) => {+ const pref = preferences?.[item.type];+ const enabled =+ (pref?.frequency ?? "IMMEDIATE") !== "NEVER";+ const scope = pref?.scope ?? "ALL";++ return (+ <NotificationRow+ key={item.type}+ item={item}+ isAdminOrManager={isAdminOrManager}+ enabled={enabled}+ scope={scope}+ onToggle={(val) => handleToggle(item.type, val)}+ onScopeChange={(s) =>+ handleScopeChange(item.type, s)+ }+ />+ );+ })}</div></div>))}@@ -192,19 +199,20 @@ export default function NotificationsSettings() {function NotificationRow({item,- isMember,- frequency,- onFrequencyChange,+ isAdminOrManager,+ enabled,+ scope,+ onToggle,+ onScopeChange,}: {item: NotificationConfig;- isMember: boolean;- frequency: TeamNotificationFrequency;- onFrequencyChange: (frequency: TeamNotificationFrequency) => void;+ isAdminOrManager: boolean;+ enabled: boolean;+ scope: TeamNotificationScope;+ onToggle: (enabled: boolean) => void;+ onScopeChange: (scope: TeamNotificationScope) => void;}) {const Icon = item.icon;- const description = isMember- ? item.descriptionMember- : item.descriptionAdmin;return (<div className="flex items-center justify-between gap-4 px-4 py-3">@@ -214,26 +222,31 @@ function NotificationRow({</div><div className="min-w-0"><p className="text-sm font-medium text-foreground">{item.title}</p>- <p className="text-xs text-muted-foreground">{description}</p>+ <p className="text-xs text-muted-foreground">{item.description}</p></div></div>- <Select- value={frequency}- onValueChange={(value) =>- onFrequencyChange(value as TeamNotificationFrequency)- }- >- <SelectTrigger className="w-[150px] shrink-0">- <SelectValue />- </SelectTrigger>- <SelectContent>- {Object.entries(FREQUENCY_LABELS).map(([value, label]) => (- <SelectItem key={value} value={value}>- {label}- </SelectItem>- ))}- </SelectContent>- </Select>+ <div className="flex items-center gap-3">+ {isAdminOrManager && enabled ? (+ <Select+ value={scope}+ onValueChange={(value) =>+ onScopeChange(value as TeamNotificationScope)+ }+ >+ <SelectTrigger className="w-[140px] shrink-0">+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ {Object.entries(SCOPE_LABELS).map(([value, label]) => (+ <SelectItem key={value} value={value}>+ {label}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ ) : null}+ <Switch checked={enabled} onCheckedChange={onToggle} />+ </div></div>);}diff --git a/prisma/migrations/20260331000000_add_notification_preferences/migration.sql b/prisma/migrations/20260331000000_add_notification_preferences/migration.sqlindex 70869b54..39e7783f 100644--- a/prisma/migrations/20260331000000_add_notification_preferences/migration.sql+++ b/prisma/migrations/20260331000000_add_notification_preferences/migration.sql@@ -5,37 +5,19 @@ CREATE TABLE "NotificationPreference" ("teamId" TEXT NOT NULL,"type" TEXT NOT NULL,"frequency" TEXT NOT NULL DEFAULT 'IMMEDIATE',+ "scope" TEXT NOT NULL DEFAULT 'ALL',"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,"updatedAt" TIMESTAMP(3) NOT NULL,CONSTRAINT "NotificationPreference_pkey" PRIMARY KEY ("id"));--- CreateTable-CREATE TABLE "NotificationDigest" (- "id" TEXT NOT NULL,- "userId" TEXT NOT NULL,- "teamId" TEXT NOT NULL,- "type" TEXT NOT NULL,- "payload" JSONB NOT NULL,- "processedAt" TIMESTAMP(3),- "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,-- CONSTRAINT "NotificationDigest_pkey" PRIMARY KEY ("id")-);--- CreateIndexCREATE UNIQUE INDEX "NotificationPreference_userId_teamId_type_key" ON "NotificationPreference"("userId", "teamId", "type");-- CreateIndexCREATE INDEX "NotificationPreference_userId_teamId_idx" ON "NotificationPreference"("userId", "teamId");--- CreateIndex-CREATE INDEX "NotificationDigest_userId_teamId_type_processedAt_idx" ON "NotificationDigest"("userId", "teamId", "type", "processedAt");---- CreateIndex-CREATE INDEX "NotificationDigest_createdAt_idx" ON "NotificationDigest"("createdAt");--- AddForeignKeyALTER TABLE "NotificationPreference" ADD CONSTRAINT "NotificationPreference_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;diff --git a/prisma/schema/notification.prisma b/prisma/schema/notification.prismaindex 14775dbc..a2af2662 100644--- a/prisma/schema/notification.prisma+++ b/prisma/schema/notification.prisma@@ -3,7 +3,8 @@ model NotificationPreference {userId StringteamId Stringtype String // "DOCUMENT_VIEW" | "DATAROOM_VIEW" | "BLOCKED_ACCESS" | "DATAROOM_UPLOAD" | "CONVERSATION_MESSAGE"- frequency String @default("IMMEDIATE") // "IMMEDIATE" | "DAILY" | "WEEKLY" | "NEVER"+ frequency String @default("IMMEDIATE") // "IMMEDIATE" | "NEVER"+ scope String @default("ALL") // "ALL" | "MINE_ONLY" — admins/managers choose; members always MINE_ONLYuser User @relation(fields: [userId], references: [id], onDelete: Cascade)team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)@@ -14,17 +15,3 @@ model NotificationPreference {@@unique([userId, teamId, type])@@index([userId, teamId])}--model NotificationDigest {- id String @id @default(cuid())- userId String- teamId String- type String // same values as NotificationPreference.type- payload Json-- processedAt DateTime?- createdAt DateTime @default(now())-- @@index([userId, teamId, type, processedAt])- @@index([createdAt])-}