Blueprint

Sync, invites & exclusive tokens

Pending sync, accept/reject, invitations, and invite/exclusive token APIs.

Sync (/api/sync/*)

RoutePurpose
POST /api/sync/handle-updateUser 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-updatesList pending records for the current user
POST /api/sync/trigger-update-checkTrigger server-side update check
POST /api/sync/batch-handle-updateBatch handle
POST /api/sync/create-invitationCreate sync/share invitation (admin or permitted flows — see route for guards)

Models: src/models/sync.ts (updateSyncRecordStatus, getSyncRecordWithUserInfo, etc.).

Invite & codes

RoutePurpose
POST /api/update-inviteUpdate user invite code / invite metadata (see route + src/services usage)
POST /api/update-invite-codeDedicated invite-code update
GET/POST .../admin/invitationsAdmin invitation management
POST /api/user/generate-exclusive-tokenGenerate exclusive token for user
POST /api/user/update-exclusive-tokenUpdate token
POST /api/resolve-exclusive-tokenResolve token server-side
POST /api/user/copy-from-referrerCopy content from referrer when joining

Data flow (sync accept)

  1. Source user change creates a sync_record with status pending.
  2. Target opens pending list → POST handle-update with accept.
  3. 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.ts
  • src/app/api/user/generate-exclusive-token/route.ts, update-exclusive-token/route.ts, copy-from-referrer/route.ts
  • src/app/api/resolve-exclusive-token/route.ts
  • src/models/sync.ts, src/lib/content-diff.ts

Dependencies

Environment

  • DATABASE_URL
  • ADMIN_EMAILS — when create-invitation or related routes are admin-gated (verify in the specific route.ts).

Database (src/db/schema.ts)

  • content_sync_records, user_invitations, user_notification_blacklist
  • users — 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.
Sync, invites & exclusive tokens | Tracker Dog Docs