import type { Account } from './account.ts' import { granolaRequest } from './client.ts' import { EMAIL_PATTERN, USER_ID_PATTERN } from './validate.ts' export const LEGAL_HOLD_NOTE = 'Legal holds need a separate "Legal hold API key" (Enterprise, enabled by Granola support; Settings → Connectors → API → Legal hold API keys). Save it under its own account name, e.g. granola--legal. https://docs.granola.ai/legal-holds' /** `["a@x.com", "usr_…"]` → `[{ email }, { id }]` (exactly one per entry, as the API requires). */ export function custodianInputs(values: Array): Array<{ email: string } | { id: string }> { if (values.length > 100) throw new Error('At most 100 custodians per request.') return values.map((v) => { if (USER_ID_PATTERN.test(v)) return { id: v } if (EMAIL_PATTERN.test(v)) return { email: v } throw new Error(`Custodian "${v}" must be a workspace member email or a Granola user id (usr_…).`) }) } export async function getHold(a: Account, holdId: string) { return (await granolaRequest>(a, { path: `/v1/legal-holds/${holdId}` })).data }