9 Commits

Author SHA1 Message Date
37ce7a44da merge: Svix webhooks, webhooks/suppressions/logs APIs (round 1b)
Request-log middleware registered before all routes; API log cleanup
job started at boot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 04:10:40 +03:00
b510307eb5 feat: A3/A4 — Svix webhook signing, public webhooks API, suppressions, and API logs
A3 — Webhook Svix signing + public webhooks API:
- Add `WebhookSignatureFormat` support: new webhooks default to SVIX; existing
  USESEND format unchanged
- `svixSign()`: HMAC-SHA256 keyed on base64-decoded whsec_ secret; produces
  `v1,{base64}` signature in `svix-id/timestamp/signature` headers (with
  webhook-* aliases for Resend SDK compat)
- `generateSvixSecret()`: returns `whsec_<base64(32 random bytes)>`
- Secret rotation: previous secret valid for 24h; both sigs sent in
  `svix-signature` header (space-separated); expired previous secret excluded
- `toResendPayload()`: maps internal webhook payloads to Resend wire shape
  (email_id, created_at, bounce, click, open, suppression.added/removed, etc.)
- Public webhooks API: POST/GET list/GET id/PATCH/DELETE /webhooks,
  POST /webhooks/:id/signing-secret/rotate, GET /webhooks/:id/events
- 13 unit tests prove `resend.webhooks.verify()` and `standardwebhooks`
  accept our signatures; rotation and toResendPayload covered

A4 — Suppressions + API request logs:
- GET/POST/DELETE /suppressions (never deletes OCI tenancy-wide list)
- GET /logs, GET /logs/:id (cursor-paginated, Resend Log shape)
- `requestLogMiddleware`: fire-and-forget ApiRequestLog writes via
  queueMicrotask(); secrets redacted; 4096-char body cap; failures swallowed
- `api-log-cleanup-job`: daily BullMQ cron (00:30 UTC); env
  API_LOG_RETENTION_DAYS configurable; 0 disables retention enforcement
- 20 API-layer tests (webhooks, suppressions, logs)

Add `standardwebhooks` dev dependency for test verification.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-10-07 04:09:03 +03:00
6f39776933 feat: Wave 3 C1/C2 — inbound MX server and received email API
Adds Resend "Receiving emails" parity:

**C1 — Inbound MX server (apps/smtp-server/src/inbound/)**
- Port-25 SMTP listener in `inbound/server.ts`; started when `INBOUND_ENABLED=true`
- `mailauth` (MIT) for SPF/DKIM/DMARC/ARC verification; drops DMARC-reject failures
- OCI Object Storage (raw .eml + attachments) with local-disk fallback via `INBOUND_STORAGE_DIR`
- Optional ClamAV scan via `CLAMD_HOST`; non-blocking (fail-open on timeout)
- Per-IP connection limit (`INBOUND_MAX_CONNECTIONS_PER_IP`)
- Recipient domain allowlist polled from web app every 5 minutes; rejects unknown domains (550)
- Internal HTTP relay via `api-client.ts` to `POST /api/internal/inbound`

**C2 — Received email API + dashboard**
- `webhook-events.ts`: adds `email.received` event with `ReceivedEmailPayload`
- `received-email-service.ts`: persist + query received emails; `email.received` webhook dispatch
- `inbound-storage-service.ts`: signed OCI PAR download URLs for attachments
- `domain-receiving.ts`: MX record helper; toggle receiving; injected into `buildDnsRecords`
- `POST /api/internal/inbound` + `GET /api/internal/inbound/domains` (shared-secret protected)
- Resend-compat routes: `GET /emails/received`, `/emails/received/:id`, `/emails/received/:id/attachments`, `/emails/received/:id/attachments/:aid`
- tRPC `receivedEmail` router (list, get, setReceiving) for dashboard
- Dashboard `/receiving` page with table + sandboxed HTML preview; no remote loads

**Deploy docs + compose**
- `docker/Dockerfile.mx`: slim MX service image
- `compose.scribase-mail.yml`: `mx` profile service on `0.0.0.0:25`; notes OCI firewall + DNS
- `DEPLOY.md`: Inbound MX section (DNS, OCI security list, grey-cloud record, start command)
- New env: `INBOUND_INTERNAL_SECRET`, `INBOUND_MX_HOSTNAME`

**Tests**
- `auth-check.unit.test.ts`: SPF/DKIM/DMARC result parsing (mailauth mocked)
- `storage.unit.test.ts`: local-disk fallback write/read
- `received-email-service.unit.test.ts`: persist, query, pagination, error paths (Prisma mocked)
- `received.api.test.ts`: GET list/detail/attachments against Hono in-process (db mocked)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 03:55:11 +03:00
7ab9e69ef5 merge: content screening and first-sends review queue
# Conflicts:
#	apps/web/prisma/schema.prisma
#	deploy/.env.example
#	deploy/DEPLOY.md
#	deploy/compose.scribase-mail.yml
2026-10-07 03:40:32 +03:00
54dd043c8f feat: content screening and admin review queue for outgoing mail
Every email (API, SMTP proxy, campaigns, scheduled) now passes one send
gate in the queue worker right after the limit check:

