← Public packages
@cameronpak/box
Full Box Public API v1 client: lifecycle, prompts, files, commands, snapshots, environments, webhooks, desktop, hosting, and account.
src/resume-box.ts
38 lines · 1.4 KB · TypeScriptimport { assertBoxId, boxRequest, failure, type Result } from './client.ts'
import type { BoxSize } from './types.ts'
import type { BoxActionOutput } from './stop-box.ts'
export type ResumeBoxInput = {
boxId: string
/** Resume onto a different machine size. Omit to keep the current size. */
type?: BoxSize
/** Resume without account secrets. One-way; the box stays no-env after this. */
noEnv?: boolean
/** Replaces the box's per-box environment variables. */
env?: Record<string, string>
/** Optionally re-pin the box to a different named environment. */
environment?: string
/** Auto-stop for the resumed box. Omit to keep the current TTL. null disables auto-stop. */
ttlSeconds?: number | null
}
/** Resume an archived box from its snapshot. Poll with waitForBox afterward. */
export default async function resumeBox(
input: ResumeBoxInput,
): Promise<Result<BoxActionOutput>> {
const invalid = assertBoxId(input?.boxId)
if (invalid) return failure<BoxActionOutput>(invalid)
const body: Record<string, unknown> = {}
if (input.type !== undefined) body.type = input.type
if (input.noEnv !== undefined) body.noEnv = input.noEnv
if (input.env !== undefined) body.env = input.env
if (input.environment !== undefined) body.environment = input.environment
if ('ttlSeconds' in input) body.ttlSeconds = input.ttlSeconds
return boxRequest<BoxActionOutput>({
path: '/boxes/' + input.boxId + '/resume',
method: 'POST',
body,
})
}