fix(whois): improve type safety and harden WHOIS parsing for missing fields

This commit is contained in:
2026-05-01 16:20:47 +00:00
parent dc3288cc51
commit c7d2b13c8b
11 changed files with 3637 additions and 4135 deletions
+37
View File
@@ -0,0 +1,37 @@
{
"@git.zone/cli": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartwhois",
"shortDescription": "execute WHOIS requests",
"npmPackagename": "@push.rocks/smartwhois",
"license": "MIT",
"description": "A package for executing WHOIS requests and processing domain and IP information.",
"keywords": [
"WHOIS",
"domain information",
"IP lookup",
"TLD validation",
"DNSSEC status",
"HTTP status checker",
"TypeScript"
]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
}
},
"@git.zone/tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
},
"@ship.zone/szci": {
"npmGlobalTools": [],
"npmRegistryUrl": "registry.npmjs.org"
}
}
+51
View File
@@ -0,0 +1,51 @@
# Changelog
## 2026-05-01 - 1.0.17 - fix(whois)
improve type safety and harden WHOIS parsing for missing fields
- add explicit additional WHOIS data interface and return types
- default parsed domain and WHOIS fields to safe fallback values to avoid undefined access
- normalize Domain Status handling for both string and array responses
- update test entrypoint to test.node.ts and align tooling and build scripts with newer dependencies
## 2025-07-29 - 1.0.16 - maintenance
Routine maintenance updates for v1.0.16 after the initial release.
- Updated project description
- Updated TypeScript configuration
- Updated `npmextra.json` git host settings
- Included a general maintenance update
## 2023-10-06 - 1.0.16 - release
Released v1.0.16.
- Published version 1.0.16
- Included a core update carried forward from the previous patch cycle
## 2023-10-06 - 1.0.15 - core
Applied a core fix update.
- Updated core behavior in v1.0.15
## 2023-04-19 - 1.0.14 - core
Patch releases from v1.0.8 through v1.0.14 consisted primarily of repeated core maintenance updates.
- Released versions 1.0.8 through 1.0.14
- Applied recurring `fix(core): update` changes across the patch range
## 2023-04-18 - 1.0.8 - release
Released v1.0.8.
- Published version 1.0.8
## 2023-04-10 - 1.0.7 - core
Patch releases from v1.0.4 through v1.0.7 focused on small core fixes.
- Released versions 1.0.4 through 1.0.7
- Applied recurring `fix(core): update` changes across the patch range
## 2023-04-03 - 1.0.4 - core
Initial patch series from v1.0.1 through v1.0.3 contained minor core fixes.
- Released versions 1.0.1 through 1.0.3
- Applied recurring `fix(core): update` changes across the patch range
+19
View File
@@ -0,0 +1,19 @@
Copyright (c) 2026 Task Venture Capital GmbH <hello@task.vc>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+15 -8
View File
@@ -1,14 +1,14 @@
{
"gitzone": {
"@git.zone/cli": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartwhois",
"description": "A package for executing WHOIS requests and processing domain and IP information.",
"shortDescription": "execute WHOIS requests",
"npmPackagename": "@push.rocks/smartwhois",
"license": "MIT",
"projectDomain": "push.rocks",
"description": "A package for executing WHOIS requests and processing domain and IP information.",
"keywords": [
"WHOIS",
"domain information",
@@ -18,13 +18,20 @@
"HTTP status checker",
"TypeScript"
]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
}
},
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"tsdoc": {
"@git.zone/tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
},
"@ship.zone/szci": {
"npmGlobalTools": [],
"npmRegistryUrl": "registry.npmjs.org"
}
}
+16 -12
View File
@@ -6,26 +6,28 @@
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"author": "Task Venture Capital GmbH",
"author": "Task Venture Capital GmbH <hello@task.vc>",
"license": "MIT",
"scripts": {
"test": "(tstest test/ --verbose)",
"build": "(tsbuild --web --allowimplicitany)",
"test": "tstest test/ --verbose",
"format": "gitzone format",
"build": "tsbuild --web",
"buildDocs": "tsdoc"
},
"devDependencies": {
"@git.zone/tsbuild": "^2.1.65",
"@git.zone/tsbundle": "^2.0.7",
"@git.zone/tsrun": "^1.2.39",
"@git.zone/tstest": "^2.3.2",
"@types/node": "^22"
"@git.zone/tsbuild": "^4.4.0",
"@git.zone/tsbundle": "^2.10.1",
"@git.zone/tsrun": "^2.0.3",
"@git.zone/tstest": "^3.6.3",
"@types/node": "^25.6.0",
"why-is-node-running": "^3.2.2"
},
"dependencies": {
"@push.rocks/smartrequest": "^4.0.1",
"@push.rocks/smartrequest": "^5.0.1",
"@push.rocks/smarturl": "^3.0.6",
"@tsclass/tsclass": "^9.2.0",
"tldts": "^7.0.10",
"whoiser": "^1.16.0"
"@tsclass/tsclass": "^9.5.1",
"tldts": "^7.0.29",
"whoiser": "^1.18.0"
},
"browserslist": [
"last 1 chrome versions"
@@ -39,6 +41,8 @@
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
".smartconfig.json",
"license",
"npmextra.json",
"readme.md"
],
+3441 -4082
View File
File diff suppressed because it is too large Load Diff
+4 -2
View File
@@ -38,6 +38,8 @@ tap.test('should check for a valid tld', async () => {
const comIsValid = await testSmartWhois.isValidTld('.com');
console.log(comIsValid);
expect(comIsValid).toBeTrue();
})
});
tap.start();
export default tap.start({
throwOnError: true
});
+3 -3
View File
@@ -1,8 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartwhois',
version: '1.0.16',
description: 'a package for dealing with whois requests'
version: '1.0.17',
description: 'A package for executing WHOIS requests and processing domain and IP information.'
}
+43 -20
View File
@@ -37,6 +37,13 @@ export interface IWhoisInfo {
expiryDate: string;
}
export interface IAdditionalWhoisData {
httpStatus: number;
httpsStatus: number;
httpHeaders: unknown;
httpsHeaders: unknown;
}
export class SmartWhois {
/**
* can be used to prepare an input for the whois command
@@ -50,15 +57,15 @@ export class SmartWhois {
return {
fullUrl: smarturlInstance.toString(),
fullDomain: smarturlInstance.hostname,
domain: tldtsData.domain,
publicSuffix: tldtsData.publicSuffix,
subdomain: tldtsData.subdomain,
domainWithoutSuffix: tldtsData.domainWithoutSuffix,
isIcann: tldtsData.isIcann,
}
domain: tldtsData.domain ?? '',
publicSuffix: tldtsData.publicSuffix ?? '',
subdomain: tldtsData.subdomain ?? '',
domainWithoutSuffix: tldtsData.domainWithoutSuffix ?? '',
isIcann: tldtsData.isIcann ?? undefined,
};
}
public async getAdditionalWhoisDataForDomain(domainArg: string) {
public async getAdditionalWhoisDataForDomain(domainArg: string): Promise<IAdditionalWhoisData> {
if (domainArg.includes('//')) {
const parsedUrlResult = await this.getDomainDelegation(domainArg);
domainArg = parsedUrlResult.fullDomain;
@@ -79,11 +86,9 @@ export class SmartWhois {
httpsStatus: httpsResult.status,
httpHeaders: httpResult.headers,
httpsHeaders: httpsResult.headers,
};
}
}
public async getWhoisForDomain(domainArg: string): Promise<IWhoisInfo> {
if (domainArg.includes('//')) {
const parsedUrlResult = await this.getDomainDelegation(domainArg);
@@ -91,21 +96,39 @@ export class SmartWhois {
}
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'];
const selectedWhoisInfo = whoisInfo[whoisServers[0]] as Record<string, unknown>;
const getStringField = (fieldName: string): string => {
const fieldValue = selectedWhoisInfo[fieldName];
return typeof fieldValue === 'string' ? fieldValue : '';
};
const registrar = getStringField('Registrar');
const registrarUrl = getStringField('Registrar URL');
const createdDate = getStringField('Created Date');
const updatedDate = getStringField('Updated Date');
const expiryDate = getStringField('Expiry Date');
const domainStatusRaw = selectedWhoisInfo['Domain Status'];
const domainStatusSource = Array.isArray(domainStatusRaw)
? domainStatusRaw
: typeof domainStatusRaw === 'string'
? [domainStatusRaw]
: [];
const domainStatus = domainStatusSource.map((statusArg) => String(statusArg).split(' ')[0]) as IWhoisInfo['domainStatus'];
const tldtsData = plugins.tldts.parse(domainArg);
return {
...tldtsData,
domain: tldtsData.domain ?? '',
domainWithoutSuffix: tldtsData.domainWithoutSuffix ?? '',
hostname: tldtsData.hostname ?? '',
isIcann: tldtsData.isIcann ?? false,
isIp: tldtsData.isIp ?? false,
isPrivate: tldtsData.isPrivate ?? false,
publicSuffix: tldtsData.publicSuffix ?? '',
subdomain: tldtsData.subdomain ?? '',
isRegistered: true,
domainStatus: selectedWhoisInfo['Domain Status'].map((statusArg: string) => statusArg.split(' ')[0]),
dnsSec: selectedWhoisInfo['DNSSEC'],
originalWhoisInfo: whoisInfo,
domainStatus,
dnsSec: getStringField('DNSSEC') as IWhoisInfo['dnsSec'],
originalWhoisInfo: whoisInfo as Record<string, unknown>,
whoisServers,
registrar,
registrarUrl,
+3 -3
View File
@@ -3,7 +3,7 @@ import * as tsclass from '@tsclass/tsclass';
export {
tsclass,
}
};
// pushrocks scope
import * as smarturl from '@push.rocks/smarturl';
@@ -12,7 +12,7 @@ import * as smartrequest from '@push.rocks/smartrequest';
export {
smarturl,
smartrequest,
}
};
// third party
import * as whoiser from 'whoiser';
@@ -21,4 +21,4 @@ import tldts from 'tldts';
export {
whoiser,
tldts,
}
};
+4 -4
View File
@@ -5,10 +5,10 @@
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noImplicitAny": true,
"esModuleInterop": true,
"verbatimModuleSyntax": true
"verbatimModuleSyntax": true,
"types": ["node"]
},
"exclude": [
"dist_*/**/*.d.ts"
]
"exclude": ["dist_*/**/*.d.ts"]
}