Events 2.4.0 backend: protocol v2, Linked products, the event feed

- Hub client: register and heartbeat on protocol v2 with the site's
  Ed25519 key (sent on the heartbeat until the Hub has it); falls back to
  v1 for a day if the Hub refuses v2, so the licence always refreshes.
- crosscode.link/1 Connect / Disconnect, both directions, trusted through
  the Hub's cached linkedProducts (ProductLink, LinkNonce).
- GET /api/feed/v1/events from FeedEntry (go-live, closing and selling
  out are changes; deactivated events go in deleted), event.changed to
  connected products, and showing their events (ImportedEvent).
- /api/v2/linked-products, /api/v2/linked-events; /events/:id/full gains
  crosscodeEvent and priceRangeCents for the JSON-LD.
- Contracts: FEED_PATHS, typesVersions for @crosscode/contracts/signing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 12:24:29 +02:00
co-authored by Claude Opus 5.5
parent 390b80e56e
commit 8a930d07c6
30 changed files with 5874 additions and 17 deletions
+65
View File
@@ -847,6 +847,10 @@ enum AdminAuditAction {
webhook_endpoint_changed
registrations_bulk
ai_settings_changed
product_link_connected
product_link_disconnected
feed_publish_toggled
feed_show_toggled
}
// Append-only audit trail for admin/supervisor-initiated actions with money or
@@ -2377,3 +2381,64 @@ model RecoveryCode {
@@index([userId])
}
// ─── Linked products and the event feed (2.4.0, docs/EVENTS-2.4-PLAN.md) ─────────────────────
// A link to one of the church's other products (Settings → Linked products → Connect): the
// shared secret signs the calls between the two (the event.changed webhook). The sibling's key
// is the one the Hub listed when it was connected.
model ProductLink {
installId String @id // the sibling's Hub install id
product String // website | app | accounts
url String
publicKey String
secret String // encrypted (utils/encryption)
connectedAt DateTime
connectedById String? // a user here; null when the sibling connected
// "Show events from this product" (off by default).
showEvents Boolean @default(false)
lastSyncAt DateTime?
lastSyncError String?
lastGoodAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
importedEvents ImportedEvent[]
}
// Nonces of link messages already accepted (crosscode.link/1), so one can't be replayed. Kept
// an hour: a message older than five minutes is refused anyway.
model LinkNonce {
nonce String @id
seenAt DateTime @default(now())
@@index([seenAt])
}
// What the feed last published for each event (feed/entries.ts): changedAt moves only when what
// a sibling sees changes, so ?updatedSince= also catches going live, closing and selling out.
model FeedEntry {
eventId String @id
hash String
payload Json
changedAt DateTime
removedAt DateTime? // stopped being public: listed in `deleted`
@@index([changedAt])
@@index([removedAt])
}
// An event from a linked product's feed: a read-only copy, never published again.
model ImportedEvent {
key String @id // eventKey(): "<product>:<id>"
linkId String
link ProductLink @relation(fields: [linkId], references: [installId], onDelete: Cascade)
payload Json // the crosscode.event/1 as received
startsAt DateTime
endsAt DateTime
campusSlug String?
updatedAt DateTime
@@index([linkId])
@@index([endsAt])
}