Repository navigation
Open
Description
Parent
What to build
Add direct email invitations (DocumentEmailInvite) supporting instant grants for existing verified accounts, domain-separated dpe_ fragment invitations with flexible-claim mismatch prompts for unregistered recipients, manager-only Pending rows (Resend / Cancel), and the two-stage Add people email-chip composer.
1. Prisma Schema, Worker Signing & MX Validation (apps/hocuspocus.server, packages/email-templates)
- Add
DocumentEmailInvitemodel (onDelete: CascadetoDocumentMetadata.documentId):id String @id @default(uuid()),documentId String,email String(normalized lowercase),role DocumentRole(all 4 rolesfull | edit | comment | view),invitedBy String,note String?,expiresAt DateTime(14dTTL),acceptedAt DateTime?,acceptedByUserId String?,revokedAt DateTime?,createdAt DateTime @default(now()).- Partial unique index:
UNIQUE ("documentId", "email") WHERE "acceptedAt" IS NULL AND "revokedAt" IS NULL. - Add FK relation (
onDelete: SetNull) fromDocumentGrant.emailInviteIdtoDocumentEmailInvite.id.
- Shared email validator: Extract
validateEmailAddress(email)(usingHOUSE_EMAIL_REGEX+resolveMxwith bounded2stimeout) fromsrc/api/email.tsintosrc/lib/email/validateEmail.tsfor reuse across/api/email/validateand email invites. - Worker-derived HMAC & email template (
packages/email-templates,hocuspocus-worker):- Require
INVITE_LINK_SECRET(>= 32chars) inhocuspocus-workerenv.schema.tsas well asrest-api. - BullMQ
EmailJobDatapasses{ inviteId, recipientEmail, documentId, role, note }ONLY — derivedpe_<inviteId>.<base64url(hmacSha256("dpe:" + inviteId, INVITE_LINK_SECRET))>insidebuildEmailMessage(never store raw tokens in BullMQ or DLQ payloads). Add a clean invitation template underpackages/email-templates/templates/.
- Require
2. Backend Endpoints (src/modules/document-sharing/, OpenAPI covered)
POST /api/documents/:documentId/invites/email— Owner orFull access.- Fail-closed budgets:
20/hrper caller, max20emails per request (returning per-address result status), max50open pending invites per document. Validates each address withvalidateEmailAddressand skips inviter's own email. - Looks up non-deleted, non-anonymous
public.userscase-insensitively byemail:- Account exists: immediately creates/updates
DocumentGrant+ Supabasedocument_access_grantsmirror (instant-grant); queues direct document link email whennotify = true. - No account matches: creates
DocumentEmailInvite(14dTTL) and requires email delivery carrying/invite#dpe_…(even if optional notify checkbox was unchecked for existing users).
- Account exists: immediately creates/updates
- Fail-closed budgets:
POST /api/documents/:documentId/invites/email/:inviteId/resend&DELETE .../invites/email/:inviteId:Resend:1 / 5 mincooldown per invite; extendsexpiresAt = now() + 14 daysand queues email.Cancel: stampsrevokedAt = now().
POST /api/documents/invites/preview&redeem(dpe_extension to#829):preview: returns invitedemail(display/mismatch check),role,note,emailMismatch: boolean.redeem: accepts{ token, confirmMismatch?: boolean }; if caller's email differs frominvite.emailand!confirmMismatch, returns structured mismatch challenge; once confirmed (confirmMismatch: trueor exact match), consumes invite atomically (acceptedAt,acceptedByUserId) insidepg_advisory_xact_lock, grantsDocumentGrant+ Supabase mirror, and redirects to document.
3. Webapp Two-Stage Compose, Pending Rows & Mismatch Screen (apps/webapp)
- Two-stage
Add peopleview (SharePopover'compose'&'share'BottomSheet'addPeople'):- Overview renders compact button
"Add people by email…"opening the dedicated compose view: multi-email chip field (Enteror,commits chip;Backspacepops last chip; invalid format highlighted), Role picker (Full access–Can view), optional message textarea,"Notify people by email"checkbox,Cancel, and solebtn-primarySend invite.
- Overview renders compact button
- Manager-only
Pendingrows (People with access):- Active header count
People with access · Ncounts Owner + active grants only (does NOT inflateNwithPendingemail invites). - Managers see
Pendingrows inside the scrollable list withPendingbadge, role dropdown +Resend invite+Cancel invite(and in-sheet mobilepersonDetailsupport without duplicatingemail (email)). Non-managers never seePendinginvites.
- Active header count
/invite#dpe_…Email MismatchPageCard:- When signed in with a different email than invited: "This invite was sent to
<invitedEmail>, but you're signed in as<currentEmail>." - Primary CTA:
Switch account(signs out / returns to auth keeping#dpe_token); Secondary CTA (variant="cancel"):Continue as <currentEmail>(confirmMismatch: true).
- When signed in with a different email than invited: "This invite was sent to
Maintainer rulings, 2026-11-23
- Hybrid rule: instant grant when verified email matches an existing account;
Pendingdpe_invite with flexible-claim mismatch disclosure when unregistered. - Derive
dpe_HMAC secrets insidehocuspocus-workerat render time (never put raw secrets in BullMQ/DLQ jobs). - Keep active header count
Nstrictly to Owner + active grants; hidePendingrows from non-managers. - Email mismatch screen uses
Switch accountas primary CTA andContinue as <email>as secondary.
Acceptance criteria
- Inviting an existing user email grants immediate access + mirror row; inviting an unregistered email creates a
Pendingrow and delivers a working/invite#dpe_…email (14dTTL). -
POST /invites/emailenforces20/hrcaller cap,20emails/batch,50pending/doc,2sMX validation, andResendextends expiry (1/5mcooldown). - Two-stage
Add peoplechip input (Enter/,/Backspace) andPendingrow actions (Resend,Cancel, change role) work across Desktop and MobileBottomSheet;People with access · Nexcludes Pending rows fromN. - Opening
/invite#dpe_…under another account shows the mismatch warning withSwitch accountprimary andContinue as <current>secondary, redeeming cleanly on choice. - Real-Postgres tests + worker template test + webapp typecheck/lint pass.
Blocked by
- Build desktop Share popover, mobile Share sheet, and General access switch dialogs #827 —
SharePopoverand mobile'share'BottomSheethosts. - Add role-scoped invite links and the /invite join journey #829 —
/invitePageCardflow and domain-separated HMAC invite verifier/redeem pipeline.
Agent brief
Type: AFK
Where to start (read from code, not measured, as of 2026-11-23):
- Server:
apps/hocuspocus.server/src/api/email.ts(extract MX helper),src/lib/email/{service,queue}.ts,src/hocuspocus.worker.ts,src/config/env.schema.ts,src/modules/document-sharing/ - Templates:
packages/email-templates/templates/ - Webapp: Share UI (
#827),apps/webapp/src/pages/invite.tsx(#829).
Deploy order: hocuspocus-worker → rest-api → webapp (after Prisma migration)
Verify: Server email invite + mismatch + rate-limit tests, hocuspocus-worker buildEmailMessage test (verifying no token in job JSON), webapp typecheck/lint/build, and end-to-end /invite#dpe_… mismatch & instant-grant check.
Out of scope
- Ownership transfer requests (
dpt_) andPending transferbanners (Add accept-required ownership transfer, expiring grant reaper, and Open document copy #834).
Activity