@cleandns/whois-rdap 1.0.31 → 1.0.32

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
@@ -1,3 +1,4 @@
1
+ import { parseIpResponse } from "./ip.js";
1
2
  import { determinePort43Domain, port43 } from "./port43.js";
2
3
  import { findInObject } from "./utils/findInObject.js";
3
4
  import { fixArrays } from "./utils/fixArrays.js";
@@ -31,7 +32,8 @@ export async function whois(origDomain, options = { fetch: fetch, thinOnly: fals
31
32
  }
32
33
  url = "https://rdap.org";
33
34
  }
34
- const thinRdap = `${url}/domain/${domain}`;
35
+ const type = domain.match(/[^\d.]/) ? "domain" : "ip";
36
+ const thinRdap = `${url}/${type}/${domain}`;
35
37
  // console.log(`fetching thin RDAP: ${thinRdap}`);
36
38
  let thinResponse = await _fetch(thinRdap)
37
39
  .then((r) => r.json())
@@ -194,6 +196,8 @@ export async function whois(origDomain, options = { fetch: fetch, thinOnly: fals
194
196
  ...((thickResponse === null || thickResponse === void 0 ? void 0 : thickResponse.events) || []),
195
197
  ...((thinResponse === null || thinResponse === void 0 ? void 0 : thinResponse.events) || []),
196
198
  ]);
199
+ if (type === 'ip')
200
+ parseIpResponse(domain, thinResponse, response);
197
201
  return response;
198
202
  }
199
203
  function findStatus(statuses, domain) {
package/dist/ip.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { WhoisResponse } from "../whois.js";
2
+ export declare function parseIpResponse(ip: string, rdap: any, response: WhoisResponse): void;
package/dist/ip.js ADDED
@@ -0,0 +1,23 @@
1
+ export function parseIpResponse(ip, rdap, response) {
2
+ var _a, _b, _c;
3
+ response.found = Boolean(rdap.handle);
4
+ const registry = rdap.port43 ? rdap.port43.match(/\.(\w+)\./)[1].toUpperCase() : '';
5
+ const realRdapServer = (_c = (_b = (_a = rdap.links) === null || _a === void 0 ? void 0 : _a.find(({ rel }) => rel === 'self')) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.replace(/\/ip\/.*/, '/ip/');
6
+ response.server = realRdapServer || 'https://rdap.org/ip/';
7
+ response.identity = {
8
+ handle: rdap.handle,
9
+ ipRange: {
10
+ start: rdap.startAddress,
11
+ endAddress: rdap.endAddress
12
+ },
13
+ cidr: (rdap.cidr0_cidrs || []).map((cidr) => cidr.v4prefix + '/' + cidr.length),
14
+ name: rdap.name,
15
+ type: rdap.type,
16
+ parent: rdap.parentHandle,
17
+ ip,
18
+ };
19
+ response.registrar = {
20
+ id: 0,
21
+ name: registry,
22
+ };
23
+ }
@@ -60,5 +60,8 @@ export async function tldToRdap(domain) {
60
60
  // }
61
61
  // }
62
62
  }
63
+ else if (parsed.type === ParseResultType.Ip) {
64
+ return [domain, "https://rdap.org"];
65
+ }
63
66
  return [domain, null];
64
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleandns/whois-rdap",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { WhoisOptions, WhoisResponse, WhoisTimestampFields } from "../whois.js";
2
+ import { parseIpResponse } from "./ip.js";
2
3
  import { determinePort43Domain, port43 } from "./port43.js";
3
4
  import { findInObject } from "./utils/findInObject.js";
4
5
  import { fixArrays } from "./utils/fixArrays.js";
@@ -41,7 +42,9 @@ export async function whois(
41
42
  url = "https://rdap.org";
42
43
  }
43
44
 
44
- const thinRdap = `${url}/domain/${domain}`;
45
+ const type = domain.match(/[^\d.]/) ? "domain" : "ip";
46
+
47
+ const thinRdap = `${url}/${type}/${domain}`;
45
48
  // console.log(`fetching thin RDAP: ${thinRdap}`);
46
49
 
47
50
  let thinResponse = await _fetch(thinRdap)
@@ -308,6 +311,8 @@ export async function whois(
308
311
  ...(thinResponse?.events || []),
309
312
  ]);
310
313
 
314
+ if (type === 'ip') parseIpResponse(domain, thinResponse, response);
315
+
311
316
  return response;
312
317
  }
313
318
 
package/src/ip.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { WhoisResponse } from "../whois.js";
2
+
3
+ export function parseIpResponse(ip: string, rdap: any, response: WhoisResponse) {
4
+ response.found = Boolean(rdap.handle);
5
+
6
+ const registry = rdap.port43 ? rdap.port43.match(/\.(\w+)\./)[1].toUpperCase() : '';
7
+ const realRdapServer = rdap.links?.find(({ rel }: { rel: string }) => rel === 'self')?.value?.replace(/\/ip\/.*/, '/ip/');
8
+
9
+ response.server = realRdapServer || 'https://rdap.org/ip/';
10
+
11
+ response.identity = {
12
+ handle: rdap.handle,
13
+ ipRange: {
14
+ start: rdap.startAddress,
15
+ endAddress: rdap.endAddress
16
+ },
17
+ cidr: (rdap.cidr0_cidrs || []).map((cidr: any) => cidr.v4prefix + '/' + cidr.length),
18
+ name: rdap.name,
19
+ type: rdap.type,
20
+ parent: rdap.parentHandle,
21
+ ip,
22
+ };
23
+
24
+ response.registrar = {
25
+ id: 0,
26
+ name: registry,
27
+ };
28
+ }
@@ -73,6 +73,9 @@ export async function tldToRdap(
73
73
  // }
74
74
  // }
75
75
  }
76
+ else if (parsed.type === ParseResultType.Ip) {
77
+ return [domain, "https://rdap.org"];
78
+ }
76
79
 
77
80
  return [domain, null];
78
81
  }
package/whois.d.ts CHANGED
@@ -21,4 +21,16 @@ export type WhoisResponse = {
21
21
  updated: Date | null;
22
22
  expires: Date | null;
23
23
  };
24
+ identity?: {
25
+ handle: string;
26
+ ipRange: {
27
+ start: string;
28
+ endAddress: string;
29
+ };
30
+ cidr: string[];
31
+ name: string;
32
+ type: string;
33
+ parent: string | null;
34
+ ip: string;
35
+ }
24
36
  };