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:
@@ -0,0 +1,54 @@
|
||||
-- 2.4.0: linked products and the event feed (docs/EVENTS-2.4-PLAN.md).
|
||||
ALTER TYPE "AdminAuditAction" ADD VALUE 'product_link_connected';
|
||||
ALTER TYPE "AdminAuditAction" ADD VALUE 'product_link_disconnected';
|
||||
ALTER TYPE "AdminAuditAction" ADD VALUE 'feed_publish_toggled';
|
||||
ALTER TYPE "AdminAuditAction" ADD VALUE 'feed_show_toggled';
|
||||
|
||||
CREATE TABLE "ProductLink" (
|
||||
"installId" TEXT NOT NULL,
|
||||
"product" TEXT NOT NULL,
|
||||
"url" TEXT NOT NULL,
|
||||
"publicKey" TEXT NOT NULL,
|
||||
"secret" TEXT NOT NULL,
|
||||
"connectedAt" TIMESTAMP(3) NOT NULL,
|
||||
"connectedById" TEXT,
|
||||
"showEvents" BOOLEAN NOT NULL DEFAULT false,
|
||||
"lastSyncAt" TIMESTAMP(3),
|
||||
"lastSyncError" TEXT,
|
||||
"lastGoodAt" TIMESTAMP(3),
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
CONSTRAINT "ProductLink_pkey" PRIMARY KEY ("installId")
|
||||
);
|
||||
|
||||
CREATE TABLE "LinkNonce" (
|
||||
"nonce" TEXT NOT NULL,
|
||||
"seenAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT "LinkNonce_pkey" PRIMARY KEY ("nonce")
|
||||
);
|
||||
CREATE INDEX "LinkNonce_seenAt_idx" ON "LinkNonce"("seenAt");
|
||||
|
||||
CREATE TABLE "FeedEntry" (
|
||||
"eventId" TEXT NOT NULL,
|
||||
"hash" TEXT NOT NULL,
|
||||
"payload" JSONB NOT NULL,
|
||||
"changedAt" TIMESTAMP(3) NOT NULL,
|
||||
"removedAt" TIMESTAMP(3),
|
||||
CONSTRAINT "FeedEntry_pkey" PRIMARY KEY ("eventId")
|
||||
);
|
||||
CREATE INDEX "FeedEntry_changedAt_idx" ON "FeedEntry"("changedAt");
|
||||
CREATE INDEX "FeedEntry_removedAt_idx" ON "FeedEntry"("removedAt");
|
||||
|
||||
CREATE TABLE "ImportedEvent" (
|
||||
"key" TEXT NOT NULL,
|
||||
"linkId" TEXT NOT NULL,
|
||||
"payload" JSONB NOT NULL,
|
||||
"startsAt" TIMESTAMP(3) NOT NULL,
|
||||
"endsAt" TIMESTAMP(3) NOT NULL,
|
||||
"campusSlug" TEXT,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
CONSTRAINT "ImportedEvent_pkey" PRIMARY KEY ("key")
|
||||
);
|
||||
CREATE INDEX "ImportedEvent_linkId_idx" ON "ImportedEvent"("linkId");
|
||||
CREATE INDEX "ImportedEvent_endsAt_idx" ON "ImportedEvent"("endsAt");
|
||||
ALTER TABLE "ImportedEvent" ADD CONSTRAINT "ImportedEvent_linkId_fkey" FOREIGN KEY ("linkId") REFERENCES "ProductLink"("installId") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -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])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user