Full Toolkit for Next-Level Domain Analysis
Improve WhoisQuickInfo ✨
Felix Wotschofskyef9ee5649c06
diff --git a/app/api/whois-summary/route.ts b/app/api/whois-summary/route.tsindex 13d61ba..86fb403 100644--- a/app/api/whois-summary/route.ts+++ b/app/api/whois-summary/route.ts@@ -1,12 +1,27 @@+import { getDomain } from 'tldts';import whoiser, { WhoisSearchResult } from 'whoiser';import { isValidDomain } from '@/lib/utils';-export type WhoisSummaryResponse = {- registrar: string | null;- createdAt: string | null;- dnssec: string | null;-};+const UNREGISTERED_INDICATORS = [+ 'no data found',+ 'no match',+ 'no object found',+ 'not been registered',+ 'not found',+ 'status: free',+];++export type WhoisSummaryResponse =+ | {+ registered: false;+ }+ | {+ registered: true;+ registrar: string | null;+ createdAt: string | null;+ dnssec: string | null;+ };export type WhoisSummaryErrorResponse = { error: true; message: string };@@ -14,15 +29,19 @@ const getSummary = async (domain: string): Promise<WhoisSummaryResponse> => {// TODO Allow resolving for TLDsif (!isValidDomain(domain)) {return {+ registered: true,registrar: null,createdAt: null,dnssec: null,};}+ const rawDomain = getDomain(domain) || domain;+try {- const results = await whoiser(domain, {+ const results = await whoiser(rawDomain, {timeout: 5000,+ raw: true,});const resultsKey = Object.keys(results).find(@@ -34,7 +53,18 @@ const getSummary = async (domain: string): Promise<WhoisSummaryResponse> => {}const firstResult = results[resultsKey] as WhoisSearchResult;+ if (+ UNREGISTERED_INDICATORS.some((indicator) =>+ firstResult['__raw'].toString().toLowerCase().includes(indicator)+ )+ ) {+ return {+ registered: false,+ };+ }+return {+ registered: true,registrar: firstResult['Registrar']?.toString(),createdAt:firstResult && 'Created Date' in firstResult@@ -47,6 +77,7 @@ const getSummary = async (domain: string): Promise<WhoisSummaryResponse> => {} catch (error) {console.error(error);return {+ registered: true,registrar: null,createdAt: null,dnssec: null,diff --git a/components/results/WhoisQuickInfo.tsx b/components/results/WhoisQuickInfo.tsxindex 73422ee..60769b9 100644--- a/components/results/WhoisQuickInfo.tsx+++ b/components/results/WhoisQuickInfo.tsx@@ -3,9 +3,36 @@import type { FC } from 'react';import useSWRImmutable from 'swr/immutable';+import { Skeleton } from '@/components/ui/skeleton';+import { WhoisSummaryResponse } from '@/app/api/whois-summary/route';-import { Skeleton } from '../ui/skeleton';+type WhoisQuickInfoTileProps =+ | {+ title: string;+ loading: true;+ value?: string;+ }+ | {+ title: string;+ loading?: false;+ value: string;+ };++const WhoisQuickInfoTile: FC<WhoisQuickInfoTileProps> = ({+ title,+ loading,+ value,+}) => (+ <div>+ <h3 className="text-xs text-muted-foreground">{title}</h3>+ {loading ? (+ <Skeleton className="mt-1 h-4 w-24 rounded-sm" />+ ) : (+ <p className="text-sm">{value}</p>+ )}+ </div>+);type WhoisQuickInfoProps = {domain: string;@@ -16,32 +43,38 @@ const WhoisQuickInfo: FC<WhoisQuickInfoProps> = ({ domain }) => {`/api/whois-summary?domain=${encodeURIComponent(domain)}`);- return (- <div className="my-8 flex flex-wrap gap-8">- <div>- <h3 className="text-xs text-muted-foreground">Registrar</h3>- {isLoading ? (- <Skeleton className="mt-1 h-4 w-24 rounded-sm" />- ) : (- <p className="text-sm">{data?.registrar || 'Unavailable'}</p>- )}- </div>- <div>- <h3 className="text-xs text-muted-foreground">Creation Date</h3>- {isLoading ? (- <Skeleton className="w-18 mt-1 h-4 rounded-sm" />- ) : (- <p className="text-sm">{data?.createdAt || 'Unavailable'}</p>- )}+ if (isLoading || !data) {+ return (+ <div className="my-8 flex flex-wrap gap-8">+ <WhoisQuickInfoTile title="Registar" loading />+ <WhoisQuickInfoTile title="Creation Date" loading />+ <WhoisQuickInfoTile title="DNSSEC" loading /></div>- <div>- <h3 className="text-xs text-muted-foreground">DNSSEC</h3>- {isLoading ? (- <Skeleton className="mt-1 h-4 w-16 rounded-sm" />- ) : (- <p className="text-sm">{data?.dnssec || 'Unavailable'}</p>- )}+ );+ }++ if (!data.registered) {+ return (+ <div className="my-8 flex flex-wrap gap-8">+ <WhoisQuickInfoTile title="Status" value="Not registered" /></div>+ );+ }++ return (+ <div className="my-8 flex flex-wrap gap-8">+ <WhoisQuickInfoTile+ title="Registar"+ value={data?.registrar || 'Unavailable'}+ />+ <WhoisQuickInfoTile+ title="Creation Date"+ value={data?.createdAt || 'Unavailable'}+ />+ <WhoisQuickInfoTile+ title="DNSSEC"+ value={data?.dnssec || 'Unavailable'}+ /></div>);};