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'
|
2024-08-17 21:52:40 +02:00
|
|
|
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-08-17 21:52:40 +02:00
|
|
|
|
2024-12-30 23:50:15 +01:00
|
|
|
export const domainToNode = (d: Domain): Node => ({
|
2024-08-17 21:52:40 +02:00
|
|
|
id: d.ldhName,
|
2024-12-30 23:50:15 +01:00
|
|
|
position: {x: 0, y: 0},
|
2024-08-17 21:52:40 +02:00
|
|
|
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[] => {
|
2024-12-27 19:17:46 +01:00
|
|
|
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'))
|
2024-12-27 19:17:46 +01:00
|
|
|
)
|
|
|
|
|
.map(e => {
|
|
|
|
|
return {
|
|
|
|
|
id: e.entity.handle,
|
2024-12-30 23:50:15 +01:00
|
|
|
position: {x: 0, y: 0},
|
2024-12-27 19:17:46 +01:00
|
|
|
type: e.roles.includes('registrant') || e.roles.includes('registrar') ? 'input' : 'output',
|
|
|
|
|
data: {label: entityToName(e)},
|
|
|
|
|
style: {
|
|
|
|
|
width: 200
|
|
|
|
|
}
|
2024-08-17 21:52:40 +02:00
|
|
|
}
|
2024-12-27 19:17:46 +01:00
|
|
|
})
|
|
|
|
|
}
|
2024-08-17 21:52:40 +02:00
|
|
|
|
2024-12-30 23:50:15 +01:00
|
|
|
export const tldToNode = (tld: Tld): Node => ({
|
2024-08-17 21:52:40 +02:00
|
|
|
id: tld.tld,
|
2024-12-30 23:50:15 +01:00
|
|
|
position: {x: 0, y: 0},
|
2024-08-17 21:52:40 +02:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2024-12-30 23:50:15 +01:00
|
|
|
export const nsToNode = (ns: Nameserver): Node => ({
|
2024-08-17 21:52:40 +02:00
|
|
|
id: ns.ldhName,
|
2024-12-30 23:50:15 +01:00
|
|
|
position: {x: 0, y: 0},
|
2024-08-17 21:52:40 +02:00
|
|
|
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-12-30 23:50:15 +01:00
|
|
|
export function watchlistToNodes(watchlist: Watchlist, withRegistrar = false, withTld = false): Node[] {
|
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-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-17 21:52:40 +02:00
|
|
|
|
2024-08-18 17:28:45 +02:00
|
|
|
return [...domains, ...entities, ...nameservers, ...(withTld ? tlds : [])]
|
2024-12-30 23:50:15 +01:00
|
|
|
}
|