1 | |
2 | type Persona = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Report Action: Dismiss Matches |
7 | * Dismisses active matches for supported report types |
8 | */ |
9 | export async function main( |
10 | auth: Persona, |
11 | report_id: string, |
12 | body: { |
13 | data: { |
14 | attributes?: { |
15 | "dismiss-type"?: string; |
16 | "entity-id"?: string; |
17 | reason?: string; |
18 | }; |
19 | }; |
20 | }, |
21 | include?: string, |
22 | fields?: string, |
23 | Key_Inflection?: string, |
24 | Idempotency_Key?: string, |
25 | Persona_Version?: string, |
26 | ) { |
27 | const url = new URL( |
28 | `https://api.withpersona.com/api/v1/reports/${report_id}/dismiss`, |
29 | ); |
30 | for (const [k, v] of [ |
31 | ["include", include], |
32 | ["fields", fields], |
33 | ]) { |
34 | if (v !== undefined && v !== "" && k !== undefined) { |
35 | url.searchParams.append(k, v); |
36 | } |
37 | } |
38 | const headers: Record<string, string> = { |
39 | Authorization: `Bearer ${auth.apiKey}`, |
40 | "Content-Type": "application/json", |
41 | }; |
42 | if (Key_Inflection) { |
43 | headers["Key-Inflection"] = Key_Inflection; |
44 | } |
45 | if (Idempotency_Key) { |
46 | headers["Idempotency-Key"] = Idempotency_Key; |
47 | } |
48 | if (Persona_Version) { |
49 | headers["Persona-Version"] = Persona_Version; |
50 | } |
51 | const response = await fetch(url, { |
52 | method: "POST", |
53 | headers, |
54 | body: JSON.stringify(body), |
55 | }); |
56 | if (!response.ok) { |
57 | const text = await response.text(); |
58 | throw new Error(`${response.status} ${text}`); |
59 | } |
60 | return await response.json(); |
61 | } |
62 |
|