quality / commitlint (push) Skipped
CD / update-wiki (push) Failing after 8s
quality / changes (push) Successful in 5s
quality / docker-check (push) Skipped
quality / web (push) Successful in 50s
quality / api (push) Successful in 41s
CD / quality (push) Successful in 1m40s
CD / publish (push) Successful in 1m33s
- Introduced origin health check routes and integrated them into the application. - Updated health check configuration to include success recovery thresholds. - Expanded error handling with new error codes for health check failures. - Added new service routes for managing health checks, including creation and listing. - Improved health check service logic to track consecutive successes and failures. This commit enhances the health check capabilities, providing better monitoring and management of service health.
107 lines
3.3 KiB
TypeScript
107 lines
3.3 KiB
TypeScript
import type { CfDnsRecord, CreateDnsRecordPayload, PatchDnsRecordPayload } from "@cfdm/shared";
|
|
import { withRetry } from "../cf-retry.js";
|
|
import { CF_API_BASE, handleCfResponse, mapCloudflareFailure } from "./http.js";
|
|
|
|
export function createDnsAdapter(token: string) {
|
|
return {
|
|
async listDnsRecords(zoneId: string): Promise<CfDnsRecord[]> {
|
|
return withRetry(async () => {
|
|
const all: CfDnsRecord[] = [];
|
|
let page = 1;
|
|
while (page <= 50) {
|
|
const url = new URL(`${CF_API_BASE}/zones/${zoneId}/dns_records`);
|
|
url.searchParams.set("per_page", "100");
|
|
url.searchParams.set("page", String(page));
|
|
const response = await fetch(url, {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
signal: AbortSignal.timeout(30_000),
|
|
});
|
|
if (response.status >= 500 || response.status === 429) {
|
|
throw mapCloudflareFailure(
|
|
"list_dns_records",
|
|
response.status,
|
|
String(response.status),
|
|
);
|
|
}
|
|
const batch = await handleCfResponse<CfDnsRecord[]>(
|
|
response,
|
|
"list_dns_records",
|
|
);
|
|
if (batch.length === 0) break;
|
|
all.push(...batch);
|
|
page += 1;
|
|
}
|
|
return all;
|
|
});
|
|
},
|
|
|
|
async createDnsRecord(
|
|
zoneId: string,
|
|
payload: CreateDnsRecordPayload,
|
|
): Promise<CfDnsRecord> {
|
|
const response = await fetch(`${CF_API_BASE}/zones/${zoneId}/dns_records`, {
|
|
method: "POST",
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(payload),
|
|
signal: AbortSignal.timeout(30_000),
|
|
});
|
|
return handleCfResponse(response, "create_dns_record");
|
|
},
|
|
|
|
async updateDnsRecord(
|
|
zoneId: string,
|
|
recordId: string,
|
|
payload: CreateDnsRecordPayload,
|
|
): Promise<CfDnsRecord> {
|
|
const response = await fetch(
|
|
`${CF_API_BASE}/zones/${zoneId}/dns_records/${recordId}`,
|
|
{
|
|
method: "PUT",
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(payload),
|
|
signal: AbortSignal.timeout(30_000),
|
|
},
|
|
);
|
|
return handleCfResponse(response, "update_dns_record");
|
|
},
|
|
|
|
async patchDnsRecord(
|
|
zoneId: string,
|
|
recordId: string,
|
|
payload: PatchDnsRecordPayload,
|
|
): Promise<CfDnsRecord> {
|
|
const response = await fetch(
|
|
`${CF_API_BASE}/zones/${zoneId}/dns_records/${recordId}`,
|
|
{
|
|
method: "PATCH",
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(payload),
|
|
signal: AbortSignal.timeout(30_000),
|
|
},
|
|
);
|
|
return handleCfResponse(response, "patch_dns_record");
|
|
},
|
|
|
|
async deleteDnsRecord(zoneId: string, recordId: string): Promise<void> {
|
|
const response = await fetch(
|
|
`${CF_API_BASE}/zones/${zoneId}/dns_records/${recordId}`,
|
|
{
|
|
method: "DELETE",
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
signal: AbortSignal.timeout(30_000),
|
|
},
|
|
);
|
|
await handleCfResponse(response, "delete_dns_record");
|
|
},
|
|
};
|
|
}
|