Files
opencode-manager/frontend/src/api/secrets.ts
T
Chris Scott 2884e68a69 feat(secrets): secrets and variables UI and env mapping in trust review
Add a Secrets manager for global values (Settings > Secrets and variables) and
repo values (Secrets tool panel and dialog), with environment scoping,
write-only secrets and copyable ${{ }} references. The trust review for
.ocm/project.json lists the environment and each mapped variable with the
expression it resolves from.
2026-10-23 22:59:57 -04:00

47 lines
1.4 KiB
TypeScript

import { API_BASE_URL } from '@/config'
import type { SecretKind, SecretListResponse, SetSecretRequest } from '@opencode-manager/shared/schemas'
import { fetchWrapper, fetchWrapperVoid } from './fetchWrapper'
export type SecretScope = { scope: 'global' } | { scope: 'repo'; repoId: number }
const KIND_SEGMENT: Record<SecretKind, string> = {
secret: 'secrets',
variable: 'variables',
}
function secretsPath(scope: SecretScope, kind: SecretKind): string {
const segment = KIND_SEGMENT[kind]
return scope.scope === 'global'
? `${API_BASE_URL}/api/${segment}`
: `${API_BASE_URL}/api/repos/${scope.repoId}/${segment}`
}
export async function listSecrets(scope: SecretScope, kind: SecretKind): Promise<SecretListResponse> {
return fetchWrapper(secretsPath(scope, kind))
}
export async function setSecret(
scope: SecretScope,
kind: SecretKind,
name: string,
request: SetSecretRequest,
): Promise<void> {
return fetchWrapperVoid(`${secretsPath(scope, kind)}/${encodeURIComponent(name)}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(request),
})
}
export async function deleteSecret(
scope: SecretScope,
kind: SecretKind,
name: string,
environment?: string,
): Promise<void> {
return fetchWrapperVoid(`${secretsPath(scope, kind)}/${encodeURIComponent(name)}`, {
method: 'DELETE',
...(environment ? { params: { environment } } : {}),
})
}