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/save-named-snapshot.ts

30 lines · 969 B · TypeScript
import { assertBoxId, boxRequest, failure, type Result } from './client.ts'
import type { NamedSnapshot } from './types.ts'

export type SaveNamedSnapshotInput = {
	boxId: string
	/** 1-63 lowercase letters, digits, or dashes, starting with a letter or digit. */
	name: string
}

export type SaveNamedSnapshotOutput = {
	status: string
	snapshot: NamedSnapshot
}

/**
 * Freeze a box's current state under a name. Returns 202 with status saving.
 * Poll getNamedSnapshot until status is ready or failed. Reusing a name
 * replaces that snapshot's artifact once the new save is ready.
 */
export default async function saveNamedSnapshot(
	input: SaveNamedSnapshotInput,
): Promise<Result<SaveNamedSnapshotOutput>> {
	const invalid = assertBoxId(input?.boxId)
	if (invalid) return failure<SaveNamedSnapshotOutput>(invalid)
	return boxRequest<SaveNamedSnapshotOutput>({
		path: '/named-snapshots',
		method: 'POST',
		body: { boxId: input.boxId, name: input.name },
	})
}