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/update-secrets.ts

24 lines · 959 B · TypeScript
import { boxRequest, type Result } from './client.ts'
import type { SecretFile } from './types.ts'
import type { SecretsOutput } from './get-secrets.ts'

export type UpdateSecretsInput = {
	/** Full .env-style content. Send the complete desired file, not a patch. */
	envContents?: string
	/** Full list of secret files to keep. Omitted files are dropped. */
	secretFiles?: Array<SecretFile>
}

/**
 * Replace the default environment's secrets setup.
 * Official docs: this is a full replacement, not a merge. Send every variable
 * and secret file that should remain.
 */
export default async function updateSecrets(
	input: UpdateSecretsInput = {},
): Promise<Result<SecretsOutput>> {
	const body: Record<string, unknown> = {}
	if (input.envContents !== undefined) body.envContents = input.envContents
	if (input.secretFiles !== undefined) body.secretFiles = input.secretFiles
	return boxRequest<SecretsOutput>({ path: '/secrets', method: 'POST', body })
}