From f95bbd6754f533526c926cdf14db1482b6ac02af Mon Sep 17 00:00:00 2001 From: Andrei Date: Sun, 10 Mar 2024 23:03:34 +0100 Subject: [PATCH] added: types & comments --- examples/all-dns-records-detect-wildcard.ts | 2 +- jsr.json | 5 +++++ src/index.ts | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 jsr.json diff --git a/examples/all-dns-records-detect-wildcard.ts b/examples/all-dns-records-detect-wildcard.ts index f3a1d7a..5119757 100644 --- a/examples/all-dns-records-detect-wildcard.ts +++ b/examples/all-dns-records-detect-wildcard.ts @@ -1,4 +1,4 @@ -import { DnsRecord, getAllDnsRecords } from '../src/index.ts' +import { getAllDnsRecords } from '../src/index.ts' const allDnsRecords = await getAllDnsRecords('wordpress.org') diff --git a/jsr.json b/jsr.json new file mode 100644 index 0000000..41199ba --- /dev/null +++ b/jsr.json @@ -0,0 +1,5 @@ +{ + "name": "@layered/dns-records", + "version": "2.0.1", + "exports": "./src/index.ts" +} diff --git a/src/index.ts b/src/index.ts index 2672404..5dba8d9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -83,7 +83,13 @@ const dnsResolvers: { [key: string]: Function } = { }, } -export async function getDnsRecords(name: string, type = 'A', resolver = 'cloudflare-dns'): Promise { +/** + * Get all DNS records of a given type for a FQDN. + * @param name Fully qualified domain name. + * @param type DNS record type: A, AAAA, TXT, CNAME, MX, etc. + * @param resolver DNS resolver to use. Default: cloudflare-dns. + */ +export async function getDnsRecords(name: string, type: string = 'A', resolver: string = 'cloudflare-dns'): Promise { if (!isDomain(name)) { throw new Error(`"${name}" is not a valid domain name`) } @@ -106,6 +112,10 @@ export type GetAllDnsRecordsOptions = { subdomains?: string[] } +/** + * Discover all DNS records for a given domain and return a readable stream. Each record is a text line. + * @param domain Valid domain name. + */ export function getAllDnsRecordsStream(domain: string, options: Partial = {}): ReadableStream { options = { resolver: 'cloudflare-dns', @@ -232,7 +242,10 @@ export function getAllDnsRecordsStream(domain: string, options: Partial = {}): Promise { const records: DnsRecord[] = [] const dnsRecordsStream = getAllDnsRecordsStream(domain, options)