0

Roll consumer keys

by
Published Oct 17, 2025

Set expiration for keys with no expiration date and creates a new key.

Script zuplo Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zuplo = {
3
	apiKey: string
4
}
5
/**
6
 * Roll consumer keys
7
 * Set expiration for keys with no expiration date and creates a new key.
8
 */
9
export async function main(
10
	auth: Zuplo,
11
	accountName: string,
12
	bucketName: string,
13
	consumerName: string,
14
	tag: string | undefined,
15
	body: { expiresOn: string }
16
) {
17
	const url = new URL(
18
		`https://dev.zuplo.com/v1/accounts/${accountName}/key-buckets/${bucketName}/consumers/${consumerName}/roll-key`
19
	)
20
	for (const [k, v] of [['tag', tag]]) {
21
		if (v !== undefined && v !== '' && k !== undefined) {
22
			url.searchParams.append(k, v)
23
		}
24
	}
25
	const response = await fetch(url, {
26
		method: 'POST',
27
		headers: {
28
			'Content-Type': 'application/json',
29
			Authorization: 'Bearer ' + auth.apiKey
30
		},
31
		body: JSON.stringify(body)
32
	})
33
	if (!response.ok) {
34
		const text = await response.text()
35
		throw new Error(`${response.status} ${text}`)
36
	}
37
	return await response.text()
38
}
39