@cleandns/whois-rdap 1.0.48 → 1.0.50

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) {
@@ -78,7 +90,7 @@ export async function whois(origDomain, options = { fetch: fetch, thinOnly: fals
78
90
  const registrars = [];
79
91
  const resellers = [];
80
92
  async function extractRegistrarsAndResellers(response, url, isThick) {
81
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
93
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
82
94
  for (const ent of [
83
95
  ...(response.entities || []),
84
96
  response.entity ? { events: response.events, ...response.entity } : null,
@@ -124,15 +136,15 @@ export async function whois(origDomain, options = { fetch: fetch, thinOnly: fals
124
136
  registrars.push({ id: 0, name: ent.vcardArray[1][1][3], email, events: ent.events || response.events || ent.enents || response.enents });
125
137
  }
126
138
  // handles .si
127
- else if ((_p = ent.vcardArray) === null || _p === void 0 ? void 0 : _p[1].find((el) => el[0] === 'fn')) {
128
- const email = ((_q = [ent, ...(ent.entities || [])]
139
+ else if (ent.vcardArray && ent.vcardArray[1] && ent.vcardArray[1].find((el) => el[0] === 'fn')) {
140
+ const email = ((_p = [ent, ...(ent.entities || [])]
129
141
  .filter((e) => e === null || e === void 0 ? void 0 : e.vcardArray)
130
142
  .map((e) => findInObject(e.vcardArray, (el) => Array.isArray(el) && el[0] === "email", (el) => el[3], ""))
131
- .filter(Boolean)) === null || _q === void 0 ? void 0 : _q[0]) || "";
143
+ .filter(Boolean)) === null || _p === void 0 ? void 0 : _p[0]) || "";
132
144
  if (ent.handle && ent.handle.toString().match(/^\d+$/)) {
133
145
  const id = ent.handle;
134
146
  const name = (parseInt(id) == id
135
- && ((_r = (await ianaIdToRegistrar(parseInt(id)))) === null || _r === void 0 ? void 0 : _r.name))
147
+ && ((_q = (await ianaIdToRegistrar(parseInt(id)))) === null || _q === void 0 ? void 0 : _q.name))
136
148
  || findInObject(ent.vcardArray, (el) => Array.isArray(el) && (el[0] === "fn" || el[0] === "org"), (el) => el[3], id);
137
149
  registrars.push({ id, name, email, events: ent.events || response.events || ent.enents || response.enents });
138
150
  }
@@ -146,19 +158,19 @@ export async function whois(origDomain, options = { fetch: fetch, thinOnly: fals
146
158
  }
147
159
  }
148
160
  if (domain.endsWith(".is") &&
149
- (((_s = ent.roles) === null || _s === void 0 ? void 0 : _s.includes("technical")) || ent.role === "technical")) {
161
+ (((_r = ent.roles) === null || _r === void 0 ? void 0 : _r.includes("technical")) || ent.role === "technical")) {
150
162
  const id = ent.handle;
151
163
  const name = (parseInt(id) == id
152
- && ((_t = (await ianaIdToRegistrar(parseInt(id)))) === null || _t === void 0 ? void 0 : _t.name))
164
+ && ((_s = (await ianaIdToRegistrar(parseInt(id)))) === null || _s === void 0 ? void 0 : _s.name))
153
165
  || findInObject(ent.vcardArray, (el) => Array.isArray(el) && (el[0] === "fn" || el[0] === "org"), (el) => el[3], id);
154
- const email = ((_u = [ent, ...(ent.entities || [])]
166
+ const email = ((_t = [ent, ...(ent.entities || [])]
155
167
  .filter((e) => e === null || e === void 0 ? void 0 : e.vcardArray)
156
168
  .map((e) => findInObject(e.vcardArray, (el) => Array.isArray(el) && el[0] === "email", (el) => el[3], ""))
157
- .filter(Boolean)) === null || _u === void 0 ? void 0 : _u[0]) || "";
169
+ .filter(Boolean)) === null || _t === void 0 ? void 0 : _t[0]) || "";
158
170
  const events = ent.events || response.events || ent.enents || response.enents;
159
171
  registrars.push({ id, name, email, events });
160
172
  }
161
- if ((((_v = ent.roles) === null || _v === void 0 ? void 0 : _v.includes("reseller")) || ent.role === "reseller") &&
173
+ if ((((_u = ent.roles) === null || _u === void 0 ? void 0 : _u.includes("reseller")) || ent.role === "reseller") &&
162
174
  ent.vcardArray) {
163
175
  // vcard objects can be unexpectedly and arbitrarily nested
164
176
  const name = findInObject(ent.vcardArray, (el) => Array.isArray(el) && (el[0] === "fn" || el[0] === "org"), (el) => el[3], "");
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,17 +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
  }
77
84
  port43response = port43response.replace(/^[ \t]+/gm, "");
78
85
  // console.log(port43response);
79
- 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)) {
80
88
  response.found = false;
89
+ response.statusCode = 404;
90
+ response.error = m[1].trim();
81
91
  return response;
82
92
  }
83
- let m;
84
93
  const parser = port43parsers[tld] || ((_b = Object.entries(port43parsers).find(([t]) => tld.endsWith('.' + t))) === null || _b === void 0 ? void 0 : _b[1]);
85
94
  if (parser) {
86
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.48",
3
+ "version": "1.0.50",
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;
@@ -179,7 +191,7 @@ export async function whois(
179
191
  registrars.push({ id: 0, name: ent.vcardArray[1][1][3], email, events: ent.events || response.events || ent.enents || response.enents });
180
192
  }
181
193
  // handles .si
182
- else if (ent.vcardArray?.[1].find((el: string[]) => el[0] === 'fn')) {
194
+ else if (ent.vcardArray && ent.vcardArray[1] && ent.vcardArray[1].find((el: string[]) => el[0] === 'fn')) {
183
195
  const email =
184
196
  [ent, ...(ent.entities || [])]
185
197
  .filter((e) => e?.vcardArray)
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,6 +84,8 @@ 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) {
@@ -88,17 +95,19 @@ export async function port43(actor: string, _fetch: typeof fetch): Promise<Whois
88
95
  port43response = port43response.replace(/^[ \t]+/gm, "");
89
96
  // console.log(port43response);
90
97
 
98
+ let m;
99
+
91
100
  if (
92
- port43response.match(
93
- /^%*\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
94
103
  )
95
104
  ) {
96
105
  response.found = false;
106
+ response.statusCode = 404;
107
+ response.error = m[1].trim();
97
108
  return response;
98
109
  }
99
110
 
100
- let m;
101
-
102
111
  const parser = port43parsers[tld] || Object.entries(port43parsers).find(([t]) => tld.endsWith('.' + t))?.[1];
103
112
 
104
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;