Build out primitive object schemas

This commit is contained in:
Xevion
2023-01-14 14:53:12 -06:00
parent b1db1fea8a
commit 34819bd195
5 changed files with 69 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
// see https://www.iana.org/assignments/rdap-json-values
import type {ExtendedUri, RdapStatusType, Uri} from "@/types";
import type {ExtendedUri, 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.",
@@ -47,7 +47,7 @@ export const registryURLs: Record<string, ExtendedUri> = {
"https://data.iana.org/rdap/object-tags.json": "entity",
};
export const placeholders: Record<Uri, string> = {
export const placeholders: Record<ObjectType, string> = {
'ip': '192.168.0.1/16',
'autnum': '65535',
'entity': 'ABC123-EXAMPLE',

View File

@@ -1,6 +1,6 @@
import {type NextPage} from "next";
import Head from "next/head";
import type {Uri} from "../types";
import type {ObjectType} from "../types";
import {placeholders} from "../constants";
import {asnMatch, domainMatch, entityMatch, getBestURL, getRDAPURL, getType, ipMatch, showSpinner} from "../rdap";
import {useEffect, useState} from "react";
@@ -11,7 +11,7 @@ import update from "immutability-helper";
import GenericObject, {Link} from "../components/DomainType";
const Index: NextPage = () => {
const [uriType, setUriType] = useState<Uri>('domain');
const [uriType, setUriType] = useState<ObjectType>('domain');
const [requestJSContact, setRequestJSContact] = useState(false);
@@ -170,7 +170,7 @@ const Index: NextPage = () => {
// Load parameters from URL query string on page load
const params = new URLSearchParams(window.location.search);
if (params.has('type'))
setUriType(params.get('type') as Uri);
setUriType(params.get('type') as ObjectType);
else if (params.has('object'))
setObject(params.get('object')!);
@@ -250,7 +250,7 @@ const Index: NextPage = () => {
<select className="custom-select" id="type" name="type"
value={uriType}
onChange={(e) => {
setUriType(e.target.value as Uri);
setUriType(e.target.value as ObjectType);
}}>
<option value="domain">Domain</option>
<option value="tld">TLD</option>

View File

@@ -1,6 +1,6 @@
import ipaddr from "ipaddr.js";
import {rdapStatusInfo, registryURLs} from "@/constants";
import type {Uri} from "@/types";
import type {ObjectType} from "@/types";
// keeps track of how many registries we've loaded
let loadedRegistries = 0;
@@ -700,7 +700,7 @@ export function createRDAPLink(url, title) {
return link;
}
const URIPatterns: [RegExp, Uri][] = [
const URIPatterns: [RegExp, ObjectType][] = [
[/^\d+$/, "autnum"],
[/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/?\d*$/, "ip"],
[/^[0-9a-f:]{2,}\/?\d*$/, "ip"],
@@ -710,7 +710,7 @@ const URIPatterns: [RegExp, Uri][] = [
];
// guess the type from the input value
export function getType(value: string): Uri | null {
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];

52
src/responses.ts Normal file
View File

@@ -0,0 +1,52 @@
import {z} from "zod";
export const ObjectTypeEnum = z.enum(['ip', 'autnum', 'entity', 'url', 'tld', 'registrar', 'json', 'domain'])
export const StatusEnum = z.enum(["validated", "renew prohibited", "update prohibited", "transfer prohibited", "delete prohibited", "proxy", "private", "removed", "obscured", "associated", "active", "inactive", "locked", "pending create", "pending renew", "pending transfer", "pending update", "pending delete", "add period", "auto renew period", "client delete prohibited", "client hold", "client renew prohibited", "client transfer prohibited", "client update prohibited", "pending restore", "redemption period", "renew period", "server delete prohibited", "server renew prohibited", "server transfer prohibited", "server update prohibited", "server hold", "transfer period"])
export const LinkSchema = z.object({
value: z.string(),
rel: z.string(),
href: z.string(),
type: z.string()
})
export const EntitySchema = z.object({
objectClassName: z.literal('entity'),
handle: z.string(),
roles: z.array(z.string()),
publicIds: z.array(z.object({
type: z.string(),
identifier: z.string(),
}))
})
export const NameserverSchema = z.object({
objectClassName: z.literal('nameserver'),
ldhName: z.string()
})
export const EventSchema = z.object({
eventAction: z.string(),
eventDate: z.date()
})
export const NoticeSchema = z.object({
title: z.string(),
description: z.string().array(),
links: z.array(z.object({
href: z.string(),
tpye: z.string()
}))
})
export const DomainSchema = z.object({
objectClassName: z.literal('domain'),
handle: z.string(),
ldhName: z.string(),
links: z.array(LinkSchema),
status: z.array(StatusEnum),
entities: z.array(EntitySchema),
events: z.array(EventSchema),
secureDNS: z.any(), // TODO: Complete
nameservers: z.array(NameserverSchema),
rdapConformance: z.string().array(), // TODO: Complete
notices: z.array(NoticeSchema),
})

View File

@@ -1,9 +1,8 @@
export type Uri = 'ip' | 'autnum' | 'entity' | 'url' | 'tld' | 'registrar' | 'json' | 'domain';
export type ExtendedUri = Omit<Uri, 'ip'> | 'ip4' | 'ip6';
export type RdapStatusType = "validated" | "renew prohibited" | "update prohibited" | "transfer prohibited"
| "delete prohibited" | "proxy" | "private" | "removed" | "obscured" | "associated" | "active" | "inactive"
| "locked" | "pending create" | "pending renew" | "pending transfer" | "pending update" | "pending delete"
| "add period" | "auto renew period" | "client delete prohibited" | "client hold" | "client renew prohibited"
| "client transfer prohibited" | "client update prohibited" | "pending restore" | "redemption period"
| "renew period" | "server delete prohibited" | "server renew prohibited" | "server transfer prohibited"
| "server update prohibited" | "server hold" | "transfer period";
import type {z} from "zod";
import type {ObjectTypeEnum} from "@/responses";
import type {StatusEnum} from "@/responses";
export type ObjectType = z.infer<typeof ObjectTypeEnum>
export type ExtendedUri = Omit<ObjectType, 'ip'> | 'ip4' | 'ip6';
export type RdapStatusType = z.infer<typeof StatusEnum>;