//native
type Zuplo = {
apiKey: string
}
/**
* Creates a consumer
* Creates a new consumer for this account.
*/
export async function main(
auth: Zuplo,
accountName: string,
bucketName: string,
with_api_key: string | undefined,
body: {
name: string
managers?: string[] | { email: string; sub: string }[]
description?: string
tags?: {}
metadata?: {}
}
) {
const url = new URL(
`https://dev.zuplo.com/v1/accounts/${accountName}/key-buckets/${bucketName}/consumers`
)
for (const [k, v] of [['with-api-key', with_api_key]]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'POST',
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.json()
}
Submitted by hugo697 235 days ago