2024-12-31 13:55:42 +01:00
|
|
|
import type {Domain, Watchlist} from '../../../../utils/api'
|
2024-12-30 23:50:15 +01:00
|
|
|
import {rdapRoleTranslation} from '../../../../utils/functions/rdapTranslation'
|
|
|
|
|
import {t} from 'ttag'
|
2024-08-22 01:44:50 +02:00
|
|
|
|
2024-12-30 23:50:15 +01:00
|
|
|
import {rolesToColor} from '../../../../utils/functions/rolesToColor'
|
2024-12-31 13:55:42 +01:00
|
|
|
import type {Edge} from '@xyflow/react'
|
2024-08-17 21:52:40 +02:00
|
|
|
|
2024-12-30 23:50:15 +01:00
|
|
|
export function domainEntitiesToEdges(d: Domain, withRegistrar = false): Edge[] {
|
2024-08-20 17:32:58 +02:00
|
|
|
const rdapRoleTranslated = rdapRoleTranslation()
|
2024-12-27 19:17:46 +01:00
|
|
|
const sponsor = d.entities.find(e => !e.deleted && e.roles.includes('sponsor'))
|
2024-08-17 21:52:40 +02:00
|
|
|
return d.entities
|
2024-12-27 19:17:46 +01:00
|
|
|
.filter(e =>
|
|
|
|
|
!e.deleted &&
|
|
|
|
|
(withRegistrar || !e.roles.includes('registrar')) &&
|
2024-12-30 23:50:15 +01:00
|
|
|
((sponsor == null) || !e.roles.includes('registrar') || e.roles.includes('sponsor'))
|
2024-12-27 19:17:46 +01:00
|
|
|
)
|
2024-08-17 21:52:40 +02:00
|
|
|
.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,
|
2024-08-17 21:52:40 +02:00
|
|
|
style: {stroke: rolesToColor(e.roles), strokeWidth: 3},
|
|
|
|
|
label: e.roles
|
2024-12-29 22:31:40 +01:00
|
|
|
.map(r => rdapRoleTranslated[r as keyof typeof rdapRoleTranslated] || r)
|
2024-08-17 21:52:40 +02:00
|
|
|
.join(', '),
|
2024-12-30 23:50:15 +01:00
|
|
|
animated: e.roles.includes('registrant')
|
2024-08-17 21:52:40 +02:00
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-30 23:50:15 +01:00
|
|
|
export const domainNSToEdges = (d: Domain): Edge[] => d.nameservers
|
2024-08-17 21:52:40 +02:00
|
|
|
.map(ns => ({
|
|
|
|
|
id: `ns-${d.ldhName}-${ns.ldhName}`,
|
|
|
|
|
source: d.ldhName,
|
|
|
|
|
target: ns.ldhName,
|
|
|
|
|
style: {stroke: 'grey', strokeWidth: 3},
|
|
|
|
|
label: 'DNS'
|
|
|
|
|
}))
|
|
|
|
|
|
2024-12-30 23:50:15 +01:00
|
|
|
export const tldToEdge = (d: Domain): Edge => ({
|
2024-08-17 21:52:40 +02:00
|
|
|
id: `tld-${d.ldhName}-${d.tld.tld}`,
|
|
|
|
|
source: d.tld.tld,
|
|
|
|
|
target: d.ldhName,
|
|
|
|
|
style: {stroke: 'yellow', strokeWidth: 3},
|
|
|
|
|
label: t`Registry`
|
|
|
|
|
})
|
|
|
|
|
|
2024-12-30 23:50:15 +01:00
|
|
|
export function watchlistToEdges(watchlist: Watchlist, withRegistrar = false, withTld = false): Edge[] {
|
2024-08-18 17:28:45 +02:00
|
|
|
const entitiesEdges = watchlist.domains.map(d => domainEntitiesToEdges(d, withRegistrar)).flat()
|
2024-08-17 21:52:40 +02:00
|
|
|
const nameserversEdges = watchlist.domains.map(domainNSToEdges).flat()
|
2024-08-18 17:28:45 +02:00
|
|
|
const tldEdge = watchlist.domains.map(tldToEdge)
|
2024-08-17 21:52:40 +02:00
|
|
|
|
2024-08-18 17:28:45 +02:00
|
|
|
return [...entitiesEdges, ...nameserversEdges, ...(withTld ? tldEdge : [])]
|
2024-08-17 21:52:40 +02:00
|
|
|
}
|