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/set-environment-secret-file.ts

22 lines · 873 B · TypeScript
import { assertEnvironmentId, boxRequest, failure, type Result } from './client.ts'
import type { EnvironmentMutationOutput } from './set-environment-var.ts'

export type SetEnvironmentSecretFileInput = {
	environmentId: string
	/** In-box path relative to the workspace, for example `.env`. */
	path: string
	contents: string
}

/** Add or replace a single secret file by path. Mints a new immutable version. */
export default async function setEnvironmentSecretFile(
	input: SetEnvironmentSecretFileInput,
): Promise<Result<EnvironmentMutationOutput>> {
	const invalid = assertEnvironmentId(input?.environmentId)
	if (invalid) return failure<EnvironmentMutationOutput>(invalid)
	return boxRequest<EnvironmentMutationOutput>({
		path: '/environments/' + input.environmentId + '/secret-files',
		method: 'PUT',
		body: { path: input.path, contents: input.contents },
	})
}