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/get-latest-box-snapshot.ts

17 lines · 707 B · TypeScript
import { assertBoxId, boxRequest, failure, type Result } from './client.ts'
import type { SnapshotSummary } from './types.ts'

export type GetLatestBoxSnapshotInput = { boxId: string }

export type GetLatestBoxSnapshotOutput = { snapshot: SnapshotSummary | null }

/** Return the most recent completed snapshot for this box, or null if it has none. */
export default async function getLatestBoxSnapshot(
	input: GetLatestBoxSnapshotInput,
): Promise<Result<GetLatestBoxSnapshotOutput>> {
	const invalid = assertBoxId(input?.boxId)
	if (invalid) return failure<GetLatestBoxSnapshotOutput>(invalid)
	return boxRequest<GetLatestBoxSnapshotOutput>({
		path: '/boxes/' + input.boxId + '/snapshots/latest',
	})
}