[READ-ONLY] Mirror of https://github.com/danielroe/domain-sync. A tiny script that migrates all my Gandi domains to use Cloudflare DNS.
cloudflare dns gandi script
0

Configure Feed

Select the types of activity you want to include in your feed.

domain-sync / api / cloudflare.ts
2.0 kB 77 lines
1import { $fetch } from 'ofetch' 2import { z } from 'zod' 3 4const api = $fetch.create({ 5 baseURL: 'https://api.cloudflare.com/client/v4', 6 headers: { 7 Authorization: `Bearer ${Bun.env.CLOUDFLARE_API_TOKEN}`, 8 }, 9}) 10 11const zoneSchema = z.object({ 12 result: z.object({ 13 id: z.string(), 14 name: z.string(), 15 status: z.string(), 16 paused: z.boolean(), 17 type: z.string(), 18 development_mode: z.number(), 19 name_servers: z.array(z.string()), 20 original_name_servers: z.array(z.string()).nullable(), 21 original_registrar: z.string().nullable(), 22 original_dnshost: z.string().nullable(), 23 modified_on: z.string(), 24 created_on: z.string(), 25 activated_on: z.string().nullable(), 26 meta: z.object({ 27 step: z.number(), 28 custom_certificate_quota: z.number(), 29 page_rule_quota: z.number(), 30 phishing_detected: z.boolean(), 31 multiple_railguns_allowed: z.boolean().optional(), 32 }), 33 owner: z.object({ 34 id: z.string().nullable(), 35 type: z.string(), 36 email: z.string().nullable(), 37 }), 38 account: z.object({ 39 id: z.string(), 40 name: z.string(), 41 }), 42 tenant: z.object({ 43 id: z.string().nullable(), 44 name: z.string().nullable(), 45 }), 46 tenant_unit: z.object({ 47 id: z.string().nullable(), 48 }), 49 permissions: z.array(z.string()), 50 plan: z.object({ 51 id: z.string(), 52 name: z.string(), 53 price: z.number(), 54 currency: z.string(), 55 frequency: z.string(), 56 is_subscribed: z.boolean(), 57 can_subscribe: z.boolean(), 58 legacy_id: z.string(), 59 legacy_discount: z.boolean(), 60 externally_managed: z.boolean(), 61 }), 62 }), 63 success: z.boolean(), 64 errors: z.array(z.unknown()), 65 messages: z.array(z.unknown()), 66}) 67 68export async function createNewDomain(domain: string) { 69 return await api('/zones', { 70 method: 'POST', 71 body: { 72 name: domain, 73 jump_start: true, 74 type: 'full', 75 }, 76 }).then(zone => zoneSchema.parse(zone)) 77}