1 | |
2 | type Persona = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Create a Browser Fingerprint List Item |
7 | * Create a new item in a >. |
8 | */ |
9 | export async function main( |
10 | auth: Persona, |
11 | body: { data?: { attributes?: { "list-id"?: string; value?: string } } }, |
12 | include?: string, |
13 | fields?: string, |
14 | Key_Inflection?: string, |
15 | Idempotency_Key?: string, |
16 | Persona_Version?: string, |
17 | ) { |
18 | const url = new URL( |
19 | `https://api.withpersona.com/api/v1/list-item/browser-fingerprints`, |
20 | ); |
21 | for (const [k, v] of [ |
22 | ["include", include], |
23 | ["fields", fields], |
24 | ]) { |
25 | if (v !== undefined && v !== "" && k !== undefined) { |
26 | url.searchParams.append(k, v); |
27 | } |
28 | } |
29 | const headers: Record<string, string> = { |
30 | Authorization: `Bearer ${auth.apiKey}`, |
31 | "Content-Type": "application/json", |
32 | }; |
33 | if (Key_Inflection) { |
34 | headers["Key-Inflection"] = Key_Inflection; |
35 | } |
36 | if (Idempotency_Key) { |
37 | headers["Idempotency-Key"] = Idempotency_Key; |
38 | } |
39 | if (Persona_Version) { |
40 | headers["Persona-Version"] = Persona_Version; |
41 | } |
42 | const response = await fetch(url, { |
43 | method: "POST", |
44 | headers, |
45 | body: JSON.stringify(body), |
46 | }); |
47 | if (!response.ok) { |
48 | const text = await response.text(); |
49 | throw new Error(`${response.status} ${text}`); |
50 | } |
51 | return await response.json(); |
52 | } |
53 |
|