smartwhois/ts/index.ts

78 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-04-03 14:48:14 +00:00
import * as plugins from './smartwhois.plugins.js';
2023-04-10 12:34:28 +00:00
export interface IWhoisInfo {
domain: string;
2023-04-10 12:42:24 +00:00
isRegistered: boolean;
domainStatus: Array<
| 'clientTransferProhibited'
| 'clientUpdateProhibited'
| 'clientDeleteProhibited'
| 'clientHold'
| 'serverTransferProhibited'
| 'serverUpdateProhibited'
| 'serverDeleteProhibited'
| 'serverHold'
| 'inactive'
| 'pendingDelete'
| 'pendingRenew'
| 'pendingTransfer'
| 'pendingUpdate'
| 'ok'>;
2023-04-10 12:34:28 +00:00
domainWithoutSuffix: string;
hostname: string;
isIcann: boolean;
isIp: boolean;
isPrivate: boolean;
publicSuffix: string;
subdomain: string;
dnsSec: 'signedDelegation' | 'unsigned';
originalWhoisInfo: {
[key: string]: any;
};
whoisServers: string[];
registrar: string;
registrarUrl: string;
createdDate: string;
updatedDate: string;
expiryDate: string;
}
2023-04-03 14:48:14 +00:00
export class SmartWhois {
2023-04-10 12:42:24 +00:00
public async getWhoisForDomain(domainArg: string): Promise<IWhoisInfo> {
2023-04-03 14:48:14 +00:00
const whoisInfo = await plugins.whoiser.domain(domainArg);
const whoisServers = Object.keys(whoisInfo);
const selectedWhoisInfo: any = whoisInfo[whoisServers[0]];
const registrar = selectedWhoisInfo.Registrar;
const registrarUrl = selectedWhoisInfo['Registrar URL'];
const createdDate = selectedWhoisInfo['Created Date'];
const updatedDate = selectedWhoisInfo['Updated Date'];
const expiryDate = selectedWhoisInfo['Expiry Date'];
2023-04-10 12:34:28 +00:00
const tldtsData = plugins.tldts.parse(domainArg);
2023-04-03 14:48:14 +00:00
return {
2023-04-10 12:34:28 +00:00
...tldtsData,
isRegistered: true,
2023-04-10 12:42:24 +00:00
domainStatus: selectedWhoisInfo['Domain Status'].map((statusArg: string) => statusArg.split(' ')[0]),
2023-04-10 12:34:28 +00:00
dnsSec: selectedWhoisInfo['DNSSEC'],
2023-04-03 14:48:14 +00:00
originalWhoisInfo: whoisInfo,
whoisServers,
registrar,
registrarUrl,
createdDate,
updatedDate,
expiryDate,
};
}
2023-04-03 15:50:55 +00:00
public async isValidTld(tldArg: string): Promise<boolean> {
const allTlds = await plugins.whoiser.allTlds();
const sanatizedTld = tldArg.startsWith('.')
? tldArg.replace('.', '').toUpperCase()
: tldArg.toUpperCase();
return allTlds.includes(sanatizedTld);
}
2023-04-03 14:48:14 +00:00
public async getWhoisForIp(ipArg: string) {}
2023-04-03 15:50:55 +00:00
}