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

27 lines · 1006 B · TypeScript
import { assertSnapshotId, boxRequest, failure, type Result } from './client.ts'
import type { DeleteAcceptedOutput } from './delete-box.ts'

export type DeleteSnapshotInput = {
	snapshotId: string
	/** Must exactly equal snapshotId. Defaults to snapshotId. */
	confirmDelete?: string
}

/**
 * Permanently delete one ordinary filesystem snapshot.
 * Returns 409 while another incremental snapshot or an active restore still
 * depends on it. Sends X-Ascii-Confirm-Delete, which must equal the snapshot id.
 * Poll getDeletionOperation until completed.
 */
export default async function deleteSnapshot(
	input: DeleteSnapshotInput,
): Promise<Result<DeleteAcceptedOutput>> {
	const invalid = assertSnapshotId(input?.snapshotId)
	if (invalid) return failure<DeleteAcceptedOutput>(invalid)
	const confirm = input.confirmDelete ?? input.snapshotId
	return boxRequest<DeleteAcceptedOutput>({
		path: '/snapshots/' + input.snapshotId,
		method: 'DELETE',
		headers: { 'X-Ascii-Confirm-Delete': confirm },
	})
}