# v403 — Notification scheduler webhook execution hardening

Current baseline after package generation: v403.

This package reviewed v402 and continued the notification delivery track. It adds a protected scheduler/webhook execution layer for notification email digests while keeping normal users inside Workspace Settings > Notifications and keeping provider setup in Workspace Integrations.

## Product changes

- Added `GET` health/readiness and `POST` guarded execution for `/api/app-notifications/email-digest/scheduler`.
- Protected scheduler execution with `DISPATCH_SPOT_NOTIFICATION_DIGEST_WEBHOOK_SECRET`.
- Kept automatic sends locked unless `DISPATCH_SPOT_NOTIFICATION_AUTO_DIGEST_ENABLED=true`.
- Added dry-run support for scheduler POST checks; GET reports scheduler readiness only and does not send.
- Limited scheduler scans by organization and users per organization.
- Scheduler execution only targets active workspace users who have saved email digest/alert choices.
- Scheduler execution reuses existing digest guards:
  - no empty digest sends
  - no duplicate pending sends
  - no recent repeated sends
  - no repeated daily team digest
  - connected company email required
- Manual trigger checks in Workspace Settings now report readiness only; they do not auto-send even if automation is enabled.
- Added scheduler/webhook readiness wording to the existing Scheduled digest plan.
- Reused existing `OutboundEmailLog` records and metadata.
- Kept `/notifications` alert/action-only.
- Kept provider setup in `/company/integrations`.

## Environment variables

- `DISPATCH_SPOT_NOTIFICATION_AUTO_DIGEST_ENABLED=true` enables guarded automatic digest sending.
- `DISPATCH_SPOT_NOTIFICATION_DIGEST_WEBHOOK_SECRET=<strong random secret>` is required before scheduler/webhook execution can run.
- Cron/webhook callers should send the secret with either:
  - `x-dispatchspot-scheduler-secret`
  - `Authorization: Bearer <secret>`

## Scheduler request examples

Dry run:

```bash
curl -X POST "https://app.dispatchspot.com/api/app-notifications/email-digest/scheduler" \
  -H "x-dispatchspot-scheduler-secret: $DISPATCH_SPOT_NOTIFICATION_DIGEST_WEBHOOK_SECRET" \
  -H "Content-Type: application/json" \
  -d '{"dryRun":true,"maxOrganizations":5,"maxUsersPerOrganization":10}'
```

Guarded execution:

```bash
curl -X POST "https://app.dispatchspot.com/api/app-notifications/email-digest/scheduler" \
  -H "x-dispatchspot-scheduler-secret: $DISPATCH_SPOT_NOTIFICATION_DIGEST_WEBHOOK_SECRET" \
  -H "Content-Type: application/json" \
  -d '{"maxOrganizations":5,"maxUsersPerOrganization":10}'
```

## Placement confirmation

- `/notifications` remains an operational alert/action page only.
- Workspace Settings > Notifications remains the home for digest controls, readiness wording, and user notification preferences.
- Workspace Integrations remains the home for SMTP/provider setup.
- Scheduler secret configuration is server environment setup, not a normal user control.

## Prisma impact

No Prisma schema changes were made.
