Skip to content

Commit

Permalink
added: types & comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiIgna committed Mar 10, 2024
1 parent 91943f1 commit f95bbd6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/all-dns-records-detect-wildcard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DnsRecord, getAllDnsRecords } from '../src/index.ts'
import { getAllDnsRecords } from '../src/index.ts'

const allDnsRecords = await getAllDnsRecords('wordpress.org')

Expand Down
5 changes: 5 additions & 0 deletions jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@layered/dns-records",
"version": "2.0.1",
"exports": "./src/index.ts"
}
17 changes: 15 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ const dnsResolvers: { [key: string]: Function } = {
},
}

export async function getDnsRecords(name: string, type = 'A', resolver = 'cloudflare-dns'): Promise<DnsRecord[]> {
/**
* 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<DnsRecord[]> {
if (!isDomain(name)) {
throw new Error(`"${name}" is not a valid domain name`)
}
Expand All @@ -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<GetAllDnsRecordsOptions> = {}): ReadableStream {
options = {
resolver: 'cloudflare-dns',
Expand Down Expand Up @@ -232,7 +242,10 @@ export function getAllDnsRecordsStream(domain: string, options: Partial<GetAllDn

return readable
}

/**
* Discover and return all DNS records for a given domain.
* @param domain Valid domain name.
*/
export async function getAllDnsRecords(domain: string, options: Partial<GetAllDnsRecordsOptions> = {}): Promise<DnsRecord[]> {
const records: DnsRecord[] = []
const dnsRecordsStream = getAllDnsRecordsStream(domain, options)
Expand Down

0 comments on commit f95bbd6

Please sign in to comment.