From 924d0298896086ee2b8a7ed5378502165063d18f Mon Sep 17 00:00:00 2001 From: Fang-Pen Lin Date: Fri, 21 Nov 2025 09:56:24 -0800 Subject: [PATCH] Implement listing zone --- .../dns-made-easy-connection-fns.ts | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/backend/src/services/app-connection/dns-made-easy/dns-made-easy-connection-fns.ts b/backend/src/services/app-connection/dns-made-easy/dns-made-easy-connection-fns.ts index d42ee465e..40fda4fb2 100644 --- a/backend/src/services/app-connection/dns-made-easy/dns-made-easy-connection-fns.ts +++ b/backend/src/services/app-connection/dns-made-easy/dns-made-easy-connection-fns.ts @@ -60,12 +60,6 @@ export const getDNSMadeEasyConnectionListItem = () => { }; export const listDNSMadeEasyZones = async (appConnection: TDNSMadeEasyConnection): Promise => { - // TODO: Implement DNS Made Easy zones listing - // This should call the DNS Made Easy API to list all zones/domains - // Example API endpoint: GET https://api.dnsmadeeasy.com/V2.0/dns/managed - // Authentication: Use API key and secret from appConnection.credentials - // Return format: Array of { id: string, name: string } - if (appConnection.method !== DNSMadeEasyConnectionMethod.APIKeySecret) { throw new Error("Unsupported DNS Made Easy connection method"); } @@ -75,10 +69,42 @@ export const listDNSMadeEasyZones = async (appConnection: TDNSMadeEasyConnection } = appConnection; try { - // TODO: const allZones: TDNSMadeEasyZone[] = []; + let currentPage = 0; + let totalPages = 1; + + // Fetch all pages of zones + while (currentPage < totalPages) { + // eslint-disable-next-line no-await-in-loop + const resp = await request.get(getDNSMadeEasyUrl("/V2.0/dns/managed/"), { + headers: { + ...makeDNSMadeEasyAuthHeaders(apiKey, secretKey), + Accept: "application/json" + }, + params: { + page: currentPage + } + }); + + if (resp.data?.data) { + // Map the API response to TDNSMadeEasyZone format + const zones = resp.data.data.map((zone) => ({ + id: String(zone.id), + name: zone.name + })); + allZones.push(...zones); + + // Update pagination info + totalPages = resp.data.totalPages || 1; + currentPage += 1; + } else { + break; + } + } + return allZones; } catch (error: unknown) { + logger.error(error, "Error listing DNS Made Easy zones"); if (error instanceof AxiosError) { throw new BadRequestError({ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access