2024-08-17 21:52:40 +02:00
|
|
|
import {Domain, Nameserver, Tld, Watchlist} from "../../../../utils/api";
|
|
|
|
|
import vCard from "vcf";
|
|
|
|
|
import React from "react";
|
|
|
|
|
import {t} from 'ttag'
|
|
|
|
|
|
|
|
|
|
export const domainToNode = (d: Domain) => ({
|
|
|
|
|
id: d.ldhName,
|
|
|
|
|
data: {label: <b>{d.ldhName}</b>},
|
|
|
|
|
style: {
|
|
|
|
|
width: 200
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2024-08-18 03:28:53 +02:00
|
|
|
export const domainEntitiesToNode = (d: Domain, withRegistrar = false) => d.entities
|
|
|
|
|
.filter(e => !withRegistrar ? !e.roles.includes('registrar') : true)
|
2024-08-17 21:52:40 +02:00
|
|
|
.map(e => {
|
|
|
|
|
const jCard = vCard.fromJSON(e.entity.jCard)
|
|
|
|
|
let label = e.entity.handle
|
|
|
|
|
if (jCard.data.fn !== undefined && !Array.isArray(jCard.data.fn)) label = jCard.data.fn.valueOf()
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
id: e.entity.handle,
|
2024-08-18 17:28:45 +02:00
|
|
|
type: e.roles.includes('registrant') || e.roles.includes('registrar') ? 'input' : 'output',
|
2024-08-17 21:52:40 +02:00
|
|
|
data: {label},
|
|
|
|
|
style: {
|
|
|
|
|
width: 200
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const tldToNode = (tld: Tld) => ({
|
|
|
|
|
id: tld.tld,
|
|
|
|
|
data: {label: t`.${tld.tld} Registry`},
|
2024-08-18 17:28:45 +02:00
|
|
|
type: 'input',
|
2024-08-17 21:52:40 +02:00
|
|
|
style: {
|
|
|
|
|
width: 200
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const nsToNode = (ns: Nameserver) => ({
|
|
|
|
|
id: ns.ldhName,
|
|
|
|
|
data: {label: ns.ldhName},
|
2024-08-18 17:28:45 +02:00
|
|
|
type: 'output',
|
2024-08-17 21:52:40 +02:00
|
|
|
style: {
|
|
|
|
|
width: 200
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2024-08-18 17:28:45 +02:00
|
|
|
export function watchlistToNodes(watchlist: Watchlist, withRegistrar = false, withTld = false) {
|
2024-08-17 21:52:40 +02:00
|
|
|
|
|
|
|
|
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-08-17 21:52:40 +02:00
|
|
|
const tlds = [...new Set(watchlist.domains.map(d => d.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-17 21:52:40 +02:00
|
|
|
|
2024-08-18 17:28:45 +02:00
|
|
|
return [...domains, ...entities, ...nameservers, ...(withTld ? tlds : [])]
|
2024-08-17 21:52:40 +02:00
|
|
|
}
|