184 lines
5.9 KiB
TypeScript
184 lines
5.9 KiB
TypeScript
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 searchQuery: string;
|
|
readonly emptyHeadlineKey: string;
|
|
readonly emptyBodyKey: string;
|
|
}
|
|
|
|
export type VaultListVM = VMState<VaultListData>;
|
|
|
|
export function buildVaultListVM(input: { rows: readonly VaultRow[]; canCreate: boolean; createHref: string; searchQuery?: string }): VaultListVM {
|
|
return {
|
|
status: "ready",
|
|
data: {
|
|
rows: input.rows,
|
|
canCreate: input.canCreate,
|
|
createHref: input.createHref,
|
|
searchQuery: input.searchQuery ?? "",
|
|
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 VaultAccessRow {
|
|
readonly userId: string;
|
|
readonly displayName: string;
|
|
readonly email: string;
|
|
readonly roleNames: readonly string[];
|
|
readonly permissionLevel: PasswordSafePermissionLevel;
|
|
}
|
|
|
|
export interface VaultMemberOption {
|
|
readonly userId: string;
|
|
readonly displayName: string;
|
|
readonly email: string;
|
|
readonly roleNames: readonly string[];
|
|
readonly hasAccess: boolean;
|
|
}
|
|
|
|
export interface PasswordSafeActivityRow {
|
|
readonly id: string;
|
|
readonly createdAtLabel: string;
|
|
readonly actionLabelKey: string;
|
|
readonly actorLabel: string;
|
|
readonly successful: boolean;
|
|
}
|
|
|
|
export interface VaultDetailData {
|
|
readonly vaultId: string;
|
|
readonly vaultName: string;
|
|
readonly accessLevel: PasswordSafePermissionLevel;
|
|
readonly canWrite: boolean;
|
|
readonly canManageAccess: boolean;
|
|
readonly canExport: boolean;
|
|
readonly rows: readonly EntryRow[];
|
|
/** Archived entries remain metadata-only and can be restored by writers. */
|
|
readonly archivedRows: readonly EntryRow[];
|
|
readonly accessRows: readonly VaultAccessRow[];
|
|
readonly memberOptions: readonly VaultMemberOption[];
|
|
readonly activityRows: readonly PasswordSafeActivityRow[];
|
|
/** 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<VaultDetailData>;
|
|
|
|
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 archivedRows?: readonly EntryRow[];
|
|
readonly accessRows?: readonly VaultAccessRow[];
|
|
readonly memberOptions?: readonly VaultMemberOption[];
|
|
readonly activityRows?: readonly PasswordSafeActivityRow[];
|
|
readonly canExport?: boolean;
|
|
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",
|
|
canExport: input.canExport ?? false,
|
|
rows: input.rows,
|
|
archivedRows: input.archivedRows ?? [],
|
|
accessRows: input.accessRows ?? [],
|
|
memberOptions: input.memberOptions ?? [],
|
|
activityRows: input.activityRows ?? [],
|
|
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 (/password-safe/admin) — metadata only, never
|
|
* content access. */
|
|
export interface AdminVaultRow {
|
|
readonly id: string;
|
|
readonly name: string;
|
|
readonly entryCount: number;
|
|
readonly accessCount: number;
|
|
readonly archived: boolean;
|
|
/** Null for a tenant metadata admin without a per-vault content grant. */
|
|
readonly detailHref: string | null;
|
|
}
|
|
|
|
export interface AdminVaultListData {
|
|
readonly rows: readonly AdminVaultRow[];
|
|
readonly activityRows: readonly PasswordSafeActivityRow[];
|
|
readonly searchQuery: string;
|
|
readonly emptyHeadlineKey: string;
|
|
readonly emptyBodyKey: string;
|
|
}
|
|
|
|
export type AdminVaultListVM = VMState<AdminVaultListData>;
|
|
|
|
export function buildAdminVaultListVM(input: {
|
|
rows: readonly AdminVaultRow[];
|
|
activityRows?: readonly PasswordSafeActivityRow[];
|
|
searchQuery?: string;
|
|
}): AdminVaultListVM {
|
|
return {
|
|
status: "ready",
|
|
data: {
|
|
rows: input.rows,
|
|
activityRows: input.activityRows ?? [],
|
|
searchQuery: input.searchQuery ?? "",
|
|
emptyHeadlineKey: "hr.admin.passwordSafe.empty.headline",
|
|
emptyBodyKey: "hr.admin.passwordSafe.empty.body",
|
|
},
|
|
};
|
|
}
|