# v400 — Notification Digest and Email-Trigger Behavior

Current baseline reviewed: v399.1.

v400 resumes the notification track after the v399.1 deployment hardening correction. The product goal is to add simple email digest/trigger behavior while keeping the placement rules intact.

## Decision

Continue with notification digest/email trigger behavior.

The notification settings placement rule remains higher priority than the feature itself:

- `/notifications` remains alert/action-only.
- Notification preferences stay in Workspace Settings > Notifications.
- Provider setup stays in Workspace Integrations.
- Normal users do not see SMTP credentials, provider diagnostics, raw delivery logs, or technical error dumps.

## Product changes

- Added `/api/app-notifications/email-digest`.
- Added a guarded notification email digest preview path.
- Added a guarded notification email send path.
- Added a **Email digest and triggers** panel inside Workspace Settings > Notifications.
- The new panel shows:
  - email choices enabled;
  - active alert count;
  - needs-attention count;
  - simple email delivery readiness;
  - preview lines before sending;
  - plain sent/failed/needs-setup status.
- Added simple trigger selection from the user’s existing notification preferences:
  - urgent alerts;
  - overdue or late work;
  - due-today checks;
  - daily team digest preference.
- Reused existing `OutboundEmailLog` records for digest send attempts.
- Sanitized send failures so the user sees action-oriented wording instead of raw provider output.
- Corrected remaining notification delivery readiness links/messages so user preference guidance points to Workspace Settings and provider setup points to Workspace Integrations.

## Placement and safety

The email digest panel lives in Workspace Settings > Notifications because it is a notification delivery management surface.

The user-facing `/notifications` page was not changed and remains for:

- active alerts;
- read/unread;
- hide/show again;
- work-record links.

It must not contain notification settings, opt-ins, phone capture, delivery setup, provider diagnostics, or test-send controls.

## What changed in code

- `app/api/app-notifications/email-digest/route.ts`
- `components/notifications/notification-email-digest-panel.tsx`
- `components/notifications/notification-delivery-panel.tsx`
- `app/(dashboard)/company/page.tsx`
- `src/modules/app-notifications/app-notification-delivery.service.ts`
- `types/index.ts`

## Prisma impact

No Prisma schema changes were made.

v400 uses existing `OutboundEmailLog` records for notification digest attempts.

## Deployment note

The WHM command must keep the v399.1 deployment hardening sequence:

1. visible unzip;
2. deploy cleanup;
3. preflight;
4. build;
5. post-build restart.

## Build validation

- `node scripts/dispatchspot-build-preflight.mjs` passed.
- Local Next build was not run in the sandbox because installed dependencies / `node_modules` are not included in the source package.

## Next recommendation

Review v400 in the browser, especially Workspace Settings > Notifications. Then continue notification delivery hardening with digest history/readiness polish, or return to another high-use operational surface.
