diff --git a/src/lib/server/osoh-store.ts b/src/lib/server/osoh-store.ts new file mode 100644 index 0000000..58b87e0 --- /dev/null +++ b/src/lib/server/osoh-store.ts @@ -0,0 +1,77 @@ +export type IsoUtcTimestamp = string; + +export type OsohMonitoredSurfaceClass = 'external_monitored_surface'; + +export type OsohSurfaceStatus = + | 'inactive' + | 'active_monitored_surface' + | 'disabled'; + +export type OsohMonitoringEventType = + | 'surface_ping_received' + | 'surface_health_changed' + | 'surface_token_used' + | 'surface_token_revoked'; + +export type OsohAuditAction = + | 'site_created' + | 'site_updated' + | 'site_disabled' + | 'token_created' + | 'token_revoked'; + +export interface OsohMonitoredSiteRecord { + siteId: string; + siteSlug: string; + displayName: string; + classification: OsohMonitoredSurfaceClass; + status: OsohSurfaceStatus; + createdAt: IsoUtcTimestamp; + updatedAt: IsoUtcTimestamp; +} + +export interface OsohMonitoredSurfaceTokenRecord { + tokenId: string; + siteId: string; + + /** + * One-way hash only. Never persist raw token material. + */ + tokenHash: string; + + scope: 'ingest'; + revoked: boolean; + createdAt: IsoUtcTimestamp; + updatedAt: IsoUtcTimestamp; +} + +export interface OsohMonitoringEventRecord { + eventId: string; + siteId: string; + eventType: OsohMonitoringEventType; + occurredAt: IsoUtcTimestamp; + receivedAt: IsoUtcTimestamp; + payload: Record; +} + +export interface OsohAuditTrailRecord { + auditId: string; + siteId: string; + action: OsohAuditAction; + occurredAt: IsoUtcTimestamp; + details: Record; +} + +export interface OsohStoreState { + monitoredSites: OsohMonitoredSiteRecord[]; + monitoredSurfaceTokens: OsohMonitoredSurfaceTokenRecord[]; + monitoringEvents: OsohMonitoringEventRecord[]; + auditTrail: OsohAuditTrailRecord[]; +} + +export const createEmptyOsohStoreState = (): OsohStoreState => ({ + monitoredSites: [], + monitoredSurfaceTokens: [], + monitoringEvents: [], + auditTrail: [], +});