← Public packages
@cameronpak/box
Full Box Public API v1 client: lifecycle, prompts, files, commands, snapshots, environments, webhooks, desktop, hosting, and account.
src/get-command-status.ts
32 lines · 1000 B · TypeScriptimport { assertBoxId, boxRequest, failure, type Result } from './client.ts'
import type { CommandStatus } from './types.ts'
export type GetCommandStatusInput = {
boxId: string
/** Process id returned by a detached runCommand. */
processId: number
/** Cap each returned log to its last N bytes. Defaults to 524288 (512 KiB). */
tailBytes?: number
}
/**
* Get status and log tails for a detached command started with
* runCommand({ detached: true }).
*/
export default async function getCommandStatus(
input: GetCommandStatusInput,
): Promise<Result<CommandStatus>> {
const invalid = assertBoxId(input?.boxId)
if (invalid) return failure<CommandStatus>(invalid)
if (!Number.isInteger(input?.processId)) {
return failure<CommandStatus>({
code: 'invalid_process_id',
message: 'processId must be an integer.',
status: 400,
})
}
return boxRequest<CommandStatus>({
path: '/boxes/' + input.boxId + '/commands/' + input.processId,
query: { tailBytes: input.tailBytes },
})
}