//native
type Zuplo = {
apiKey: string
}
/**
* Roll consumer keys
* Set expiration for keys with no expiration date and creates a new key.
*/
export async function main(
auth: Zuplo,
accountName: string,
bucketName: string,
consumerName: string,
tag: string | undefined,
body: { expiresOn: string }
) {
const url = new URL(
`https://dev.zuplo.com/v1/accounts/${accountName}/key-buckets/${bucketName}/consumers/${consumerName}/roll-key`
)
for (const [k, v] of [['tag', tag]]) {
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.text()
}
Submitted by hugo697 235 days ago