Compare commits

...

73 Commits

Author SHA1 Message Date
semantic-release-bot 3f0f14529d chore(release): 0.0.2-develop.1 [skip ci]
## [0.0.2-develop.1](https://git.lumeweb.com/LumeWeb/libresolver/compare/v0.0.1...v0.0.2-develop.1) (2023-07-05)
2023-07-05 08:43:20 +00:00
Derrick Hammer 17e840e859
ci: setup 2023-07-05 04:40:06 -04:00
Derrick Hammer 9dbcdd088d
refactor: move to new devops 2023-07-05 04:39:55 -04:00
Derrick Hammer e9ac273378
*update dist 2023-02-19 20:27:04 -05:00
Derrick Hammer 0f0ee49914
*Add resolver get/set to ResolverModule interface 2023-02-19 20:26:50 -05:00
Derrick Hammer cc8a889bfc
*Update dist 2023-02-19 20:08:08 -05:00
Derrick Hammer f4283e2d8f
*add a setter for the resolver object and dont use constructor based init 2023-02-19 20:07:52 -05:00
Derrick Hammer 68640a2bb8
*Cast supported due to overload 2023-02-19 20:02:24 -05:00
Derrick Hammer 6973f7218b
*Update dist 2023-02-19 20:00:58 -05:00
Derrick Hammer 6a8c6b9535
*make getSupportedTlds an overloaded method 2023-02-19 20:00:43 -05:00
Derrick Hammer 0fa39b7a6b
*Update dist 2023-02-19 18:20:17 -05:00
Derrick Hammer b5d4b63ade
*Use function overloading 2023-02-19 18:18:00 -05:00
Derrick Hammer 1551e0aa75
*Update dist 2023-02-19 18:03:47 -05:00
Derrick Hammer 1e62962a1d
*Refactor isTldSupported to support promises 2023-02-19 18:03:32 -05:00
Derrick Hammer aba5fad2c7
*Update dist 2023-02-19 17:47:50 -05:00
Derrick Hammer d1c8f72ab8
*Add extra promise return type 2023-02-19 17:47:33 -05:00
Derrick Hammer 14053e3a08
*Update dist 2023-02-19 16:59:24 -05:00
Derrick Hammer 067080c83e
*Remove _resolvers private property 2023-02-19 16:59:11 -05:00
Derrick Hammer 56ddff3ec5
*Update dist 2023-02-19 15:55:21 -05:00
Derrick Hammer e07d479ce1
*Remove rpc code for now 2023-02-19 15:55:02 -05:00
Derrick Hammer db81b961fb
*Update dist 2023-02-19 15:09:33 -05:00
Derrick Hammer cd650f9605
*Add dev deps of rpc-client to satisfy tsc 2023-02-19 15:08:58 -05:00
Derrick Hammer b798cff4d2
*add typescript dep 2023-02-19 15:02:45 -05:00
Derrick Hammer cfc827829a
*Use newer dht-rpc-client, now rpc-client 2023-02-19 15:02:21 -05:00
Derrick Hammer 37a42e66e8
*Update dist 2022-08-29 00:56:17 -04:00
Derrick Hammer c0b6384fa5
*Add utility function ensureUniqueRecords to ensure there are no duplicate records 2022-08-29 00:55:53 -04:00
Derrick Hammer 07dcd78261
*Set type to module 2022-08-23 13:25:46 -04:00
Derrick Hammer 1cdfd12ce9
*Update package name 2022-08-20 03:01:17 -04:00
Derrick Hammer b7de2018e8
*Update dist 2022-08-20 02:49:08 -04:00
Derrick Hammer ee4b80b4ce
*add ResolverModuleConstructor interface 2022-08-20 02:48:48 -04:00
Derrick Hammer 234074fb8f
*Update dist 2022-08-19 15:50:10 -04:00
Derrick Hammer cf214c2f43
*Update deps 2022-08-19 15:49:44 -04:00
Derrick Hammer 7a1a2d2150
*import only the type RpcNetwork 2022-08-19 15:49:30 -04:00
Derrick Hammer 09a5a605a7
*Update dist 2022-08-19 15:45:08 -04:00
Derrick Hammer e4c0a1b9ba
*add a stub declare for ResolverRegistry to break circular dependency 2022-08-19 15:44:51 -04:00
Derrick Hammer 65799211db
*Update dist 2022-08-19 14:48:49 -04:00
Derrick Hammer bea742218c
*Remove async 2022-08-19 14:48:35 -04:00
Derrick Hammer 37c31d57d2
*Remove implements as it causes too many issues 2022-08-19 14:48:16 -04:00
Derrick Hammer 8802c21f61
*Update dist 2022-08-19 13:47:35 -04:00
Derrick Hammer 902cc9ec67
*resolve should be async 2022-08-19 13:46:10 -04:00
Derrick Hammer 739cc5e3ee
*Update dist 2022-08-19 13:42:44 -04:00
Derrick Hammer 7d3383dd4f
*Input should be domain 2022-08-19 13:42:32 -04:00
Derrick Hammer fa0e3d6a71
*More type changes 2022-08-19 13:42:14 -04:00
Derrick Hammer 67ef8b8030
*Update dist 2022-08-19 12:37:22 -04:00
Derrick Hammer 084c4c7347
*Remove DEFAULT 2022-08-19 12:37:05 -04:00
Derrick Hammer 4cb79067b0
*Update dist 2022-08-19 11:53:39 -04:00
Derrick Hammer 42712a51d7
*Update types 2022-08-19 11:53:26 -04:00
Derrick Hammer 3b3e70af21
*AbstractResolverModule should implement ResolverModule 2022-08-19 11:29:46 -04:00
Derrick Hammer 2c26e9e4de
*Update dist 2022-08-18 20:10:31 -04:00
Derrick Hammer 171791d491
*Add isPromise to util 2022-08-18 20:10:00 -04:00
Derrick Hammer 64caf6c006
*Update dist 2022-08-18 20:01:36 -04:00
Derrick Hammer ba155ab715
*Add getSupportedTlds to ResolverModule interface 2022-08-18 20:01:23 -04:00
Derrick Hammer 292b110f19
*Update dist 2022-08-18 14:32:18 -04:00
Derrick Hammer 87a563c92d
*Add normalizeDomain function 2022-08-18 14:31:52 -04:00
Derrick Hammer 8739ba1f30
*Update dist 2022-08-18 14:09:07 -04:00
Derrick Hammer 01664a35dd
*force should be bypassCache 2022-08-18 14:08:53 -04:00
Derrick Hammer 223da6b2f0
*Update dist 2022-08-18 14:03:40 -04:00
Derrick Hammer aa3502bf71
*DNSResult.records should be type DNSRecord[] 2022-08-18 14:03:22 -04:00
Derrick Hammer 692417b1e5
*Add helper functions for handling resolver responses 2022-08-18 14:03:04 -04:00
Derrick Hammer 6e961044e5
*Update dist 2022-08-18 13:55:11 -04:00
Derrick Hammer 82d11b30f5
*Export util 2022-08-18 13:54:45 -04:00
Derrick Hammer e5f9980c2d
*Update dist 2022-08-18 13:09:02 -04:00
Derrick Hammer 815c6e6f75
*Update ResolverRegistry import 2022-08-18 13:08:15 -04:00
Derrick Hammer dbe35225be
*Add types 2022-08-18 13:02:27 -04:00
Derrick Hammer d6b581819f
*update dist 2022-08-18 11:14:05 -04:00
Derrick Hammer 9d95bb59e3
*Make type a string 2022-08-18 11:13:49 -04:00
Derrick Hammer 97e45a098d
*Options should be optional 2022-08-18 11:11:53 -04:00
Derrick Hammer a72c530fc0
*Add a DEFAULT DNS record type 2022-08-18 11:04:41 -04:00
Derrick Hammer 351e4ceb85
*records should not be in ResolverOptions 2022-08-18 11:03:50 -04:00
Derrick Hammer 32c33748e4
*Update dist 2022-08-18 11:01:28 -04:00
Derrick Hammer 3f68971640
*ResolverModule should not be default 2022-08-18 11:01:07 -04:00
Derrick Hammer 16e94b5737
*Add dist 2022-08-18 10:58:17 -04:00
Derrick Hammer c4498d812d
*Initial version 2022-08-18 10:57:46 -04:00
10 changed files with 19531 additions and 1 deletions

