*Initial version

This commit is contained in:
Derrick Hammer 2022-08-18 10:49:10 -04:00
parent b0478eea5e
commit c4498d812d
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
7 changed files with 127 additions and 1 deletions

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2022 Lume Web
Copyright (c) 2022 Hammmer Technologies LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

6
package.json Normal file
View File

@ -0,0 +1,6 @@
{
"name": "@lumeweb/resolver-common",
"version": "0.1.0",
"description": "Common code and interfaces for the DNS resolver modules",
"main": "dist/index.js"
}

2
src/index.ts Normal file
View File

@ -0,0 +1,2 @@
export * from "./types.js";
export * from "./resolverModule.js";

34
src/resolverModule.ts Normal file
View File

@ -0,0 +1,34 @@
import type { DNSResult, ResolverOptions } from "./types.js";
import { getTld } from "./util.js";
export default interface ResolverModule {
constructor(resolver: any): void;
resolve(
domain: string,
options: ResolverOptions,
bypassCache: boolean
): Promise<DNSResult>;
}
export abstract class AbstractResolverModule {
protected resolver: any;
constructor(resolver: any) {
this.resolver = resolver;
}
abstract resolve(
input: string,
options: ResolverOptions,
force: boolean
): Promise<DNSResult>;
getSupportedTlds(): string[] {
return [];
}
isTldSupported(domain: string): boolean {
return this.getSupportedTlds().includes(getTld(domain));
}
}

31
src/types.ts Normal file
View File

@ -0,0 +1,31 @@
export interface ResolverOptions {
type: any;
customType?: string;
records: any[];
options: any;
}
export interface DNSResult {
records: any[];
error?: Error;
}
export interface DNSRecord {
type: string;
customType?: string;
value: string;
}
const DNS_RECORD_TYPE = {
A: "A",
CNAME: "CNAME",
NS: "NS",
CONTENT: "CONTENT",
TEXT: "TEXT",
ALL: "ALL",
CUSTOM: "CUSTOM",
};
Object.freeze(DNS_RECORD_TYPE);
export { DNS_RECORD_TYPE };

30
src/util.ts Normal file
View File

@ -0,0 +1,30 @@
export function getTld(domain: string): string {
if (domain.includes(".")) {
domain = domain.split(".")[domain.split(".").length - 1];
}
return domain;
}
export function getSld(domain: string): string {
if (domain.includes(".")) {
domain = domain
.split(".")
.slice(0, domain.split(".").length - 1)
.join(".");
}
return domain;
}
export function isIp(ip: string) {
return /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(
ip
);
}
export function isDomain(domain: string) {
return /(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]/.test(
domain
);
}

23
tsconfig.json Normal file
View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"declaration": true,
"strict": true,
"module": "esnext",
"target": "esnext",
"esModuleInterop": true,
"sourceMap": false,
"rootDir": "src",
"outDir": "dist",
"typeRoots": [
"node_modules/@types"
],
"moduleResolution": "node",
"declarationMap": true,
"declarationDir": "dist",
"emitDeclarationOnly": false,
"allowJs": true
},
"include": [
"src"
]
}