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/download-artifact.ts

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

export type DownloadArtifactInput = {
	boxId: string
	path: string
}

/**
 * Download a Box artifact as raw bytes.
 * The API streams application/octet-stream; this export base64-encodes the
 * body so the package stays JSON-safe.
 */
export default async function downloadArtifact(
	input: DownloadArtifactInput,
): Promise<Result<BinaryPayload>> {
	const invalid = assertBoxId(input?.boxId)
	if (invalid) return failure<BinaryPayload>(invalid)
	if (!input?.path) {
		return failure<BinaryPayload>({
			code: 'path_required',
			message: 'path is required.',
			status: 400,
		})
	}
	return boxRequest<BinaryPayload>({
		path: '/boxes/' + input.boxId + '/artifacts',
		query: { path: input.path },
		raw: true,
	})
}