mirror of
https://github.com/Xevion/rdap.git
synced 2025-12-06 01:16:00 -06:00
Move types into schema, prepare for full lookup implementation
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type {FunctionComponent, ReactNode} from "react";
|
||||
import React, {Fragment} from "react";
|
||||
import {rdapStatusInfo} from "@/constants";
|
||||
import type {Domain} from "@/responses";
|
||||
import type {Domain} from "@/schema";
|
||||
import Events from "@/components/Events"
|
||||
|
||||
export type DomainProps = {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type {FunctionComponent} from "react";
|
||||
import type {Event} from "@/responses";
|
||||
import type {Event} from "@/schema";
|
||||
import {Fragment} from "react";
|
||||
|
||||
export type EventsProps = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type {FunctionComponent} from "react";
|
||||
import DomainCard from "@/components/DomainCard";
|
||||
import type {Domain, AutonomousNumber, Entity, Nameserver, IpNetwork} from "@/responses";
|
||||
import type {Domain, AutonomousNumber, Entity, Nameserver, IpNetwork} from "@/schema";
|
||||
|
||||
export type ParsedGeneric = Domain | Nameserver | Entity | AutonomousNumber | IpNetwork;
|
||||
export type ObjectProps = {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// see https://www.iana.org/assignments/rdap-json-values
|
||||
import type {ExtendedUri, RdapStatusType, ObjectType} from "@/types";
|
||||
import type {RegistryType, RdapStatusType, ObjectType} from "@/types";
|
||||
|
||||
export const rdapStatusInfo: Record<RdapStatusType, string> = {
|
||||
"validated": "Signifies that the data of the object instance has been found to be accurate. This type of status is usually found on entity object instances to note the validity of identifying contact information.",
|
||||
@@ -39,7 +39,7 @@ export const rdapStatusInfo: Record<RdapStatusType, string> = {
|
||||
};
|
||||
|
||||
// list of RDAP bootstrap registry URLs
|
||||
export const registryURLs: Record<string, ExtendedUri> = {
|
||||
export const registryURLs: Record<string, RegistryType> = {
|
||||
"https://data.iana.org/rdap/asn.json": "autnum",
|
||||
"https://data.iana.org/rdap/dns.json": "domain",
|
||||
"https://data.iana.org/rdap/ipv4.json": "ip4",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {type NextPage} from "next";
|
||||
import Head from "next/head";
|
||||
import type {ObjectType} from "@/types";
|
||||
import type {ObjectType, Register} from "@/types";
|
||||
import {placeholders, registryURLs} from "@/constants";
|
||||
import {domainMatch, getBestURL, getType} from "@/rdap";
|
||||
import type {FormEvent} from "react";
|
||||
@@ -10,8 +10,7 @@ import axios from "axios";
|
||||
import type {ParsedGeneric} from "@/components/Generic";
|
||||
import Generic from "@/components/Generic";
|
||||
import type {ZodSchema} from "zod";
|
||||
import type {Register} from "@/responses";
|
||||
import {DomainSchema, RegisterSchema} from "@/responses";
|
||||
import {DomainSchema, RegisterSchema} from "@/schema";
|
||||
|
||||
const Index: NextPage = () => {
|
||||
const [requestJSContact, setRequestJSContact] = useState(false);
|
||||
@@ -144,7 +143,9 @@ const Index: NextPage = () => {
|
||||
data = schema.parse(JSON.parse(url.substring(7)))
|
||||
} else {
|
||||
try {
|
||||
const response = await axios.get(url, {responseType: "json"})
|
||||
const response = await axios.get(url, {responseType: "json", headers: {
|
||||
'Referrer-Policy': 'no-referrer'
|
||||
}})
|
||||
if (response.status == 404)
|
||||
setError('This object does not exist.');
|
||||
else if (response.status != 200)
|
||||
|
||||
19
src/rdap.ts
19
src/rdap.ts
@@ -1,4 +1,4 @@
|
||||
import type {ObjectType} from "@/types";
|
||||
import type {RegistryType, ObjectType} from "@/types";
|
||||
|
||||
// keeps track of how many registries we've loaded
|
||||
const loadedRegistries = 0;
|
||||
@@ -762,20 +762,19 @@ export function createRDAPLink(url, title) {
|
||||
}
|
||||
*/
|
||||
|
||||
const URIPatterns: [RegExp, ObjectType][] = [
|
||||
const URIPatterns: [RegExp, RegistryType][] = [
|
||||
[/^\d+$/, "autnum"],
|
||||
[/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/?\d*$/, "ip"],
|
||||
[/^[0-9a-f:]{2,}\/?\d*$/, "ip"],
|
||||
[/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/?\d*$/, "ip4"],
|
||||
[/^[0-9a-f:]{2,}\/?\d*$/, "ip6"],
|
||||
[/^https?:/, "url"],
|
||||
[/^{/, "json"],
|
||||
[/./, "domain"],
|
||||
];
|
||||
|
||||
// guess the type from the input value
|
||||
export function getType(value: string): ObjectType | null {
|
||||
for (let i = 0; i < URIPatterns.length; i++)
|
||||
if (URIPatterns[i]![0].test(value)) {
|
||||
return URIPatterns[i]![1];
|
||||
}
|
||||
export function getType(value: string): RegistryType | null {
|
||||
for (const [pattern, type] of URIPatterns) {
|
||||
if (pattern.test(value))
|
||||
return type;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -9,7 +9,6 @@ export const LinkSchema = z.object({
|
||||
href: z.string(),
|
||||
type: z.string()
|
||||
})
|
||||
export type Link = z.infer<typeof LinkSchema>;
|
||||
|
||||
|
||||
export const EntitySchema = z.object({
|
||||
@@ -21,20 +20,17 @@ export const EntitySchema = z.object({
|
||||
identifier: z.string(),
|
||||
})).optional()
|
||||
})
|
||||
export type Entity = z.infer<typeof EntitySchema>;
|
||||
|
||||
export const NameserverSchema = z.object({
|
||||
objectClassName: z.literal('nameserver'),
|
||||
ldhName: z.string()
|
||||
})
|
||||
export type Nameserver = z.infer<typeof NameserverSchema>;
|
||||
|
||||
export const EventSchema = z.object({
|
||||
eventAction: z.string(),
|
||||
eventActor: z.string().optional(),
|
||||
eventDate: z.string()
|
||||
})
|
||||
export type Event = z.infer<typeof EventSchema>;
|
||||
|
||||
export const NoticeSchema = z.object({
|
||||
title: z.string().optional(),
|
||||
@@ -63,7 +59,6 @@ export const IpNetworkSchema = z.object({
|
||||
port43: z.any().optional(),
|
||||
events: z.array(EventSchema)
|
||||
})
|
||||
export type IpNetwork = z.infer<typeof IpNetworkSchema>;
|
||||
|
||||
|
||||
export const AutonomousNumberSchema = z.object({
|
||||
@@ -80,7 +75,6 @@ export const AutonomousNumberSchema = z.object({
|
||||
roles: z.array(z.string()),
|
||||
links: z.array(LinkSchema)
|
||||
})
|
||||
export type AutonomousNumber = z.infer<typeof AutonomousNumberSchema>;
|
||||
|
||||
export const DomainSchema = z.object({
|
||||
objectClassName: z.literal('domain'),
|
||||
@@ -97,7 +91,6 @@ export const DomainSchema = z.object({
|
||||
notices: z.array(NoticeSchema),
|
||||
network: IpNetworkSchema.optional(),
|
||||
})
|
||||
export type Domain = z.infer<typeof DomainSchema>;
|
||||
|
||||
|
||||
const RegistrarSchema = z.tuple([
|
||||
@@ -115,4 +108,3 @@ export const RegisterSchema = z.object({
|
||||
services: z.array(RegistrarSchema),
|
||||
version: z.string()
|
||||
});
|
||||
export type Register = z.infer<typeof RegisterSchema>;
|
||||
26
src/types.ts
26
src/types.ts
@@ -1,8 +1,26 @@
|
||||
import type {z} from "zod";
|
||||
import type {ObjectTypeEnum} from "@/responses";
|
||||
import type {StatusEnum} from "@/responses";
|
||||
import type {
|
||||
AutonomousNumberSchema,
|
||||
DomainSchema,
|
||||
EntitySchema,
|
||||
EventSchema,
|
||||
IpNetworkSchema,
|
||||
LinkSchema,
|
||||
NameserverSchema,
|
||||
ObjectTypeEnum,
|
||||
RegisterSchema,
|
||||
StatusEnum
|
||||
} from "@/schema";
|
||||
|
||||
export type ObjectType = z.infer<typeof ObjectTypeEnum>
|
||||
export type ExtendedUri = Omit<ObjectType, 'ip'> | 'ip4' | 'ip6';
|
||||
export type RegistryType = Exclude<ObjectType, 'ip'> | 'ip4' | 'ip6';
|
||||
|
||||
export type RdapStatusType = z.infer<typeof StatusEnum>;
|
||||
export type RdapStatusType = z.infer<typeof StatusEnum>;
|
||||
export type Link = z.infer<typeof LinkSchema>;
|
||||
export type Entity = z.infer<typeof EntitySchema>;
|
||||
export type Nameserver = z.infer<typeof NameserverSchema>;
|
||||
export type Event = z.infer<typeof EventSchema>;
|
||||
export type IpNetwork = z.infer<typeof IpNetworkSchema>;
|
||||
export type AutonomousNumber = z.infer<typeof AutonomousNumberSchema>;
|
||||
export type Register = z.infer<typeof RegisterSchema>;
|
||||
export type Domain = z.infer<typeof DomainSchema>;
|
||||
|
||||
Reference in New Issue
Block a user