//native
type Digitalocean = {
token: string;
};
/**
* Create a New Droplet
* To create a new Droplet, send a POST request to `/v2/droplets` setting the
required attributes.
*/
export async function main(
auth: Digitalocean,
body:
| ({ name: string } & {
region?: string;
size: string;
image: string | number;
ssh_keys?: string | number[];
backups?: false | true;
backup_policy?: {
plan?: "daily" | "weekly";
weekday?: "SUN" | "MON" | "TUE" | "WED" | "THU" | "FRI" | "SAT";
hour?: 0 | 4 | 8 | 12 | 16 | 20;
window_length_hours?: number;
retention_period_days?: number;
} & {};
ipv6?: false | true;
monitoring?: false | true;
tags?: string[];
user_data?: string;
private_networking?: false | true;
volumes?: string[];
vpc_uuid?: string;
with_droplet_agent?: false | true;
})
| ({ names: string[] } & {
region?: string;
size: string;
image: string | number;
ssh_keys?: string | number[];
backups?: false | true;
backup_policy?: {
plan?: "daily" | "weekly";
weekday?: "SUN" | "MON" | "TUE" | "WED" | "THU" | "FRI" | "SAT";
hour?: 0 | 4 | 8 | 12 | 16 | 20;
window_length_hours?: number;
retention_period_days?: number;
} & {};
ipv6?: false | true;
monitoring?: false | true;
tags?: string[];
user_data?: string;
private_networking?: false | true;
volumes?: string[];
vpc_uuid?: string;
with_droplet_agent?: false | true;
}),
) {
const url = new URL(`https://api.digitalocean.com/v2/droplets`);
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 537 days ago