28 lines
873 B
TypeScript
28 lines
873 B
TypeScript
type UnknownMap = Record<string, unknown>;
|
|
|
|
function objectValue(value: unknown): UnknownMap | null {
|
|
return value && typeof value === "object" && !Array.isArray(value)
|
|
? value as UnknownMap
|
|
: null;
|
|
}
|
|
|
|
export function intelligenceSummary(value: unknown) {
|
|
const intelligence = objectValue(value);
|
|
const location = objectValue(intelligence?.location);
|
|
const locationLabel = [location?.city, location?.region, location?.countryCode ?? location?.country]
|
|
.filter((value): value is string => typeof value === "string" && value.length > 0)
|
|
.join(", ");
|
|
const classification = typeof intelligence?.classification === "string"
|
|
? intelligence.classification
|
|
: null;
|
|
|
|
return {
|
|
location: locationLabel || null,
|
|
classification,
|
|
};
|
|
}
|
|
|
|
export function eventIpSummary(data: UnknownMap) {
|
|
return intelligenceSummary(data.ipIntelligence);
|
|
}
|