@cleandns/whois-rdap 1.0.15 → 1.0.17

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.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import { WhoisOptions, WhoisResponse } from "../whois.js";
2
- export declare function whois(domain: string, options?: WhoisOptions): Promise<WhoisResponse>;
2
+ export declare function whois(origDomain: string, options?: WhoisOptions): Promise<WhoisResponse>;
package/dist/index.js CHANGED
@@ -10,11 +10,12 @@ const eventMap = new Map([
10
10
  ["expiration", "expires"],
11
11
  ["expiration date", "expires"],
12
12
  ]);
13
- export async function whois(domain, options = { fetch: fetch }) {
13
+ export async function whois(origDomain, options = { fetch: fetch }) {
14
14
  var _a, _b, _c, _d, _e, _f;
15
15
  const fetch = options.fetch;
16
+ let domain = origDomain;
16
17
  let url = null;
17
- [domain, url] = await tldToRdap(domain);
18
+ [domain, url] = await tldToRdap(origDomain);
18
19
  const response = {
19
20
  found: false,
20
21
  registrar: { id: 0, name: null },
@@ -87,10 +88,11 @@ export async function whois(domain, options = { fetch: fetch }) {
87
88
  ((_d = pubIds.find((id) => id.type === "IANA Registrar ID")) === null || _d === void 0 ? void 0 : _d.Identifier) ||
88
89
  ((_e = pubIds.find((id) => id.type === "IANA Registrar ID")) === null || _e === void 0 ? void 0 : _e.identifier);
89
90
  if (reg) {
91
+ console.log(ent.vcardArray);
90
92
  const id = reg;
91
- const name = parseInt(id) == id
92
- ? (_f = (await ianaIdToRegistrar(parseInt(id)))) === null || _f === void 0 ? void 0 : _f.name
93
- : findInObject(ent.vcardArray, (el) => Array.isArray(el) && (el[0] === "fn" || el[0] === "org"), (el) => el[3], reg);
93
+ const name = (parseInt(id) == id
94
+ && ((_f = (await ianaIdToRegistrar(parseInt(id)))) === null || _f === void 0 ? void 0 : _f.name))
95
+ || findInObject(ent.vcardArray, (el) => Array.isArray(el) && (el[0] === "fn" || el[0] === "org"), (el) => el[3], reg);
94
96
  const email = ((_g = [ent, ...(ent.entities || [])]
95
97
  .filter((e) => e === null || e === void 0 ? void 0 : e.vcardArray)
96
98
  .map((e) => findInObject(e.vcardArray, (el) => Array.isArray(el) && el[0] === "email", (el) => el[3], ""))
@@ -102,9 +104,9 @@ export async function whois(domain, options = { fetch: fetch }) {
102
104
  if (domain.endsWith(".is") &&
103
105
  (((_h = ent.roles) === null || _h === void 0 ? void 0 : _h.includes("technical")) || ent.role === "technical")) {
104
106
  const id = ent.handle;
105
- const name = parseInt(id) == id
106
- ? (_j = (await ianaIdToRegistrar(parseInt(id)))) === null || _j === void 0 ? void 0 : _j.name
107
- : findInObject(ent.vcardArray, (el) => Array.isArray(el) && (el[0] === "fn" || el[0] === "org"), (el) => el[3], id);
107
+ const name = (parseInt(id) == id
108
+ && ((_j = (await ianaIdToRegistrar(parseInt(id)))) === null || _j === void 0 ? void 0 : _j.name))
109
+ || findInObject(ent.vcardArray, (el) => Array.isArray(el) && (el[0] === "fn" || el[0] === "org"), (el) => el[3], id);
108
110
  const email = ((_k = [ent, ...(ent.entities || [])]
109
111
  .filter((e) => e === null || e === void 0 ? void 0 : e.vcardArray)
110
112
  .map((e) => findInObject(e.vcardArray, (el) => Array.isArray(el) && el[0] === "email", (el) => el[3], ""))
package/dist/port43.js CHANGED
@@ -21,9 +21,10 @@ export function determinePort43Domain(actor) {
21
21
  return [actor, "", null];
22
22
  }
23
23
  export async function port43(actor) {
24
- var _a, _b, _c;
24
+ var _a, _b, _c, _d;
25
25
  const [domain, tld, whoisServer] = determinePort43Domain(actor);
26
26
  const opts = whoisServer;
27
+ const isWwww = opts === null || opts === void 0 ? void 0 : opts.url;
27
28
  const server = (opts === null || opts === void 0 ? void 0 : opts.host) || opts || null;
28
29
  const query = (opts === null || opts === void 0 ? void 0 : opts.query)
29
30
  ? opts.query.replace("$addr", domain)
@@ -43,14 +44,21 @@ export async function port43(actor) {
43
44
  }
44
45
  let port43response = "";
45
46
  try {
46
- const promiseSocket = new PromiseSocket(new Socket());
47
- promiseSocket.setTimeout(5 * 1000);
48
- await promiseSocket.connect(port, server);
49
- await promiseSocket.write(query);
50
- port43response = (await promiseSocket.readAll())
51
- .toString()
52
- .replace(/^[ \t]+/gm, "");
53
- await promiseSocket.end();
47
+ if (isWwww) {
48
+ port43response = (await fetch(opts.url.replace('%%domain%%', domain)).then(r => r.text())).toString().replace(/^[ \t]+/gm, "");
49
+ response.server = (_a = opts.url.match('//(.*?)/')) === null || _a === void 0 ? void 0 : _a[1];
50
+ }
51
+ else {
52
+ response.server = server;
53
+ const promiseSocket = new PromiseSocket(new Socket());
54
+ promiseSocket.setTimeout(5 * 1000);
55
+ await promiseSocket.connect(port, server);
56
+ await promiseSocket.write(query);
57
+ port43response = (await promiseSocket.readAll())
58
+ .toString()
59
+ .replace(/^[ \t]+/gm, "");
60
+ await promiseSocket.end();
61
+ }
54
62
  }
55
63
  catch (error) {
56
64
  response.found = false;
@@ -63,7 +71,7 @@ export async function port43(actor) {
63
71
  return response;
64
72
  }
65
73
  let m;
66
- const parser = port43parsers[tld] || ((_a = Object.entries(port43parsers).find(([t]) => tld.endsWith('.' + t))) === null || _a === void 0 ? void 0 : _a[1]);
74
+ const parser = port43parsers[tld] || ((_b = Object.entries(port43parsers).find(([t]) => tld.endsWith('.' + t))) === null || _b === void 0 ? void 0 : _b[1]);
67
75
  if (parser) {
68
76
  await parser(port43response, response);
69
77
  }
@@ -85,12 +93,12 @@ export async function port43(actor) {
85
93
  !response.ts.expires &&
86
94
  (m = port43response.match(/^(?:(?:Registry )?Expiry Date):[ \t]*(\S.+)/m)) &&
87
95
  (response.ts.expires = new Date(m[1]) || null);
88
- !((_b = response.status) === null || _b === void 0 ? void 0 : _b.length) && (m = port43response.match(/^(?:Status|Domain Status|status):.*/gm)) &&
96
+ !((_c = response.status) === null || _c === void 0 ? void 0 : _c.length) && (m = port43response.match(/^(?:Status|Domain Status|status):.*/gm)) &&
89
97
  m.forEach((s) => {
90
98
  let m;
91
99
  (m = s.match(/^(?:Status|Domain Status|status):[ \t]*(?:<a[^>]*>)?(\S+)/m)) && response.status.push(normalizeWhoisStatus(m[1]));
92
100
  });
93
- !((_c = response.nameservers) === null || _c === void 0 ? void 0 : _c.length) && (m = port43response.match(/^(?:Name Server|ns_name_\d+|namserver|nserver):.*/gm)) &&
101
+ !((_d = response.nameservers) === null || _d === void 0 ? void 0 : _d.length) && (m = port43response.match(/^(?:Name Server|ns_name_\d+|namserver|nserver):.*/gm)) &&
94
102
  m.forEach((s) => {
95
103
  let m;
96
104
  (m = s.match(/^(?:Name Server|ns_name_\d+|namserver|nserver):[ \t]*(\S+)/m)) && response.nameservers.push(m[1].toLowerCase());
@@ -147,6 +147,9 @@ export const port43servers = {
147
147
  "uy.com": "whois.centralnic.net",
148
148
  "web.com": "whois.centralnic.net",
149
149
  "za.com": "whois.centralnic.net",
150
+ "it.com": {
151
+ url: `https://engine.itcomdomains.com/api/v1/domain/%%domain%%/whois_info`,
152
+ },
150
153
  com: {
151
154
  host: "whois.verisign-grs.com",
152
155
  query: "DOMAIN $addr\r\n",
@@ -1,6 +1,7 @@
1
1
  import { ParseResultType, parseDomain } from "parse-domain";
2
2
  const tldCache = new Map([]);
3
3
  const tldCachePresets = [
4
+ ["it.com", null],
4
5
  ["br.com", "https://rdap.centralnic.com/br.com"],
5
6
  ["cn.com", "https://rdap.centralnic.com/cn.com"],
6
7
  ["de.com", "https://rdap.centralnic.com/de.com"],
@@ -33,7 +34,7 @@ export async function tldToRdap(domain) {
33
34
  const response = await fetch(`https://data.iana.org/rdap/dns.json`).then((r) => r.json());
34
35
  for (const [tlds, urls] of response.services) {
35
36
  for (const tld of tlds) {
36
- tldCache.set(tld, urls[0].replace(/\/$/, ''));
37
+ tldCache.set(tld, urls[0].replace(/\/$/, ""));
37
38
  }
38
39
  }
39
40
  }
@@ -41,11 +42,11 @@ export async function tldToRdap(domain) {
41
42
  if (parsed.type === ParseResultType.Listed) {
42
43
  let tld = parsed.topLevelDomains.join(".");
43
44
  if (tldCache.has(tld)) {
44
- return [parsed.domain + '.' + tld, tldCache.get(tld)];
45
+ return [parsed.domain + "." + tld, tldCache.get(tld)];
45
46
  }
46
47
  tld = parsed.icann.topLevelDomains.join(".");
47
48
  if (tldCache.has(tld)) {
48
- return [parsed.icann.domain + '.' + tld, tldCache.get(tld)];
49
+ return [parsed.icann.domain + "." + tld, tldCache.get(tld)];
49
50
  }
50
51
  // const tlds = [
51
52
  // parsed.topLevelDomains.join("."),
@@ -0,0 +1 @@
1
+ export declare const loadWWWServers: Record<string, string>;
@@ -0,0 +1,3 @@
1
+ export const loadWWWServers = {
2
+ "it.com": `https://engine.itcomdomains.com/api/v1/domain/%%domain%%/whois_info`
3
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleandns/whois-rdap",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/index.ts CHANGED
@@ -14,13 +14,15 @@ const eventMap = new Map<string, WhoisTimestampFields>([
14
14
  ]);
15
15
 
16
16
  export async function whois(
17
- domain: string,
17
+ origDomain: string,
18
18
  options: WhoisOptions = { fetch: fetch }
19
19
  ): Promise<WhoisResponse> {
20
20
  const fetch = options.fetch!;
21
21
 
22
+ let domain = origDomain;
22
23
  let url: string | null = null;
23
- [domain, url] = await tldToRdap(domain);
24
+
25
+ [domain, url] = await tldToRdap(origDomain);
24
26
 
25
27
  const response: WhoisResponse = {
26
28
  found: false,
@@ -115,11 +117,12 @@ export async function whois(
115
117
  pubIds.find((id: any) => id.type === "IANA Registrar ID")?.identifier;
116
118
 
117
119
  if (reg) {
120
+ console.log(ent.vcardArray);
118
121
  const id = reg;
119
122
  const name =
120
- parseInt(id) == id
121
- ? (await ianaIdToRegistrar(parseInt(id)))?.name
122
- : findInObject(
123
+ (parseInt(id) == id
124
+ && (await ianaIdToRegistrar(parseInt(id)))?.name)
125
+ || findInObject(
123
126
  ent.vcardArray,
124
127
  (el: any) =>
125
128
  Array.isArray(el) && (el[0] === "fn" || el[0] === "org"),
@@ -151,9 +154,9 @@ export async function whois(
151
154
  ) {
152
155
  const id = ent.handle;
153
156
  const name =
154
- parseInt(id) == id
155
- ? (await ianaIdToRegistrar(parseInt(id)))?.name
156
- : findInObject(
157
+ (parseInt(id) == id
158
+ && (await ianaIdToRegistrar(parseInt(id)))?.name)
159
+ || findInObject(
157
160
  ent.vcardArray,
158
161
  (el: any) =>
159
162
  Array.isArray(el) && (el[0] === "fn" || el[0] === "org"),
package/src/port43.ts CHANGED
@@ -29,6 +29,7 @@ export function determinePort43Domain(actor: string) {
29
29
  export async function port43(actor: string): Promise<WhoisResponse> {
30
30
  const [domain, tld, whoisServer] = determinePort43Domain(actor);
31
31
  const opts = whoisServer;
32
+ const isWwww = opts?.url;
32
33
  const server = opts?.host || opts || null;
33
34
  const query = opts?.query
34
35
  ? opts.query.replace("$addr", domain)
@@ -53,14 +54,21 @@ export async function port43(actor: string): Promise<WhoisResponse> {
53
54
  let port43response = "";
54
55
 
55
56
  try {
56
- const promiseSocket = new PromiseSocket(new Socket());
57
- promiseSocket.setTimeout(5 * 1000);
58
- await promiseSocket.connect(port, server);
59
- await promiseSocket.write(query);
60
- port43response = (await promiseSocket.readAll())!
61
- .toString()
62
- .replace(/^[ \t]+/gm, "");
63
- await promiseSocket.end();
57
+ if (isWwww) {
58
+ port43response = (await fetch(opts.url.replace('%%domain%%', domain)).then(r => r.text())).toString().replace(/^[ \t]+/gm, "");
59
+ response.server = opts.url.match('//(.*?)/')?.[1];
60
+ }
61
+ else {
62
+ response.server = server;
63
+ const promiseSocket = new PromiseSocket(new Socket());
64
+ promiseSocket.setTimeout(5 * 1000);
65
+ await promiseSocket.connect(port, server);
66
+ await promiseSocket.write(query);
67
+ port43response = (await promiseSocket.readAll())!
68
+ .toString()
69
+ .replace(/^[ \t]+/gm, "");
70
+ await promiseSocket.end();
71
+ }
64
72
  } catch (error) {
65
73
  response.found = false;
66
74
  }
@@ -187,6 +187,11 @@ export const port43servers: Record<string, any> = {
187
187
  "uy.com": "whois.centralnic.net",
188
188
  "web.com": "whois.centralnic.net",
189
189
  "za.com": "whois.centralnic.net",
190
+
191
+ "it.com": {
192
+ url: `https://engine.itcomdomains.com/api/v1/domain/%%domain%%/whois_info`,
193
+ },
194
+
190
195
  com: {
191
196
  host: "whois.verisign-grs.com",
192
197
  query: "DOMAIN $addr\r\n",
@@ -1,8 +1,9 @@
1
1
  import { ParseResultType, parseDomain } from "parse-domain";
2
2
 
3
3
  type TldToRdap = [string[], string[]];
4
- const tldCache = new Map<string, string>([]);
5
- const tldCachePresets = [
4
+ const tldCache = new Map<string, string | null>([]);
5
+ const tldCachePresets: [string, string | null][] = [
6
+ ["it.com", null],
6
7
  ["br.com", "https://rdap.centralnic.com/br.com"],
7
8
  ["cn.com", "https://rdap.centralnic.com/cn.com"],
8
9
  ["de.com", "https://rdap.centralnic.com/de.com"],
@@ -27,20 +28,22 @@ const tldCachePresets = [
27
28
  ["za.com", "https://rdap.centralnic.com/za.com"],
28
29
  ];
29
30
 
30
- export async function tldToRdap(domain: string): Promise<[ string, string | null ]> {
31
+ export async function tldToRdap(
32
+ domain: string
33
+ ): Promise<[string, string | null]> {
31
34
  if (tldCache.size === 0) {
32
35
  for (const [tld, url] of tldCachePresets) {
33
36
  tldCache.set(tld, url);
34
37
  }
35
38
 
36
39
  // console.warn(`fetching tld-to-rdap`);
37
- const response: { services: TldToRdap[]; } = await fetch(
40
+ const response: { services: TldToRdap[] } = await fetch(
38
41
  `https://data.iana.org/rdap/dns.json`
39
42
  ).then((r) => r.json() as any);
40
43
 
41
44
  for (const [tlds, urls] of response.services) {
42
45
  for (const tld of tlds) {
43
- tldCache.set(tld, urls[0].replace(/\/$/, ''));
46
+ tldCache.set(tld, urls[0].replace(/\/$/, ""));
44
47
  }
45
48
  }
46
49
  }
@@ -50,11 +53,11 @@ export async function tldToRdap(domain: string): Promise<[ string, string | null
50
53
  if (parsed.type === ParseResultType.Listed) {
51
54
  let tld = parsed.topLevelDomains.join(".");
52
55
  if (tldCache.has(tld)) {
53
- return [ parsed.domain + '.' + tld, tldCache.get(tld)! ];
56
+ return [parsed.domain + "." + tld, tldCache.get(tld)!];
54
57
  }
55
58
  tld = parsed.icann.topLevelDomains.join(".");
56
59
  if (tldCache.has(tld)) {
57
- return [ parsed.icann.domain + '.' + tld, tldCache.get(tld)! ];
60
+ return [parsed.icann.domain + "." + tld, tldCache.get(tld)!];
58
61
  }
59
62
 
60
63
  // const tlds = [
@@ -69,5 +72,5 @@ export async function tldToRdap(domain: string): Promise<[ string, string | null
69
72
  // }
70
73
  }
71
74
 
72
- return [ domain, null ];
75
+ return [domain, null];
73
76
  }
package/whois.d.ts CHANGED
@@ -6,6 +6,7 @@ export type WhoisOptions = Partial<{
6
6
 
7
7
  export type WhoisResponse = {
8
8
  found: boolean;
9
+ server?: string;
9
10
  registrar: {
10
11
  id: string | number;
11
12
  name: string | null;