Build, Test, and Push CFDM Docker Image / test (push) Failing after 51s
Build, Test, and Push CFDM Docker Image / build-and-push (push) Has been skipped
Build, Test, and Push CFDM Docker Image / update-wiki (push) Has been skipped
Build, Test, and Push CFDM Docker Image / create-release (push) Has been skipped
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
export function dnsNameToSubdomainLabel(
|
|
recordName: string,
|
|
zoneName: string,
|
|
): string | null {
|
|
const rn = recordName.trim().replace(/\.+$/, "");
|
|
const zn = zoneName.trim().replace(/\.+$/, "");
|
|
if (!rn || !zn) return null;
|
|
|
|
if (rn === "*") return "*";
|
|
|
|
const wildcardFqdn = `*.${zn}`;
|
|
if (rn.toLowerCase() === wildcardFqdn.toLowerCase()) return "*";
|
|
|
|
if (rn.toLowerCase() === zn.toLowerCase()) return "@";
|
|
|
|
const zoneSuffix = `.${zn}`;
|
|
if (rn.toLowerCase().endsWith(zoneSuffix.toLowerCase())) {
|
|
const prefix = rn.slice(0, rn.length - zoneSuffix.length);
|
|
return prefix || "@";
|
|
}
|
|
|
|
if (!rn.includes(".")) return rn;
|
|
|
|
return null;
|
|
}
|
|
|
|
export function subdomainLabelToFqdn(label: string, zoneName: string): string {
|
|
return label === "@" ? zoneName : `${label}.${zoneName}`;
|
|
}
|
|
|
|
/** Canonical DNS record name as returned by Cloudflare for a zone. */
|
|
export function normalizeDnsRecordName(
|
|
recordName: string,
|
|
zoneName: string,
|
|
): string {
|
|
const label = dnsNameToSubdomainLabel(recordName, zoneName);
|
|
if (label == null) {
|
|
return recordName.trim().replace(/\.+$/, "");
|
|
}
|
|
return subdomainLabelToFqdn(label, zoneName);
|
|
}
|
|
|
|
export function dnsRecordNamesMatch(
|
|
left: string,
|
|
right: string,
|
|
zoneName: string,
|
|
): boolean {
|
|
return (
|
|
normalizeDnsRecordName(left, zoneName).toLowerCase() ===
|
|
normalizeDnsRecordName(right, zoneName).toLowerCase()
|
|
);
|
|
}
|