13
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,13 @@
name: Build/Publish
on:
push:
branches:
- master
- develop
- develop-*
jobs:
main:
uses: lumeweb/github-node-deploy-workflow/.github/workflows/main.yml@master
secrets: inherit

5
.presetterrc.json Normal file
View File

@ -0,0 +1,5 @@
{
"preset": [
"@lumeweb/node-library-preset"
]
}

1
CHANGELOG.md Normal file
View File

@ -0,0 +1 @@
## [0.0.2-develop.1](https://git.lumeweb.com/LumeWeb/libresolver/compare/v0.0.1...v0.0.2-develop.1) (2023-07-05)

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

19314
npm-shrinkwrap.json generated Normal file

File diff suppressed because it is too large Load Diff

27
package.json Normal file
View File

@ -0,0 +1,27 @@
{
"name": "@lumeweb/libresolver",
"version": "0.0.2-develop.1",
"description": "Common code and interfaces for the DNS resolver modules",
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "gitea@git.lumeweb.com:LumeWeb/libresolver.git"
},
"type": "module",
"devDependencies": {
"@lumeweb/node-library-preset": "^0.2.7",
"presetter": "*"
},
"readme": "ERROR: No README data found!",
"scripts": {
"prepare": "presetter bootstrap",
"build": "run build",
"semantic-release": "semantic-release"
},
"files": [
"lib"
],
"publishConfig": {
"access": "public"
}
}

