1
//native
2
type Discourse = {
3
apiKey: string;
4
defaultHost: string;
5
apiUsername: string;
6
};
7
/**
8
* Remove a topic
9
*
10
*/
11
export async function main(
12
auth: Discourse,
13
id: string,
14
) {
15
const url = new URL(`https://${auth.defaultHost}/t/${id}.json`);
16
17
const response = await fetch(url, {
18
method: "DELETE",
19
headers: {
20
"API-KEY": auth.apiKey,
21
"API-USERNAME": auth.apiUsername,
22
},
23
body: undefined,
24
});
25
if (!response.ok) {
26
const text = await response.text();
27
throw new Error(`${response.status} ${text}`);
28
}
29
return await response.text();
30
31