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