Skip to content

Commit 4e6b17b

Browse files
committed
get from list
1 parent 0492e35 commit 4e6b17b

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed

alchemy/src/cloudflare/zone.ts

+25-31
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ import type {
2121
ZeroRTTValue,
2222
} from "./zone-settings";
2323

24-
/**
25-
* Cloudflare Zone response format
26-
*/
27-
export interface CloudflareZone {
28-
id: string;
29-
name: string;
30-
}
31-
3224
/**
3325
* Properties for creating or updating a Zone
3426
*/
@@ -349,8 +341,8 @@ export const Zone = Resource(
349341
);
350342
}
351343

352-
const result = (await response.json()) as CloudflareZoneResponse;
353-
const zoneData = result.result;
344+
const zoneData = ((await response.json()) as { result: CloudflareZone })
345+
.result;
354346

355347
// Update zone settings if provided
356348
if (props.settings) {
@@ -401,15 +393,22 @@ export const Zone = Resource(
401393
);
402394
}
403395

404-
zoneData = ((await getResponse.json()) as CloudflareZoneResponse)
405-
.result;
396+
const zones = (
397+
(await getResponse.json()) as { result: CloudflareZone[] }
398+
).result;
399+
if (zones.length === 0) {
400+
throw new Error(
401+
`Zone '${props.name}' does not exist, but the name is reserved for another user.`,
402+
);
403+
}
404+
zoneData = zones[0];
406405
} else {
407406
throw new Error(
408407
`Error creating zone '${props.name}': ${response.statusText}\n${body}`,
409408
);
410409
}
411410
} else {
412-
zoneData = (JSON.parse(body) as CloudflareZoneResponse).result;
411+
zoneData = (JSON.parse(body) as { result: CloudflareZone }).result;
413412
}
414413

415414
// Update zone settings if provided
@@ -547,25 +546,20 @@ async function getZoneSettings(
547546
}
548547

549548
/**
550-
* Cloudflare Zone API response
549+
* Cloudflare Zone response format
551550
*/
552-
interface CloudflareZoneResponse {
553-
result: {
551+
export interface CloudflareZone {
552+
id: string;
553+
name: string;
554+
type: "full" | "partial" | "secondary";
555+
status: string;
556+
paused: boolean;
557+
account: {
554558
id: string;
555-
name: string;
556-
type: "full" | "partial" | "secondary";
557-
status: string;
558-
paused: boolean;
559-
account: {
560-
id: string;
561-
};
562-
name_servers: string[];
563-
original_name_servers: string[] | null;
564-
created_on: string;
565-
modified_on: string;
566-
activated_on: string | null;
567559
};
568-
success: boolean;
569-
errors: Array<{ code: number; message: string }>;
570-
messages: string[];
560+
name_servers: string[];
561+
original_name_servers: string[] | null;
562+
created_on: string;
563+
modified_on: string;
564+
activated_on: string | null;
571565
}

0 commit comments

Comments
 (0)