|
9 | 9 | - [Common Routes](#common-routes) |
10 | 10 | - [Priority Routes](#priority-routes) |
11 | 11 | - [Sync Routes](#sync-routes) |
| 12 | +- [Events Stream Routes](#events-stream-routes) |
12 | 13 | - [Event Routes](#event-routes) |
13 | 14 | - [Operational Headers](#operational-headers) |
14 | 15 |
|
@@ -373,6 +374,36 @@ Authenticated user trigger for full import restart: |
373 | 374 |
|
374 | 375 | --- |
375 | 376 |
|
| 377 | +## Events Stream Routes |
| 378 | + |
| 379 | +**Source**: `packages/backend/src/events/events.routes.config.ts`, `packages/backend/src/events/controllers/events.controller.ts`, `packages/backend/src/servers/sse/sse.server.ts` |
| 380 | + |
| 381 | +### /api/events/stream |
| 382 | + |
| 383 | +Authenticated realtime stream endpoint used by the web `EventSource` client. |
| 384 | + |
| 385 | +- `GET /api/events/stream` |
| 386 | +- middleware: `verifySession()` |
| 387 | +- response type: `text/event-stream` (long-lived HTTP response) |
| 388 | +- transport notes: |
| 389 | + - server sends named events (`event: <NAME>`) with JSON data payloads |
| 390 | + - server sends heartbeat comments (`: keepalive`) roughly every 25 seconds |
| 391 | + - stream fan-out is per authenticated Compass user id (all active tabs for that user receive published events) |
| 392 | + |
| 393 | +On stream connect: |
| 394 | + |
| 395 | +1. backend subscribes the response to SSE fan-out first |
| 396 | +2. backend fetches current user metadata |
| 397 | +3. backend immediately publishes `USER_METADATA` to that connection |
| 398 | + |
| 399 | +Operational constraints: |
| 400 | + |
| 401 | +- stream requires a valid SuperTokens session cookie; unauthenticated requests are rejected by middleware |
| 402 | +- import progress (`IMPORT_GCAL_START` / `IMPORT_GCAL_END`) and background refresh notifications (`EVENT_CHANGED`, `SOMEDAY_EVENT_CHANGED`, `GOOGLE_REVOKED`) are delivered over this stream |
| 403 | +- clients should treat stream events as asynchronous hints and refetch through normal API/repository paths where applicable |
| 404 | + |
| 405 | +--- |
| 406 | + |
376 | 407 | ## Event Routes |
377 | 408 |
|
378 | 409 | **Source**: `packages/backend/src/event/event.routes.config.ts` |
@@ -513,6 +544,7 @@ When this payload accompanies `401` or `410`, web clients should keep the sessio |
513 | 544 | - `/api/signinup`, `/api/signout`, `/api/session/*` - SuperTokens OAuth/session APIs |
514 | 545 | - SuperTokens EmailPassword APIs (invoked through SDK methods in auth form hooks) |
515 | 546 | - `/api/user/*` - User profile and metadata |
| 547 | +- `/api/events/stream` - authenticated SSE stream for realtime sync events |
516 | 548 | - `/api/event/*` - Calendar event CRUD operations |
517 | 549 | - `/api/calendars/*` - Calendar list and selection |
518 | 550 | - `/api/sync/*` - Google Calendar synchronization |
|
0 commit comments