-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add fallback to archive on https failure
- Loading branch information
Showing
3 changed files
with
54 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { CustomError } from "../lib/mailauth/tools"; | ||
|
||
const ZKEMAIL_DNS_ARCHIVER_API = "https://archive.prove.email/api/key"; | ||
|
||
export async function resolveDNSFromZKEmailArchive(name: string, type: string) { | ||
if (type !== "TXT") { | ||
throw new Error(`ZK Email Archive only supports TXT records - got ${type}`); | ||
} | ||
|
||
// Get domain from full dns record name - $selector._domainkey.$domain.com | ||
const domain = name.split(".").slice(-2).join("."); | ||
const selector = name.split(".")[0]; | ||
|
||
const queryUrl = new URL(ZKEMAIL_DNS_ARCHIVER_API); | ||
queryUrl.searchParams.set("domain", domain); | ||
|
||
const resp = await fetch(queryUrl); | ||
const data = await resp.json(); | ||
|
||
const dkimRecord = data.find((record: any) => record.selector === selector); | ||
|
||
if (!dkimRecord) { | ||
throw new CustomError( | ||
`DKIM record not found for domain ${domain} and selector ${selector} in ZK Email Archive.`, | ||
"ENODATA" | ||
); | ||
} | ||
|
||
return [dkimRecord.value]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters