import type { VMState } from "../index.js"; /** * HR password-safe view-models (AK-P17a). Pure functions (DoD A.3). * * CRITICAL: no secret value ever enters a VM. The entry rows carry only titles, * tags, url and BOOLEAN "hasX" flags — never the username/password/notes. The * actual value is fetched on demand by a separate, audited reveal action and is * never persisted in any rendered model. */ export type PasswordSafePermissionLevel = "read" | "write" | "admin"; export interface VaultRow { readonly id: string; readonly name: string; readonly description: string | null; /** The caller's own access level on this vault. */ readonly accessLevel: PasswordSafePermissionLevel; /** Internal route to the vault's entries. */ readonly detailHref: string; } export interface VaultListData { readonly rows: readonly VaultRow[]; readonly canCreate: boolean; readonly createHref: string; readonly emptyHeadlineKey: string; readonly emptyBodyKey: string; } export type VaultListVM = VMState; export function buildVaultListVM(input: { rows: readonly VaultRow[]; canCreate: boolean; createHref: string }): VaultListVM { return { status: "ready", data: { rows: input.rows, canCreate: input.canCreate, createHref: input.createHref, emptyHeadlineKey: "hr.passwordSafe.empty.headline", emptyBodyKey: "hr.passwordSafe.empty.body", }, }; } /** A single entry WITHOUT secret values — only presence flags. */ export interface EntryRow { readonly id: string; readonly title: string; readonly tags: readonly string[]; readonly url: string | null; readonly hasUsername: boolean; readonly hasPassword: boolean; readonly hasNotes: boolean; /** Endpoint the UI calls to reveal a single field on demand (audited). */ readonly revealHref: string; } export interface VaultDetailData { readonly vaultId: string; readonly vaultName: string; readonly accessLevel: PasswordSafePermissionLevel; readonly canWrite: boolean; readonly canManageAccess: boolean; readonly rows: readonly EntryRow[]; /** 30s clipboard auto-clear window (ms) the UI enforces after a copy (DoD #3). */ readonly copyAutoClearMs: number; readonly exportHref: string; readonly emptyHeadlineKey: string; readonly emptyBodyKey: string; } export type VaultDetailVM = VMState; export const PASSWORD_SAFE_COPY_AUTO_CLEAR_MS = 30_000; export interface BuildVaultDetailVMInput { readonly vaultId: string; readonly vaultName: string; readonly accessLevel: PasswordSafePermissionLevel; readonly rows: readonly EntryRow[]; readonly exportHref: string; } export function buildVaultDetailVM(input: BuildVaultDetailVMInput): VaultDetailVM { const canWrite = input.accessLevel === "write" || input.accessLevel === "admin"; return { status: "ready", data: { vaultId: input.vaultId, vaultName: input.vaultName, accessLevel: input.accessLevel, canWrite, canManageAccess: input.accessLevel === "admin", rows: input.rows, copyAutoClearMs: PASSWORD_SAFE_COPY_AUTO_CLEAR_MS, exportHref: input.exportHref, emptyHeadlineKey: "hr.passwordSafe.entries.empty.headline", emptyBodyKey: "hr.passwordSafe.entries.empty.body", }, }; } /** Tenant-wide admin vault list (/admin/hr/password-safe) — metadata only, never * content access. */ export interface AdminVaultRow { readonly id: string; readonly name: string; readonly entryCount: number; readonly accessCount: number; readonly archived: boolean; readonly detailHref: string; } export interface AdminVaultListData { readonly rows: readonly AdminVaultRow[]; readonly emptyHeadlineKey: string; readonly emptyBodyKey: string; } export type AdminVaultListVM = VMState; export function buildAdminVaultListVM(input: { rows: readonly AdminVaultRow[] }): AdminVaultListVM { return { status: "ready", data: { rows: input.rows, emptyHeadlineKey: "hr.admin.passwordSafe.empty.headline", emptyBodyKey: "hr.admin.passwordSafe.empty.body", }, }; }