Skip to content
File

Blob: src/shared/contracts/session.ts

typescript27 lines
1import { eg, type TypeFromCodec } from "@cloudflare/util-en-garde";
2 
3export const UserSession = eg.object({
4 type: eg.literal("user"),
5 address: eg.string,
6});
7export type UserSession = TypeFromCodec<typeof UserSession>;
8 
9export const AdminSession = eg.object({
10 type: eg.literal("admin"),
11 // The verified OIDC `sub` claim from tessera. Persisted in KV so
12 // requireAdmin can re-check the operator allowlist on every request,
13 // failing closed when an operator is removed from
14 // TESSERA_OPERATOR_SUBS mid-session (instead of waiting for KV TTL).
15 sub: eg.string,
16});
17export type AdminSession = TypeFromCodec<typeof AdminSession>;
18 
19export const SessionRecord = eg.union([UserSession, AdminSession]);
20export type SessionRecord = TypeFromCodec<typeof SessionRecord>;
21 
22export const WebSocketTicketRecord = eg.object({
23 address: eg.string,
24 session: SessionRecord,
25});
26export type WebSocketTicketRecord = TypeFromCodec<typeof WebSocketTicketRecord>;