Skip to content
← Public packages

@cameronpak/box

Full Box Public API v1 client: lifecycle, prompts, files, commands, snapshots, environments, webhooks, desktop, hosting, and account.

src/rotate-webhook-secret.ts

25 lines · 830 B · TypeScript
import { assertWebhookId, boxRequest, failure, type Result } from './client.ts'
import type { Webhook } from './types.ts'

export type RotateWebhookSecretInput = { webhookId: string }

export type RotateWebhookSecretOutput = {
	webhook: Webhook
	/** New signing secret, shown only once. Briefly accept the old secret too. */
	secret: string
}

/**
 * Replace a webhook signing secret and return the new secret once.
 * Treat the secret as confidential.
 */
export default async function rotateWebhookSecret(
	input: RotateWebhookSecretInput,
): Promise<Result<RotateWebhookSecretOutput>> {
	const invalid = assertWebhookId(input?.webhookId)
	if (invalid) return failure<RotateWebhookSecretOutput>(invalid)
	return boxRequest<RotateWebhookSecretOutput>({
		path: '/webhooks/' + input.webhookId + '/rotate',
		method: 'POST',
	})
}