mirror of
https://github.com/different-ai/openwork
synced 2026-05-15 03:26:24 +02:00
22 lines
562 B
TypeScript
22 lines
562 B
TypeScript
type RawEvent = {
|
|
type?: string;
|
|
properties?: unknown;
|
|
payload?: { type?: string; properties?: unknown };
|
|
};
|
|
|
|
export type NormalizedEvent = {
|
|
type: string;
|
|
properties?: any;
|
|
};
|
|
|
|
export function normalizeEvent(raw: RawEvent | null | undefined): NormalizedEvent | null {
|
|
if (!raw) return null;
|
|
if (typeof raw.type === "string") {
|
|
return { type: raw.type, properties: raw.properties };
|
|
}
|
|
if (raw.payload && typeof raw.payload.type === "string") {
|
|
return { type: raw.payload.type, properties: raw.payload.properties };
|
|
}
|
|
return null;
|
|
}
|