//native
type Confluence = {
email: string
apiToken: string
domain: string
}
/**
* Search content
* Searches for content using the
[Confluence Query Language (CQL)](https://developer.
*/
export async function main(
auth: Confluence,
cql: string | undefined,
cqlcontext: string | undefined,
cursor: string | undefined,
next: string | undefined,
prev: string | undefined,
limit: string | undefined,
start: string | undefined,
includeArchivedSpaces: string | undefined,
excludeCurrentSpaces: string | undefined,
excerpt:
| 'highlight'
| 'indexed'
| 'none'
| 'highlight_unescaped'
| 'indexed_unescaped'
| undefined,
sitePermissionTypeFilter: 'all' | 'externalCollaborator' | 'none' | undefined,
_: string | undefined,
expand: string | undefined
) {
const url = new URL(`https://${auth.domain}/wiki/rest/api/search`)
for (const [k, v] of [
['cql', cql],
['cqlcontext', cqlcontext],
['cursor', cursor],
['next', next],
['prev', prev],
['limit', limit],
['start', start],
['includeArchivedSpaces', includeArchivedSpaces],
['excludeCurrentSpaces', excludeCurrentSpaces],
['excerpt', excerpt],
['sitePermissionTypeFilter', sitePermissionTypeFilter],
['_', _],
['expand', expand]
]) {
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