61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
export const EventCategory = z.enum([
|
|
'military',
|
|
'sanctions',
|
|
'infrastructure',
|
|
'energy',
|
|
'cyber',
|
|
'diplomatic',
|
|
'humanitarian',
|
|
]);
|
|
export type EventCategory = z.infer<typeof EventCategory>;
|
|
|
|
export const EventSeverity = z.enum(['low', 'medium', 'high', 'critical']);
|
|
export type EventSeverity = z.infer<typeof EventSeverity>;
|
|
|
|
export const GeopoliticalEventSchema = z.object({
|
|
title: z.string(),
|
|
description: z.string(),
|
|
category: EventCategory,
|
|
severity: EventSeverity,
|
|
timestamp: z.coerce.date(),
|
|
sourceUrl: z.string().nullable().optional(),
|
|
});
|
|
export type GeopoliticalEvent = z.infer<typeof GeopoliticalEventSchema>;
|
|
|
|
export const GeopoliticalEventSeedSchema = z.array(GeopoliticalEventSchema);
|
|
|
|
/** Color mapping for event categories (used for chart annotations) */
|
|
export const EVENT_CATEGORY_COLORS: Record<EventCategory, string> = {
|
|
military: '#ef4444', // red-500
|
|
sanctions: '#f97316', // orange-500
|
|
infrastructure: '#f59e0b', // amber-500
|
|
energy: '#eab308', // yellow-500
|
|
cyber: '#a855f7', // purple-500
|
|
diplomatic: '#3b82f6', // blue-500
|
|
humanitarian: '#6b7280', // gray-500
|
|
};
|
|
|
|
/** Severity level numeric values for sorting */
|
|
export const SEVERITY_ORDER: Record<EventSeverity, number> = {
|
|
low: 0,
|
|
medium: 1,
|
|
high: 2,
|
|
critical: 3,
|
|
};
|
|
|
|
/** String-keyed versions for safe runtime lookup without type assertions */
|
|
const CATEGORY_COLOR_MAP: Record<string, string> = EVENT_CATEGORY_COLORS;
|
|
const SEVERITY_ORDER_MAP: Record<string, number> = SEVERITY_ORDER;
|
|
|
|
/** Safe lookup for event category color — returns fallback for unknown categories */
|
|
export function getCategoryColor(category: string): string {
|
|
return CATEGORY_COLOR_MAP[category] ?? '#6b7280';
|
|
}
|
|
|
|
/** Safe lookup for severity order — returns 0 for unknown severities */
|
|
export function getSeverityOrder(severity: string): number {
|
|
return SEVERITY_ORDER_MAP[severity] ?? 0;
|
|
}
|