@cleandns/whois-rdap 1.0.47 → 1.0.49

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
@@ -20,6 +20,8 @@ export async function whois(origDomain, options = { fetch: fetch, thinOnly: fals
20
20
  [domain, url] = await tldToRdap(origDomain);
21
21
  const response = {
22
22
  found: false,
23
+ statusCode: 0,
24
+ error: '',
23
25
  registrar: { id: 0, name: null },
24
26
  reseller: null,
25
27
  status: [],
@@ -43,10 +45,20 @@ export async function whois(origDomain, options = { fetch: fetch, thinOnly: fals
43
45
  const type = domain.match(/[^\d.]/) ? "domain" : "ip";
44
46
  let thinResponse = null;
45
47
  const thinRdap = `${url}/${type}/${domain}`;
46
- // console.log(`fetching thin RDAP: ${thinRdap}`);
47
48
  thinResponse = await _fetch(thinRdap)
48
- .then((r) => r.json())
49
- .catch(() => null);
49
+ .then((r) => {
50
+ response.statusCode = r.status;
51
+ // console.log({ ok: r.ok, status: r.status, statusText: r.statusText });
52
+ if (r.status >= 200 && r.status < 400) {
53
+ return r.json();
54
+ }
55
+ response.error = r.statusText;
56
+ return null;
57
+ })
58
+ .catch((error) => {
59
+ console.warn(`thin RDAP lookup failure: ${error.message}`);
60
+ return null;
61
+ });
50
62
  if (thinResponse && !thinResponse.errorCode) {
51
63
  }
52
64
  else if (!options.server) {
package/dist/port43.js CHANGED
@@ -33,6 +33,8 @@ export async function port43(actor, _fetch) {
33
33
  // console.log(`looking up ${domain} on ${server}`);
34
34
  const response = {
35
35
  found: true,
36
+ statusCode: 200,
37
+ error: '',
36
38
  registrar: { id: 0, name: null },
37
39
  reseller: null,
38
40
  status: [],
@@ -40,6 +42,9 @@ export async function port43(actor, _fetch) {
40
42
  ts: { created: null, updated: null, expires: null },
41
43
  };
42
44
  if (!server) {
45
+ response.found = false;
46
+ response.statusCode = 405;
47
+ response.error = "No server specified for port 43 lookup";
43
48
  return response;
44
49
  }
45
50
  let port43response = "";
@@ -70,16 +75,21 @@ export async function port43(actor, _fetch) {
70
75
  catch (error) {
71
76
  console.warn({ port, server, query, error: error.message });
72
77
  response.found = false;
78
+ response.statusCode = 500;
79
+ response.error = error.message || "Unknown error during port 43 lookup";
73
80
  }
74
81
  if (!response.found) {
75
82
  return response;
76
83
  }
84
+ port43response = port43response.replace(/^[ \t]+/gm, "");
77
85
  // console.log(port43response);
78
- if (port43response.match(/^%*\s+(NOT FOUND|No match|NO OBJECT FOUND|No entries found|No Data Found|Domain is available for registration|No information available|Status: free)\b/im)) {
86
+ let m;
87
+ if (m = port43response.match(/^%*\s*(NOT FOUND|No match|NO OBJECT FOUND|No entries found|No Data Found|Domain is available for registration|No information available|Status: free)\b/im)) {
79
88
  response.found = false;
89
+ response.statusCode = 404;
90
+ response.error = m[1].trim();
80
91
  return response;
81
92
  }
82
- let m;
83
93
  const parser = port43parsers[tld] || ((_b = Object.entries(port43parsers).find(([t]) => tld.endsWith('.' + t))) === null || _b === void 0 ? void 0 : _b[1]);
84
94
  if (parser) {
85
95
  await parser(port43response, response);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleandns/whois-rdap",
3
- "version": "1.0.47",
3
+ "version": "1.0.49",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/index.ts CHANGED
@@ -28,6 +28,8 @@ export async function whois(
28
28
 
29
29
  const response: WhoisResponse = {
30
30
  found: false,
31
+ statusCode: 0,
32
+ error: '',
31
33
  registrar: { id: 0, name: null },
32
34
  reseller: null,
33
35
  status: [],
@@ -54,11 +56,21 @@ export async function whois(
54
56
  let thinResponse: any = null;
55
57
  const thinRdap = `${url}/${type}/${domain}`;
56
58
 
57
- // console.log(`fetching thin RDAP: ${thinRdap}`);
58
-
59
59
  thinResponse = await _fetch(thinRdap)
60
- .then((r) => r.json() as any)
61
- .catch(() => null);
60
+ .then((r) => {
61
+ response.statusCode = r.status;
62
+ // console.log({ ok: r.ok, status: r.status, statusText: r.statusText });
63
+ if (r.status >= 200 && r.status < 400) {
64
+ return r.json() as any;
65
+ }
66
+ response.error = r.statusText;
67
+ return null;
68
+ })
69
+ .catch((error: Error) => {
70
+ console.warn(`thin RDAP lookup failure: ${error.message}`);
71
+ return null;
72
+ });
73
+
62
74
  if (thinResponse && !thinResponse.errorCode) {
63
75
  } else if (!options.server) {
64
76
  return response;
package/src/port43.ts CHANGED
@@ -40,6 +40,8 @@ export async function port43(actor: string, _fetch: typeof fetch): Promise<Whois
40
40
 
41
41
  const response: WhoisResponse = {
42
42
  found: true,
43
+ statusCode: 200,
44
+ error: '',
43
45
  registrar: { id: 0, name: null },
44
46
  reseller: null,
45
47
  status: [],
@@ -48,6 +50,9 @@ export async function port43(actor: string, _fetch: typeof fetch): Promise<Whois
48
50
  };
49
51
 
50
52
  if (!server) {
53
+ response.found = false;
54
+ response.statusCode = 405;
55
+ response.error = "No server specified for port 43 lookup";
51
56
  return response;
52
57
  }
53
58
 
@@ -79,25 +84,30 @@ export async function port43(actor: string, _fetch: typeof fetch): Promise<Whois
79
84
  } catch (error: any) {
80
85
  console.warn({ port, server, query, error: error.message });
81
86
  response.found = false;
87
+ response.statusCode = 500;
88
+ response.error = error.message || "Unknown error during port 43 lookup";
82
89
  }
83
90
 
84
91
  if (!response.found) {
85
92
  return response;
86
93
  }
87
94
 
95
+ port43response = port43response.replace(/^[ \t]+/gm, "");
88
96
  // console.log(port43response);
89
97
 
98
+ let m;
99
+
90
100
  if (
91
- port43response.match(
92
- /^%*\s+(NOT FOUND|No match|NO OBJECT FOUND|No entries found|No Data Found|Domain is available for registration|No information available|Status: free)\b/im
101
+ m = port43response.match(
102
+ /^%*\s*(NOT FOUND|No match|NO OBJECT FOUND|No entries found|No Data Found|Domain is available for registration|No information available|Status: free)\b/im
93
103
  )
94
104
  ) {
95
105
  response.found = false;
106
+ response.statusCode = 404;
107
+ response.error = m[1].trim();
96
108
  return response;
97
109
  }
98
110
 
99
- let m;
100
-
101
111
  const parser = port43parsers[tld] || Object.entries(port43parsers).find(([t]) => tld.endsWith('.' + t))?.[1];
102
112
 
103
113
  if (parser) {
package/whois.d.ts CHANGED
@@ -8,6 +8,8 @@ export type WhoisOptions = Partial<{
8
8
 
9
9
  export type WhoisResponse = {
10
10
  found: boolean;
11
+ statusCode?: number;
12
+ error?: string;
11
13
  server?: string;
12
14
  registrar: {
13
15
  id: string | number;