← Public packages
@cameronpak/box
Full Box Public API v1 client: lifecycle, prompts, files, commands, snapshots, environments, webhooks, desktop, hosting, and account.
src/stop-box.ts
28 lines · 912 B · TypeScriptimport { assertBoxId, boxRequest, failure, type Result } from './client.ts'
import type { Box } from './types.ts'
export type StopBoxInput = {
boxId: string
/**
* Stop even when the disk cannot be snapshotted. Everything written since the
* last successful snapshot is lost permanently. Only use after a stop was refused.
*/
force?: boolean
}
export type BoxActionOutput = { id: string; status: string; box?: Box | null }
/** Stop a box and archive it so it can be resumed or forked later. */
export default async function stopBox(input: StopBoxInput): Promise<Result<BoxActionOutput>> {
const invalid = assertBoxId(input?.boxId)
if (invalid) return failure<BoxActionOutput>(invalid)
const body: Record<string, unknown> = {}
if (input.force !== undefined) body.force = input.force
return boxRequest<BoxActionOutput>({
path: '/boxes/' + input.boxId + '/stop',
method: 'POST',
body,
})
}