3
src/index.ts Normal file
View File

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

69
src/resolverModule.ts Normal file
View File

@ -0,0 +1,69 @@
import type { DNSResult, ResolverOptions } from "./types.js";
import { getTld, isPromise } from "./util.js";
declare class ResolverRegistry {
get resolvers(): Set<ResolverModule> | Promise<Set<ResolverModule>>;
resolve(
domain: string,
options?: ResolverOptions,
bypassCache?: boolean
): Promise<DNSResult>;
register(resolver: ResolverModule): void;
clear(): void;
}
export interface ResolverModule {
get resolver(): ResolverRegistry;
set resolver(value: ResolverRegistry);
resolve(
domain: string,
options: ResolverOptions,
bypassCache: boolean
): Promise<DNSResult>;
getSupportedTlds(): string[];
getSupportedTlds(): Promise<string[]>;
getSupportedTlds(): any;
}
// ts-ignore
export abstract class AbstractResolverModule {
constructor(resolver?: ResolverRegistry) {
this._resolver = resolver;
}
private _resolver?: ResolverRegistry;
get resolver(): ResolverRegistry {
return this._resolver as ResolverRegistry;
}
set resolver(value: ResolverRegistry) {
this._resolver = value;
}
abstract resolve(
domain: string,
options: ResolverOptions,
bypassCache: boolean
): Promise<DNSResult>;
getSupportedTlds(): string[];
getSupportedTlds(): Promise<string[]>;
getSupportedTlds(): any {
return [];
}
isTldSupported(domain: string): Promise<boolean>;
isTldSupported(domain: string): boolean;
isTldSupported(domain: string): any {
let supported = this.getSupportedTlds() as any;
if (isPromise(supported)) {
return (supported as Promise<string[]>).then((supported: string[]) => {
return supported.includes(getTld(domain));
});
}
return (supported as string[]).includes(getTld(domain));
}
}

29
src/types.ts Normal file
View File

@ -0,0 +1,29 @@
export interface ResolverOptions {
type: string;
customType?: string;
options?: any;
}
export interface DNSResult {
records: DNSRecord[];
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 };

69
src/util.ts Normal file
View File

@ -0,0 +1,69 @@
import { DNSRecord, DNSResult } from "./types.js";
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
);
}
export function resolverEmptyResponse(): DNSResult {
return {
records: [],
};
}
export function resolverError(e: Error | string): DNSResult {
if (!(e instanceof Error)) {
e = new Error(e);
}
return {
records: [],
error: e,
};
}
export function resolveSuccess(records: DNSRecord[]): DNSResult {
return {
records,
};
}
export function normalizeDomain(domain: string): string {
return domain.replace(/^\.+|\.+$/g, "").replace(/^\/+|\/+$/g, "");
}
export function isPromise(obj: Promise<any>) {
return (
!!obj &&
(typeof obj === "object" || typeof obj === "function") &&
typeof obj.then === "function"
);
}
export function ensureUniqueRecords(records: DNSRecord[]) {
return [
...new Set(records.map((item: DNSRecord) => JSON.stringify(item))),
].map((item) => JSON.parse(item));
}