53 lines
1.6 KiB
TypeScript
Raw Normal View History

import {Domain, Nameserver, Tld, Watchlist} from "../../../../utils/api";
import React from "react";
import {t} from 'ttag'
2024-08-21 02:01:20 +02:00
import {entityToName} from "../../../../utils";
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)
.map(e => {
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-21 02:01:20 +02:00
data: {label: entityToName(e)},
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',
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',
style: {
width: 200
}
})
2024-08-18 17:28:45 +02:00
export function watchlistToNodes(watchlist: Watchlist, withRegistrar = false, withTld = false) {
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())]
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-18 17:28:45 +02:00
return [...domains, ...entities, ...nameservers, ...(withTld ? tlds : [])]
}