5export const cleanupExplicitWcDns = async (hostname: string) => { 8 const headers = getCfHeaders({cfApiKeySecretName, required: false}) 11 const zoneName = hostname.split('.').slice(-2).join('.') 12 const zones = await cfFetch('/zones', headers) 13 const zone = zones.find((z: any) => z.name === zoneName) 16 const allRecords = await cfFetch(`/zones/${zone.id}/dns_records?per_page=1000`, headers) 17 const matchNames = [hostname, `a-${hostname}`, `cname-${hostname}`] 18 const txtOwnerRecords = allRecords.filter((r: any) => 19 r.type === 'TXT' && r.content?.includes('heritage=external-dns') && matchNames.includes(r.name) 21 const aRecords = allRecords.filter((r: any) => 22 (r.type === 'A' || r.type === 'CNAME') && r.name === hostname 24 const toDelete = [...txtOwnerRecords, ...aRecords] 26 if (!toDelete.length) return 28 for (const record of toDelete) { 29 await cfFetch(`/zones/${zone.id}/dns_records/${record.id}`, headers, {method: 'DELETE'}) 31 betLog({cleanupExplicitWcDns: hostname, deletedRecords: toDelete.length})