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-box.ts

29 lines · 1.0 KB · TypeScript
import { assertBoxId, boxRequest, failure, type Result } from './client.ts'
import type { Box } from './types.ts'

export type UpdateBoxInput = {
	boxId: string
	/** New display name. Empty strings are rejected; longer names truncate to 120 chars. */
	name?: string
	/** New archival TTL. null disables auto-stop. */
	ttlSeconds?: number | null
	/** Rename the box's stable subdomain (`<subdomain>.on.ascii.dev`). */
	subdomain?: string
}

export type UpdateBoxOutput = { box: Box }

/** Update a box's name, auto-stop TTL, or subdomain. */
export default async function updateBox(input: UpdateBoxInput): Promise<Result<UpdateBoxOutput>> {
	const invalid = assertBoxId(input?.boxId)
	if (invalid) return failure<UpdateBoxOutput>(invalid)
	const body: Record<string, unknown> = {}
	if (input.name !== undefined) body.name = input.name
	if ('ttlSeconds' in input) body.ttlSeconds = input.ttlSeconds
	if (input.subdomain !== undefined) body.subdomain = input.subdomain
	return boxRequest<UpdateBoxOutput>({
		path: '/boxes/' + input.boxId,
		method: 'PATCH',
		body,
	})
}