fix(dns): fallback to data fields comparison for cloudflare structured SRV/CAA records

This commit is contained in:
Yash Kumar 2026-09-08 17:20:59 +05:30
parent df0986b4e1
commit ea1c6fc3fe

View File

@ -169,23 +169,33 @@ export const cloudflareClient: DnsClient<CloudflareConfig> = {
};
const existing = await cfFetch<
{ id: string; type: string; content: string; priority?: number }[]
{
id: string;
type: string;
content: string;
priority?: number;
data?: Record<string, unknown>;
}[]
>(
config,
`/zones/${record.zoneId}/dns_records?type=${record.type}&name=${encodeURIComponent(record.name)}`,
);
const built = buildValue(record);
const normalizedRecord = {
type: record.type,
content: built.content ?? record.content.trim(),
priority: built.priority,
};
const expectedContent = inlinePriority(normalizedRecord);
const existingRecord = existing.find(
(r) => inlinePriority(r) === expectedContent,
);
const existingRecord = existing.find((r) => {
if (built.data) {
return Object.entries(built.data).every(
([k, v]) => r.data && r.data[k] === v,
);
}
const normalizedRecord = {
type: record.type,
content: built.content ?? record.content.trim(),
priority: built.priority,
};
return inlinePriority(r) === inlinePriority(normalizedRecord);
});
if (existingRecord) {
const updated = await cfFetch<{ id: string }>(
config,