//native
type Vercel = {
token: string;
};
/**
* Create a DNS record
* Creates a DNS record for a domain.
*/
export async function main(
auth: Vercel,
domain: string,
teamId: string | undefined,
slug: string | undefined,
body:
| ({
name: string;
type: "A";
ttl?: number;
value: string;
comment?: string;
} & {
type:
| "A"
| "AAAA"
| "ALIAS"
| "CAA"
| "CNAME"
| "HTTPS"
| "MX"
| "SRV"
| "TXT"
| "NS";
})
| ({
name: string;
type: "AAAA";
ttl?: number;
value: string;
comment?: string;
} & {
type:
| "A"
| "AAAA"
| "ALIAS"
| "CAA"
| "CNAME"
| "HTTPS"
| "MX"
| "SRV"
| "TXT"
| "NS";
})
| ({
name: string;
type: "ALIAS";
ttl?: number;
value: string;
comment?: string;
} & {
type:
| "A"
| "AAAA"
| "ALIAS"
| "CAA"
| "CNAME"
| "HTTPS"
| "MX"
| "SRV"
| "TXT"
| "NS";
})
| ({
name: string;
type: "CAA";
ttl?: number;
value: string;
comment?: string;
} & {
type:
| "A"
| "AAAA"
| "ALIAS"
| "CAA"
| "CNAME"
| "HTTPS"
| "MX"
| "SRV"
| "TXT"
| "NS";
})
| ({
name: string;
type: "CNAME";
ttl?: number;
value?: string;
comment?: string;
} & {
type:
| "A"
| "AAAA"
| "ALIAS"
| "CAA"
| "CNAME"
| "HTTPS"
| "MX"
| "SRV"
| "TXT"
| "NS";
})
| ({
name: string;
type: "MX";
ttl?: number;
value: string;
mxPriority: number;
comment?: string;
} & {
type:
| "A"
| "AAAA"
| "ALIAS"
| "CAA"
| "CNAME"
| "HTTPS"
| "MX"
| "SRV"
| "TXT"
| "NS";
})
| ({
name: string;
type: "SRV";
ttl?: number;
srv: { priority: number; weight: number; port: number; target: string };
comment?: string;
} & {
type:
| "A"
| "AAAA"
| "ALIAS"
| "CAA"
| "CNAME"
| "HTTPS"
| "MX"
| "SRV"
| "TXT"
| "NS";
})
| ({
name: string;
type: "TXT";
ttl?: number;
value: string;
comment?: string;
} & {
type:
| "A"
| "AAAA"
| "ALIAS"
| "CAA"
| "CNAME"
| "HTTPS"
| "MX"
| "SRV"
| "TXT"
| "NS";
})
| ({
name: string;
type: "NS";
ttl?: number;
value?: string;
comment?: string;
} & {
type:
| "A"
| "AAAA"
| "ALIAS"
| "CAA"
| "CNAME"
| "HTTPS"
| "MX"
| "SRV"
| "TXT"
| "NS";
})
| ({
name: string;
type: "HTTPS";
ttl?: number;
https: { priority: number; target: string; params?: string };
comment?: string;
} & {
type:
| "A"
| "AAAA"
| "ALIAS"
| "CAA"
| "CNAME"
| "HTTPS"
| "MX"
| "SRV"
| "TXT"
| "NS";
}),
) {
const url = new URL(`https://api.vercel.com/v2/domains/${domain}/records`);
for (const [k, v] of [
["teamId", teamId],
["slug", slug],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago