66 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-12-31 13:55:42 +01:00
import type {Domain, Nameserver, Tld, Watchlist} from '../../../../utils/api'
2024-12-30 23:50:15 +01:00
import React from 'react'
import {t} from 'ttag'
2024-08-22 01:44:50 +02:00
2024-12-30 23:50:15 +01:00
import {entityToName} from '../../../../utils/functions/entityToName'
2024-12-31 13:55:42 +01:00
import type {Node} from '@xyflow/react'
2024-12-30 23:50:15 +01:00
export const domainToNode = (d: Domain): Node => ({
id: d.ldhName,
2024-12-30 23:50:15 +01:00
position: {x: 0, y: 0},
data: {label: <b>{d.ldhName}</b>},
style: {
width: 200
}
})
2024-12-30 23:50:15 +01:00
export const domainEntitiesToNode = (d: Domain, withRegistrar = false): Node[] => {
const sponsor = d.entities.find(e => !e.deleted && e.roles.includes('sponsor'))
return d.entities
.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'))
)
.map(e => {
return {
id: e.entity.handle,
2024-12-30 23:50:15 +01:00
position: {x: 0, y: 0},
type: e.roles.includes('registrant') || e.roles.includes('registrar') ? 'input' : 'output',
data: {label: entityToName(e)},
style: {
width: 200
}
}
})
}
2024-12-30 23:50:15 +01:00
export const tldToNode = (tld: Tld): Node => ({
id: tld.tld,
2024-12-30 23:50:15 +01:00
position: {x: 0, y: 0},
data: {label: t`.${tld.tld} Registry`},
2024-08-18 17:28:45 +02:00
type: 'input',
style: {
width: 200
}
})
2024-12-30 23:50:15 +01:00
export const nsToNode = (ns: Nameserver): Node => ({
id: ns.ldhName,
2024-12-30 23:50:15 +01:00
position: {x: 0, y: 0},
data: {label: ns.ldhName},
2024-08-18 17:28:45 +02:00
type: 'output',
style: {
width: 200
}
})
2024-12-30 23:50:15 +01:00
export function watchlistToNodes(watchlist: Watchlist, withRegistrar = false, withTld = false): Node[] {
const domains = watchlist.domains.map(domainToNode)
2024-08-18 17:28:45 +02:00
const entities = [...new Set(watchlist.domains.map(d => domainEntitiesToNode(d, withRegistrar)).flat())]
2024-12-20 17:43:35 +01:00
const tlds = [...new Set(watchlist.domains.map(d => d.tld))].filter(t => t.tld !== '.').map(tldToNode)
2024-08-18 17:28:45 +02:00
const nameservers = [...new Set(watchlist.domains.map(d => d.nameservers))].flat().map(nsToNode, withRegistrar)
2024-08-18 17:28:45 +02:00
return [...domains, ...entities, ...nameservers, ...(withTld ? tlds : [])]
2024-12-30 23:50:15 +01:00
}