//native
type Linode = {
token: string;
};
/**
* Create a domain record
* Adds a new Domain Record to the zonefile this Domain represents.
*/
export async function main(
auth: Linode,
apiVersion: "v4" | "v4beta",
domainId: string,
body: {
created?: string;
id?: number;
name?: string;
port?: number;
priority?: number;
protocol?: string;
service?: string;
tag?: "issue" | "issuewild" | "iodef";
target?: string;
ttl_sec?: number;
type?: "A" | "AAAA" | "NS" | "MX" | "CNAME" | "TXT" | "SRV" | "PTR" | "CAA";
updated?: string;
weight?: number;
},
) {
const url = new URL(
`https://api.linode.com/${apiVersion}/domains/${domainId}/records`,
);
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 235 days ago