# v367 - CORI Mail schema-backed storage and Workspace Integrations foundation

## Purpose

v367 moves CORI Mail from interface-only planning into schema-backed memory planning and adds a new Workspace Settings page for third-party integrations.

The goal is to keep the user-facing experience simple while preparing the platform to safely connect real outside services behind the scenes.

## What changed

- Added Prisma schema models for workspace integration provider accounts.
- Added Prisma schema models for CORI Mail drafts.
- Added Prisma schema models for CORI Mail email-to-work actions.
- Added Prisma schema models for CORI Mail send audit records.
- Added encrypted secret payload support for provider accounts.
- Added backend services and API routes for:
  - workspace integration overview
  - provider account listing and save foundation
  - CORI Mail persistence summary
  - CORI Mail draft persistence
  - CORI Mail work action persistence
  - CORI Mail send audit staging
- Added a new Workspace Settings page:

`/company/integrations`

- Added left-sidebar navigation for **Third-Party Integrations** under Workspace.
- Added integration tabs for:
  - Email
  - Google Maps API
  - Twilio
  - QuickBooks API
  - Stripe Connect
  - Other APIs
- Added a simple custom domain SMTP setup flow inside Workspace Integrations.
- Updated CORI Mail with visible database-memory cards for saved provider accounts, stored drafts, work cards, and send records.
- Added a direct link from CORI Mail to Workspace Integrations.
- Added new environment placeholders for workspace integration storage and future API providers.

## Simple user-facing rule

Users should not need to understand OAuth, API keys, SMTP, webhooks, or tokens during daily dispatch work.

Those details belong in Workspace Settings. The main work pages should show only the useful result, the warning, or the next step.

## Security rule

Provider passwords, API keys, OAuth tokens, and SMTP passwords must not become browser memory as the final store.

They must be saved as encrypted server-side secret payloads using the integration secret vault.

## Prisma impact

v367 includes Prisma schema changes.

Deployment requires:

```bash
npx prisma generate
npx prisma db push
```

before TypeScript and Next build checks.

## Recommended next step

After v367 is verified, continue by connecting the new integrations page more deeply to CORI Mail and the phone/route/accounting setup paths.

The most useful next move is to add real connection test flows for Custom SMTP and Twilio readiness while keeping live sending and live calling guarded.
