//native
type Confluence = {
email: string
apiToken: string
domain: string
}
/**
* Publish shared draft
* Publishes a shared draft of a page created from a blueprint.
By default, the following objects are expanded: `body.storage`, `history`, `space`, `version`, `ancestors`.
**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
Permission to view the draft and 'Add' permission for the space that
the content will be created in.
*/
export async function main(
auth: Confluence,
draftId: string,
status: string | undefined,
expand: string | undefined,
body: {
version: { number: number }
title: string
type: 'page'
status?: 'current'
space?: { key: string }
ancestors?: { id: string }[]
}
) {
const url = new URL(`https://${auth.domain}/wiki/rest/api/content/blueprint/instance/${draftId}`)
for (const [k, v] of [
['status', status],
['expand', expand]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
},
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