@@ -21,14 +21,6 @@ import type {
21
21
ZeroRTTValue ,
22
22
} from "./zone-settings" ;
23
23
24
- /**
25
- * Cloudflare Zone response format
26
- */
27
- export interface CloudflareZone {
28
- id : string ;
29
- name : string ;
30
- }
31
-
32
24
/**
33
25
* Properties for creating or updating a Zone
34
26
*/
@@ -349,8 +341,8 @@ export const Zone = Resource(
349
341
) ;
350
342
}
351
343
352
- const result = ( await response . json ( ) ) as CloudflareZoneResponse ;
353
- const zoneData = result . result ;
344
+ const zoneData = ( ( await response . json ( ) ) as { result : CloudflareZone } )
345
+ . result ;
354
346
355
347
// Update zone settings if provided
356
348
if ( props . settings ) {
@@ -401,15 +393,22 @@ export const Zone = Resource(
401
393
) ;
402
394
}
403
395
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 ] ;
406
405
} else {
407
406
throw new Error (
408
407
`Error creating zone '${ props . name } ': ${ response . statusText } \n${ body } ` ,
409
408
) ;
410
409
}
411
410
} else {
412
- zoneData = ( JSON . parse ( body ) as CloudflareZoneResponse ) . result ;
411
+ zoneData = ( JSON . parse ( body ) as { result : CloudflareZone } ) . result ;
413
412
}
414
413
415
414
// Update zone settings if provided
@@ -547,25 +546,20 @@ async function getZoneSettings(
547
546
}
548
547
549
548
/**
550
- * Cloudflare Zone API response
549
+ * Cloudflare Zone response format
551
550
*/
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 : {
554
558
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 ;
567
559
} ;
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 ;
571
565
}
0 commit comments