import { mutationSpec, parseWithAccount } from '../../lib/api.ts' import { granolaRequest } from '../../lib/client.ts' import { echo, mutationMode, preview } from '../../lib/guard.ts' import { CUSTODIAN_ID_PATTERN, HOLD_ID_PATTERN } from '../../lib/validate.ts' /** * Remove a custodian from a legal hold (`DELETE /v1/legal-holds/{hold_id}/custodians/{custodian_id}`). * The record survives (listed with `removed_at`). If no other active hold covers the person, their * notes lose preservation. WRITE: previews unless `confirm: true`. * * @param input.account - Account whose secret holds a Legal hold API key. Required. @param input.secretName - Secret override. * @param input.holdId - `lgh_…` id. Required. * @param input.custodianId - `lhc_…` custodian entry id (from ./legal-holds/custodians/list), not the user id. Required. * @param input.dryRun - Preview only. @param input.confirm - `true` to remove. * @returns Preview `{ dryRun: true, request }`, or `{ executed: true, result: { id, removed: true, removed_at } }` * * @example * import removeCustodian from 'kody:@charlesmatte/granola/legal-holds/custodians/remove' * * const preview = await removeCustodian({ account: 'work-legal', holdId: 'lgh_Abc123XyZ456Dq', custodianId: 'lhc_7Yt3nBv8Kq2mXb' }) */ export default async function removeGranolaLegalHoldCustodian(input: unknown) { const p = parseWithAccount<{ holdId: string; custodianId: string; dryRun?: boolean; confirm?: boolean }>( input, { holdId: { type: 'string', required: true, pattern: HOLD_ID_PATTERN }, custodianId: { type: 'string', required: true, pattern: CUSTODIAN_ID_PATTERN }, ...mutationSpec, }, 'legal-holds/custodians/remove', ) const mode = mutationMode(p) const path = `/v1/legal-holds/${p.holdId}/custodians/${p.custodianId}` const target = `custodian ${p.custodianId} on legal hold ${p.holdId}` if (!mode.execute) return preview(p.acct, 'legal-holds/custodians/remove', target, mode, { method: 'DELETE', path }) const res = await granolaRequest(p.acct, { method: 'DELETE', path, retries: 1 }) return { dryRun: false, executed: true, echo: echo(p.acct, 'legal-holds/custodians/remove', target, mode), result: res.data } }