46 lines
1.9 KiB
TypeScript
Raw Normal View History

import {Domain, Watchlist} from "../../../../utils/api";
2024-08-20 17:32:58 +02:00
import {rdapRoleTranslation} from "../../../search/rdapTranslation";
import {t} from "ttag";
2024-08-21 02:01:20 +02:00
import {rolesToColor} from "../../../../utils";
2024-08-18 03:28:53 +02:00
export function domainEntitiesToEdges(d: Domain, withRegistrar = false) {
2024-08-20 17:32:58 +02:00
const rdapRoleTranslated = rdapRoleTranslation()
return d.entities
2024-08-18 03:28:53 +02:00
.filter(e => !withRegistrar ? !e.roles.includes('registrar') : true)
.map(e => ({
id: `e-${d.ldhName}-${e.entity.handle}`,
2024-08-18 03:28:53 +02:00
source: e.roles.includes('registrant') || e.roles.includes('registrar') ? e.entity.handle : d.ldhName,
target: e.roles.includes('registrant') || e.roles.includes('registrar') ? d.ldhName : e.entity.handle,
style: {stroke: rolesToColor(e.roles), strokeWidth: 3},
label: e.roles
2024-08-20 17:32:58 +02:00
.map(r => r in rdapRoleTranslated ? rdapRoleTranslated[r as keyof typeof rdapRoleTranslated] : r)
.join(', '),
animated: e.roles.includes('registrant'),
}))
}
export const domainNSToEdges = (d: Domain) => d.nameservers
.map(ns => ({
id: `ns-${d.ldhName}-${ns.ldhName}`,
source: d.ldhName,
target: ns.ldhName,
style: {stroke: 'grey', strokeWidth: 3},
label: 'DNS'
}))
export const tldToEdge = (d: Domain) => ({
id: `tld-${d.ldhName}-${d.tld.tld}`,
source: d.tld.tld,
target: d.ldhName,
style: {stroke: 'yellow', strokeWidth: 3},
label: t`Registry`
})
2024-08-18 17:28:45 +02:00
export function watchlistToEdges(watchlist: Watchlist, withRegistrar = false, withTld = false) {
const entitiesEdges = watchlist.domains.map(d => domainEntitiesToEdges(d, withRegistrar)).flat()
const nameserversEdges = watchlist.domains.map(domainNSToEdges).flat()
2024-08-18 17:28:45 +02:00
const tldEdge = watchlist.domains.map(tldToEdge)
2024-08-18 17:28:45 +02:00
return [...entitiesEdges, ...nameserversEdges, ...(withTld ? tldEdge : [])]
}