← Public packages
@cameronpak/box
Full Box Public API v1 client: lifecycle, prompts, files, commands, snapshots, environments, webhooks, desktop, hosting, and account.
src/get-desktop-url.ts
42 lines · 1.4 KB · TypeScriptimport { assertBoxId, boxRequest, failure, type Result } from './client.ts'
export type GetDesktopUrlInput = {
boxId: string
/** Use VNC/noVNC streaming. Send 1. */
vnc?: 1
/** Desktop streaming theme for non-VNC mode. */
theme?: 'light' | 'dark'
/** For vnc=1, return a noVNC URL that does not require an access token. */
publicAccess?: boolean
}
export type GetDesktopUrlOutput = {
success?: boolean
/** Secret-bearing desktop or noVNC URL. Redact from logs. */
desktopUrl?: string | null
ip?: string | null
mode?: string
/** For vnc=1, true means VNC is still being prepared; poll again. */
provisioning?: boolean
message?: string
}
/**
* Create or fetch a secret-bearing desktop or noVNC URL.
* Desktop and VNC URLs can contain access tokens. Do not log or persist them
* unredacted. Use vnc=1 for noVNC; a provisioning: true response means poll again.
*/
export default async function getDesktopUrl(
input: GetDesktopUrlInput,
): Promise<Result<GetDesktopUrlOutput>> {
const invalid = assertBoxId(input?.boxId)
if (invalid) return failure<GetDesktopUrlOutput>(invalid)
const body: Record<string, unknown> = {}
if (input.publicAccess !== undefined) body.publicAccess = input.publicAccess
return boxRequest<GetDesktopUrlOutput>({
path: '/boxes/' + input.boxId + '/desktop',
method: 'POST',
query: { vnc: input.vnc, theme: input.theme },
body: Object.keys(body).length ? body : undefined,
})
}