Skip to content

Commit 88675a6

Browse files
authored
feat(contact): expose NsResolver class (#650)
1 parent f7ce6f5 commit 88675a6

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

.changeset/upset-socks-clean.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nodesecure/contact": minor
3+
---
4+
5+
Expose NsResolver class and add API documentation

workspaces/contact/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ console.log({ illuminated, expired });
5454

5555
## API
5656

57+
- [NsResolver](./docs/NsResolver.md)
58+
5759
Contact is defined by the following TypeScript interface:
5860
```ts
5961
interface Contact {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# NsResolver
2+
3+
`NsResolver` is a utility class that collects email addresses and detects which ones have **expired domain names** by performing DNS NS record lookups.
4+
5+
It is used internally by `ContactExtractor` but is also exported for direct use.
6+
7+
## Usage example
8+
9+
```ts
10+
import { NsResolver } from "@nodesecure/contact";
11+
12+
const resolver = new NsResolver();
13+
14+
resolver.registerEmail("alice@valid-domain.com");
15+
resolver.registerEmail("bob@expired-domain.xyz");
16+
17+
const expired = await resolver.getExpired();
18+
console.log(expired); // ["bob@expired-domain.xyz"] (if NS lookup fails)
19+
```
20+
21+
## API
22+
23+
### `new NsResolver()`
24+
25+
Creates a new instance. The DNS resolver is pre-configured to use Cloudflare (`1.1.1.1`) and Google (`8.8.8.8`) public DNS servers.
26+
27+
### `registerEmail(email: string | undefined | null): void`
28+
29+
Registers an email address for later NS resolution. Silently ignores `null`, `undefined`, and blank strings.
30+
31+
### `getExpired(): Promise<string[]>`
32+
33+
Resolves NS records for the domain of every registered email in parallel. Returns the list of emails whose domain **failed** the NS lookup (i.e. the domain is expired or does not exist).

workspaces/contact/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from "./ContactExtractor.class.ts";
22
export {
33
compareContact
44
} from "./utils/index.ts";
5+
export { NsResolver } from "./NsResolver.class.ts";

0 commit comments

Comments
 (0)