MCPcopy Create free account
hub / github.com/aetherstate/GODMOD3.AI / validateEvent

Function validateEvent

functions/api/telemetry.ts:91–111  ·  view source on GitHub ↗

Validates that an event conforms to the expected shape.

(event: unknown)

Source from the content-addressed store, hash-verified

89
90/** Validates that an event conforms to the expected shape. */
91function validateEvent(event: unknown): event is TelemetryEvent {
92 if (typeof event !== 'object' || event === null || Array.isArray(event)) {
93 return false
94 }
95 const e = event as Record<string, unknown>
96
97 // 'type' must be a non-empty string
98 if (typeof e.type !== 'string' || e.type.length === 0) return false
99
100 // 'timestamp' must be a finite number
101 if (typeof e.timestamp !== 'number' || !Number.isFinite(e.timestamp)) return false
102
103 // 'session_id' is required and must be a string (can be empty – the
104 // rate limiter will derive a key if needed, but the field must exist)
105 if (typeof e.session_id !== 'string') return false
106
107 // Reject events that are unreasonably large (> 64 KB serialised)
108 if (JSON.stringify(e).length > 65_536) return false
109
110 return true
111}
112
113// Handle CORS preflight
114export const onRequestOptions: PagesFunction<Env> = async () => {

Callers 1

onRequestPostFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected