@cleandns/whois-rdap 1.0.40 → 1.0.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -41,23 +41,24 @@ export async function whois(origDomain, options = { fetch: fetch, thinOnly: fals
41
41
  url = "https://rdap.org";
42
42
  }
43
43
  const type = domain.match(/[^\d.]/) ? "domain" : "ip";
44
+ let thinResponse = null;
44
45
  const thinRdap = `${url}/${type}/${domain}`;
45
46
  // console.log(`fetching thin RDAP: ${thinRdap}`);
46
- let thinResponse = await _fetch(thinRdap)
47
+ thinResponse = await _fetch(thinRdap)
47
48
  .then((r) => r.json())
48
49
  .catch(() => null);
49
50
  if (thinResponse && !thinResponse.errorCode) {
50
51
  }
51
- else {
52
+ else if (!options.server) {
52
53
  return response;
53
54
  }
54
55
  if ((_a = thinResponse === null || thinResponse === void 0 ? void 0 : thinResponse.rdapConformance) === null || _a === void 0 ? void 0 : _a["0"]) {
55
56
  thinResponse = fixArrays(thinResponse);
56
57
  }
57
- const selfRdap = (_b = thinResponse.links) === null || _b === void 0 ? void 0 : _b.find((link) => link.rel === "self");
58
- const thickRdap = (_d = (_c = thinResponse.links) === null || _c === void 0 ? void 0 : _c.find((link) => link.href !== (selfRdap === null || selfRdap === void 0 ? void 0 : selfRdap.href) &&
58
+ const selfRdap = (_b = thinResponse === null || thinResponse === void 0 ? void 0 : thinResponse.links) === null || _b === void 0 ? void 0 : _b.find((link) => link.rel === "self");
59
+ const thickRdap = ((_d = (_c = thinResponse.links) === null || _c === void 0 ? void 0 : _c.find((link) => link.href !== (selfRdap === null || selfRdap === void 0 ? void 0 : selfRdap.href) &&
59
60
  link.rel === "related" &&
60
- link.type === "application/rdap+json")) === null || _d === void 0 ? void 0 : _d.href.replace("/domain/domain/", "/domain/");
61
+ link.type === "application/rdap+json")) === null || _d === void 0 ? void 0 : _d.href.replace("/domain/domain/", "/domain/")) || `${options.server}/domain/${domain}`;
61
62
  let thickResponse = null;
62
63
  if (!options.thinOnly && thickRdap) {
63
64
  // console.log(`fetching thick RDAP: ${thickRdap}`);
package/dist/test.js CHANGED
@@ -1,2 +1,2 @@
1
1
  import { whois } from "./index.js";
2
- whois(process.argv[2], { thinOnly: Boolean(process.argv[3]) }).then((r) => console.log(JSON.stringify(r, undefined, 2)));
2
+ whois(process.argv[2], { thinOnly: Boolean(process.argv[3]), server: process.argv[4] }).then((r) => console.log(JSON.stringify(r, undefined, 2)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleandns/whois-rdap",
3
- "version": "1.0.40",
3
+ "version": "1.0.44",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/index.ts CHANGED
@@ -40,7 +40,7 @@ export async function whois(
40
40
  const host = new URL(url).host;
41
41
  /* check for A record via DNS lookup */
42
42
  const isLive = await resolve4(host).then((r) => Boolean(r?.length)).catch(() => false);
43
- if (! isLive) url = null;
43
+ if (!isLive) url = null;
44
44
  }
45
45
 
46
46
  if (url === null) {
@@ -51,15 +51,16 @@ export async function whois(
51
51
  }
52
52
 
53
53
  const type = domain.match(/[^\d.]/) ? "domain" : "ip";
54
-
54
+ let thinResponse: any = null;
55
55
  const thinRdap = `${url}/${type}/${domain}`;
56
+
56
57
  // console.log(`fetching thin RDAP: ${thinRdap}`);
57
58
 
58
- let thinResponse = await _fetch(thinRdap)
59
+ thinResponse = await _fetch(thinRdap)
59
60
  .then((r) => r.json() as any)
60
61
  .catch(() => null);
61
62
  if (thinResponse && !thinResponse.errorCode) {
62
- } else {
63
+ } else if (!options.server) {
63
64
  return response;
64
65
  }
65
66
 
@@ -67,7 +68,8 @@ export async function whois(
67
68
  thinResponse = fixArrays(thinResponse);
68
69
  }
69
70
 
70
- const selfRdap = thinResponse.links?.find((link: any) => link.rel === "self");
71
+ const selfRdap = thinResponse?.links?.find((link: any) => link.rel === "self");
72
+
71
73
  const thickRdap = thinResponse.links
72
74
  ?.find(
73
75
  (link: any) =>
@@ -75,7 +77,7 @@ export async function whois(
75
77
  link.rel === "related" &&
76
78
  link.type === "application/rdap+json"
77
79
  )
78
- ?.href.replace("/domain/domain/", "/domain/");
80
+ ?.href.replace("/domain/domain/", "/domain/") || `${options.server}/domain/${domain}`;
79
81
 
80
82
  let thickResponse: any = null;
81
83
 
package/src/test.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { whois } from "./index.js";
2
2
 
3
- whois(process.argv[2], { thinOnly: Boolean(process.argv[3]) }).then((r) =>
3
+ whois(process.argv[2], { thinOnly: Boolean(process.argv[3]), server: process.argv[4] }).then((r) =>
4
4
  console.log(JSON.stringify(r, undefined, 2))
5
5
  );
package/whois.d.ts CHANGED
@@ -3,6 +3,7 @@ export type WhoisTimestampFields = "created" | "updated" | "expires";
3
3
  export type WhoisOptions = Partial<{
4
4
  fetch: typeof fetch;
5
5
  thinOnly: boolean;
6
+ server: string;
6
7
  }>;
7
8
 
8
9
  export type WhoisResponse = {