//native
type Confluence = {
email: string
apiToken: string
domain: string
}
/**
* Get content descendants by type
* Returns all descendants of a given type, for a piece of content.
*/
export async function main(
auth: Confluence,
id: string,
_type: 'page' | 'comment' | 'attachment',
depth: 'all' | 'root' | '<any positive integer argument in the range of 1 and 100>' | undefined,
expand: string | undefined,
start: string | undefined,
limit: string | undefined
) {
const url = new URL(`https://${auth.domain}/wiki/rest/api/content/${id}/descendant/${_type}`)
for (const [k, v] of [
['depth', depth],
['expand', expand],
['start', start],
['limit', limit]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 235 days ago