(raw: unknown)
| 160 | } |
| 161 | |
| 162 | function sanitizeEvent(raw: unknown): StoredEvent | null { |
| 163 | if (typeof raw !== 'object' || raw === null) return null; |
| 164 | const e = raw as JsonObject; |
| 165 | if (typeof e.event !== 'string') return null; |
| 166 | const spec = EVENTS[e.event]; |
| 167 | if (!spec) return null; |
| 168 | |
| 169 | const rawProps = (typeof e.props === 'object' && e.props !== null ? e.props : {}) as JsonObject; |
| 170 | const props: JsonObject = {}; |
| 171 | for (const [key, sanitize] of Object.entries(spec.props)) { |
| 172 | const val = sanitize(rawProps[key]); |
| 173 | if (val !== undefined) props[key] = val; |
| 174 | } |
| 175 | for (const req of spec.required) { |
| 176 | if (!(req in props)) return null; |
| 177 | } |
| 178 | |
| 179 | const out: StoredEvent = { event: e.event, props }; |
| 180 | const ts = clampTimestamp(e.ts); |
| 181 | if (ts !== undefined) out.ts = ts; |
| 182 | return out; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Re-narrow a sanitized envelope value for binding. The ENVELOPE_PROPS sanitizers |
no test coverage detected