//native
type Xata = {
apiKey: string
}
/**
* Update workspace member role
* Update a workspace member role. Workspaces must always have at least one owner, so this operation will fail if trying to remove owner role from the last owner in the workspace.
*/
export async function main(
auth: Xata,
workspace_id: string,
user_id: string,
body: { role: 'owner' | 'maintainer' }
) {
const url = new URL(`https://api.xata.io/workspaces/${workspace_id}/members/${user_id}`)
const response = await fetch(url, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.apiKey
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.text()
}
Submitted by hugo697 428 days ago