1 | |
2 | type Persona = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Redact a Case |
7 | * Permanently redacts a > and its fields. Case objects must be redacted individually. **This action cannot be undone**. |
8 | */ |
9 | export async function main( |
10 | auth: Persona, |
11 | case_id: string, |
12 | include: string | undefined, |
13 | fields: string | undefined, |
14 | Key_Inflection?: string, |
15 | Idempotency_Key?: string, |
16 | Persona_Version?: string, |
17 | ) { |
18 | const url = new URL(`https://api.withpersona.com/api/v1/cases/${case_id}`); |
19 | for (const [k, v] of [ |
20 | ["include", include], |
21 | ["fields", fields], |
22 | ]) { |
23 | if (v !== undefined && v !== "" && k !== undefined) { |
24 | url.searchParams.append(k, v); |
25 | } |
26 | } |
27 | const headers: Record<string, string> = { |
28 | Authorization: `Bearer ${auth.apiKey}`, |
29 | }; |
30 | if (Key_Inflection) { |
31 | headers["Key-Inflection"] = Key_Inflection; |
32 | } |
33 | if (Idempotency_Key) { |
34 | headers["Idempotency-Key"] = Idempotency_Key; |
35 | } |
36 | if (Persona_Version) { |
37 | headers["Persona-Version"] = Persona_Version; |
38 | } |
39 | const response = await fetch(url, { |
40 | method: "DELETE", |
41 | headers, |
42 | body: undefined, |
43 | }); |
44 | if (!response.ok) { |
45 | const text = await response.text(); |
46 | throw new Error(`${response.status} ${text}`); |
47 | } |
48 | return await response.json(); |
49 | } |
50 |
|