Blueprint
Sync, invites & exclusive tokens
Pending sync, accept/reject, invitations, and invite/exclusive token APIs.
Sync (/api/sync/*)
| Route | Purpose |
|---|---|
POST /api/sync/handle-update | User decision on a pending sync record: accept | reject | ignore; target user must match target_user_uuid; accept merges via generateContentDiff / incremental snapshot into unified modules (src/models/unified-modules-simple, src/lib/content-diff) |
GET /api/sync/pending-updates | List pending records for the current user |
POST /api/sync/trigger-update-check | Trigger server-side update check |
POST /api/sync/batch-handle-update | Batch handle |
POST /api/sync/create-invitation | Create sync/share invitation (admin or permitted flows — see route for guards) |
Models: src/models/sync.ts (updateSyncRecordStatus, getSyncRecordWithUserInfo, etc.).
Invite & codes
| Route | Purpose |
|---|---|
POST /api/update-invite | Update user invite code / invite metadata (see route + src/services usage) |
POST /api/update-invite-code | Dedicated invite-code update |
GET/POST .../admin/invitations | Admin invitation management |
POST /api/user/generate-exclusive-token | Generate exclusive token for user |
POST /api/user/update-exclusive-token | Update token |
POST /api/resolve-exclusive-token | Resolve token server-side |
POST /api/user/copy-from-referrer | Copy content from referrer when joining |
Data flow (sync accept)
- Source user change creates a sync_record with status
pending. - Target opens pending list → POST
handle-updatewithaccept. - Server applies diff to unified modules; status updated; optional blacklist side effects (
notification-blacklist).
Key files
src/app/api/sync/**src/app/api/update-invite/route.ts,update-invite-code/route.tssrc/app/api/user/generate-exclusive-token/route.ts,update-exclusive-token/route.ts,copy-from-referrer/route.tssrc/app/api/resolve-exclusive-token/route.tssrc/models/sync.ts,src/lib/content-diff.ts
Dependencies
Environment
DATABASE_URLADMIN_EMAILS— whencreate-invitationor related routes are admin-gated (verify in the specificroute.ts).
Database (src/db/schema.ts)
content_sync_records,user_invitations,user_notification_blacklistusers—invite_code,invited_by,exclusive_link_token- On accept:
user_profiles,user_module_configs,user_module_website_relations,user_custom_module_types,user_custom_websites, etc.