@cleandns/whois-rdap 1.0.52 → 1.0.55

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.
Files changed (40) hide show
  1. package/.github/workflows/test.yml +38 -0
  2. package/dist/index.d.ts +3 -1
  3. package/dist/index.js +69 -88
  4. package/dist/index.test.d.ts +1 -0
  5. package/dist/index.test.js +360 -0
  6. package/dist/ip.js +8 -1
  7. package/dist/polyfills.d.ts +11 -0
  8. package/dist/polyfills.js +64 -0
  9. package/dist/port43.js +28 -14
  10. package/dist/utils/escapeRegex.d.ts +5 -0
  11. package/dist/utils/escapeRegex.js +7 -0
  12. package/dist/utils/findInObject.js +14 -4
  13. package/dist/utils/findNameservers.d.ts +1 -0
  14. package/dist/utils/findNameservers.js +15 -0
  15. package/dist/utils/findStatus.d.ts +1 -0
  16. package/dist/utils/findStatus.js +10 -0
  17. package/dist/utils/findTimestamps.d.ts +6 -0
  18. package/dist/utils/findTimestamps.js +39 -0
  19. package/dist/utils/toArray.d.ts +5 -0
  20. package/dist/utils/toArray.js +17 -0
  21. package/dist/utils/validateDomain.d.ts +5 -0
  22. package/dist/utils/validateDomain.js +18 -0
  23. package/github-workflow.patch +1044 -0
  24. package/package.json +24 -17
  25. package/src/index.test.ts +440 -0
  26. package/src/index.ts +65 -89
  27. package/src/ip.ts +9 -1
  28. package/src/polyfills.ts +76 -0
  29. package/src/port43.ts +29 -21
  30. package/src/utils/escapeRegex.ts +7 -0
  31. package/src/utils/findInObject.ts +19 -4
  32. package/src/utils/findNameservers.ts +15 -0
  33. package/src/utils/findStatus.ts +12 -0
  34. package/src/utils/findTimestamps.ts +44 -0
  35. package/src/utils/toArray.ts +17 -0
  36. package/src/utils/validateDomain.ts +18 -0
  37. package/tsconfig.json +1 -1
  38. package/dist/wwwservers.d.ts +0 -1
  39. package/dist/wwwservers.js +0 -3
  40. package/pnpm-workspace.yaml +0 -2
@@ -0,0 +1,39 @@
1
+ import { eventMap } from "../index.js";
2
+ /**
3
+ * Extracts timestamps from RDAP events array.
4
+ * Properly iterates through events and breaks when a match is found.
5
+ */
6
+ export function findTimestamps(values) {
7
+ var _a;
8
+ const ts = {
9
+ created: null,
10
+ updated: null,
11
+ expires: null,
12
+ };
13
+ let events = [];
14
+ if (Array.isArray(values)) {
15
+ events = values;
16
+ }
17
+ else if (typeof values === "object" && values !== null) {
18
+ events = Object.values(values);
19
+ }
20
+ // Iterate through each event type we're looking for
21
+ for (const [eventAction, field] of eventMap) {
22
+ // Skip if we already have a value for this field
23
+ if (ts[field] !== null) {
24
+ continue;
25
+ }
26
+ // Find matching event and extract date
27
+ for (const ev of events) {
28
+ if (((_a = ev === null || ev === void 0 ? void 0 : ev.eventAction) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === eventAction && ev.eventDate) {
29
+ const dateStr = ev.eventDate.toString().replace(/\+0000Z$/, "Z");
30
+ const d = new Date(dateStr);
31
+ if (!isNaN(d.valueOf())) {
32
+ ts[field] = d;
33
+ break; // Found valid date, stop searching for this field
34
+ }
35
+ }
36
+ }
37
+ }
38
+ return ts;
39
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Safely converts a value to an array.
3
+ * Handles cases where the value might be null, undefined, or a non-iterable object.
4
+ */
5
+ export declare function toArray<T>(value: T | T[] | null | undefined): T[];
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Safely converts a value to an array.
3
+ * Handles cases where the value might be null, undefined, or a non-iterable object.
4
+ */
5
+ export function toArray(value) {
6
+ if (value === null || value === undefined) {
7
+ return [];
8
+ }
9
+ if (Array.isArray(value)) {
10
+ return value;
11
+ }
12
+ // Handle object case - some RDAP responses return objects instead of arrays
13
+ if (typeof value === "object") {
14
+ return Object.values(value);
15
+ }
16
+ return [];
17
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Validates domain input format.
3
+ * Returns sanitized domain or throws on invalid input.
4
+ */
5
+ export declare function validateDomain(domain: string): string;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Validates domain input format.
3
+ * Returns sanitized domain or throws on invalid input.
4
+ */
5
+ export function validateDomain(domain) {
6
+ if (!domain || typeof domain !== 'string') {
7
+ throw new Error('Domain must be a non-empty string');
8
+ }
9
+ // Basic sanitization - trim whitespace
10
+ const sanitized = domain.trim().toLowerCase();
11
+ if (sanitized.length === 0) {
12
+ throw new Error('Domain must be a non-empty string');
13
+ }
14
+ if (sanitized.length > 253) {
15
+ throw new Error('Domain name too long');
16
+ }
17
+ return sanitized;
18
+ }