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/types.ts

254 lines · 5.1 KB · TypeScript
export type BoxState =
	| 'init'
	| 'provisioning'
	| 'provisioned'
	| 'cloning'
	| 'ready'
	| 'idle'
	| 'running'
	| 'archiving'
	| 'archived'
	| 'error'

export type BoxSize = 'small' | 'default' | 'large'

/** A Box machine as returned by the v1 API. */
export type Box = {
	id: string
	name: string
	state: BoxState
	type?: BoxSize | 'bare-metal'
	vcpu?: number
	memoryGB?: number
	billingMultiplier?: number
	url?: string | null
	ip?: string | null
	createdAt?: string | null
	updatedAt?: string | null
	archiveAfter?: string | null
	desktopAvailable: boolean
	/** Secret-bearing stream URL. Redact from logs. */
	desktopUrl?: string | null
	snapshotAvailable: boolean
	snapshotCompletedAt?: string | null
	subdomain?: string | null
	lastSnapshotAttemptAt?: string | null
	lastSnapshotStatus?: string | null
	setupStatus?: 'pending' | 'running' | 'done' | 'failed' | null
	setupError?: string | null
	environment?: string | null
	environmentVersion?: number | null
}

export type PageInfo = {
	nextCursor: string | null
	hasMore: boolean
	limit: number
}

export type BoxEvent = {
	id?: string
	type: string
	timestamp?: number
	taskId?: string | null
	data?: Record<string, unknown>
}

export type PromptRun = {
	id: string
	promptId: string
	boxId: string
	status: 'sending' | 'queued' | 'running' | 'finished' | 'failed'
	done: boolean
	createdAt?: string | null
	model?: string | null
	reasoningEffort?: string | null
}

export type CommandResult = {
	success: boolean
	exitCode: number | null
	signal?: string | null
	stdout: string
	stderr: string
	stdoutTruncated?: boolean
	stderrTruncated?: boolean
	timedOut: boolean
	cwd?: string
	startedAt?: string
	finishedAt?: string
}

export type CommandStarted = {
	success: boolean
	processId: number
	pid: number
	command: string
	cwd?: string
	startedAt: string
	logPath?: string
	errLogPath?: string
}

export type CommandStatus = {
	success: boolean
	processId: number
	pid?: number
	status: 'running' | 'exited' | 'lost'
	known?: boolean
	running: boolean
	exitCode: number | null
	signal?: string | null
	command?: string | null
	cwd?: string | null
	startedAt?: string | null
	finishedAt?: string | null
	stdout: string
	stderr: string
	stdoutTruncated?: boolean
	stderrTruncated?: boolean
	logPath?: string
	errLogPath?: string
}

export type DeletionOperation = {
	id: string
	kind: 'box' | 'snapshot'
	targetId: string
	reason: 'explicit' | 'zdr' | 'account'
	status: 'pending' | 'processing' | 'blocked' | 'completed'
	attemptCount: number
	requestedAt: string
	completedAt: string | null
}

export type DataRetentionPolicy = {
	enabled: boolean
	enabledAt: string | null
	queuedBoxes?: number
	acceptedDeletionOperationsIrreversible?: boolean
}

export type WebhookEventType = 'box.ready' | 'box.error' | 'box.archived'

export type Webhook = {
	id: string
	name: string | null
	url: string
	events: Array<WebhookEventType>
	createdAt: string
	updatedAt: string
}

export type SecretFile = {
	path: string
	/** Secret file contents. Treat as sensitive. */
	contents: string
}

export type ApiKey = {
	id: string
	name: string
	keyPrefix: string
	keyLastFour: string
	createdAt: string
	lastUsedAt?: string | null
}

export type NamedSnapshot = {
	name: string
	status: 'saving' | 'ready' | 'failed'
	error?: string
	sourceBoxId: string
	snapshotId?: string
	type?: string
	sizeBytes?: number
	createdAt: string
}

export type SnapshotSummary = {
	id: string
	boxId: string
	status: 'completed'
	kind?: 'base' | 'incremental' | null
	generation: number
	chainId?: string | null
	createdAt: string
	completedAt?: string | null
	sizeBytes: number
	fileCount: number
	contentSizeBytes?: number | null
	contentFileCount?: number | null
}

export type SnapshotTreeEntry = {
	path: string
	kind: 'file' | 'dir' | 'symlink'
	size?: number
}

export type SnapshotChunk = {
	snapshotId: string
	generation: number
	chunkIndex: number
	r2Key: string
	sizeBytes: number
	sha256: string
	/** Time-limited download URL. Redact from logs. */
	signedUrl: string
}

export type Repository = {
	id?: number
	databaseId?: string
	name?: string
	fullName?: string
	private?: boolean
	permissions?: string
	pushedAt?: string | null
}

export type SelectedRepository = Repository & {
	baseBranch?: string
	setupRoutineId?: string | null
	setupScript?: string
	setupBlocking?: boolean
	preCommitHooks?: Array<{ id?: string; script?: string; blocking?: boolean }>
}

export type RepositoryInstallation = {
	type?: string
	accountLogin?: string
	accountAvatarUrl?: string | null
	repositories?: Array<Repository>
}

export type BoxEnvironmentVersionSummary = {
	id: string
	versionNumber: number
	boxCount: number
	createdAt: string
}

export type BoxEnvironment = {
	id: string
	name: string
	isDefault: boolean
	latestVersionId: string | null
	safeForThirdParties: boolean
	passGithub: boolean
	passSecrets: boolean
	passBoxCredentials: boolean
	passAgentsCredentials: boolean
	envContents: string
	secretFiles: Array<SecretFile>
	selectedRepositories?: Array<SelectedRepository>
	versions: Array<BoxEnvironmentVersionSummary>
}

export type BoxUser = {
	login: string
	email: string | null
	zeroDataRetention?: boolean
	zeroDataRetentionEnabledAt?: string | null
}