- ContentScreeningService: extracts all links (href/src/action, bare URLs,
  redirect/tracking-wrapped targets) and checks them against a threat-feed
  host index (default: Phishing.Database active phishing domains, MIT),
  stored in Redis as a ~3 MB sorted hash index and refreshed every 6h by
  a BullMQ job. Shared platforms are exempt from feed matches.
- In-process heuristics: blocked attachment types (.exe/.js/.scr/.iso/...),
  raw-IP links, URL shorteners, link-text/href domain mismatch,
  javascript:/data: links, base64-only bodies, missing unsubscribe on
  marketing mail, phishing/crypto/gift-card language, caps, hidden text.
- Verdicts: allow / hold / reject. Rejections return a clear 400 on the
  API/SMTP path and refuse campaigns at schedule time; malicious rejects
  are strikes and 3 in 7 days block the team.
- First-sends review: new cloud teams' emails are HELD until 20 sent and
  48h old (configurable in sending-policy.ts / env), unless verified or
  trusted (Team.sendingTrustedAt).
- New EmailStatus HELD + EmailReview table; customers see HELD in logs
  and GET /v1/emails/{id} (latestStatus); admin is emailed (rate-limited).
- Admin > Review (/admin/review, adminReview tRPC router): sandboxed
  CSP-locked preview, approve / approve and trust / approve team / reject
  (note) / reject and block team.
- Cleanup job keeps bodies of HELD emails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 03:38:20 +03:00
045cb046ad feat: replace Stripe billing with Dodo Payments
- Plans FREE / PRO ($20, 50k/mo, 10 domains) / SCALE ($90, 100k/mo,
  1,000 domains) with $0.90 per 1,000 overage, defined once in
  packages/lib/src/constants/pricing.ts and used by PLAN_LIMITS, the
  billing UI and the marketing pricing section
- Dodo checkout sessions, customer portal, prorated plan change,
  cancel/resume at period end (official dodopayments SDK)
- /api/webhook/dodo verified with Standard Webhooks via SDK unwrap();
  idempotent per webhook-id (BillingWebhookEvent claim and billing writes
  in one transaction); handles subscription active/renewed/plan_changed/
  on_hold/cancelled/failed/expired and payment succeeded/failed; ignores
  other products on the shared Dodo business
- Usage job ingests daily sent-email counts as Dodo usage events with
  deterministic ids (team + day), 3-day catch-up, 1,000-event batches
- Migration: Plan BASIC -> PRO, add SCALE; Team.stripeCustomerId ->
  billingCustomerId; provider-neutral Subscription (provider, customerId,
  plan, productId/productIds)
- Remove stripe package, Stripe route and STRIPE_* env; add DODO_* env,
  compose/.env.example entries and owner steps in deploy/DEPLOY.md
- Billing UI degrades to "Billing not configured" without keys

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 03:30:53 +03:00
f0ceeaa2e0 feat: Scribase Mail branding, docs, deploy prep and AGPL notices
- rename product to Scribase Mail across web app, emails, marketing and docs
- new monochrome mark/favicons and neutral black/white theme; remove emoji UI
- source code link (AGPL-3.0) in sidebar, login and unsubscribe pages
- rewrite marketing site and self-hosting docs for OCI Email Delivery,
  add OCI notes page (event sources, unavailable features)
- add NOTICE and MERGE.md crediting useSend and listing changes
- add deploy/compose.scribase-mail.yml (web+postgres+redis, 1.47 GB limits),
  deploy/.env.example, Caddy site and DEPLOY.md for mail.scribase.com
- replace legacy provider env vars in turbo.json, CI, env examples, docker files
- OCI SDK packages as server externals for the standalone build

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 01:57:04 +03:00
aedac77725 feat: switch sending provider to Oracle Cloud Email Delivery
- add provider interface (apps/web/src/server/provider) and OCI implementation:
  SMTP sending via nodemailer, email domains + DKIM (CNAME), approved senders,
  suppression list API, provider status
- poll the OCI suppression list for bounces/complaints and feed them through
  the shared email event pipeline (no push notifications)
- first-party open/click tracking with signed pixel and redirect URLs
- replace SES settings with auto-created ProviderSetting + Email provider page
- image uploads via OCI Object Storage pre-authenticated requests
- squash Prisma migrations into a single provider-neutral baseline
- remove all legacy provider SDK packages

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 01:35:20 +03:00
KM Koushik
8676965019
feat: add webhooks (#334) 2026-01-18 20:50:54 +11:00