1 | |
2 | type Persona = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Update an Account |
7 | * Updates an existing Account. |
8 | */ |
9 | export async function main( |
10 | auth: Persona, |
11 | account_id: string, |
12 | body: { |
13 | data?: { |
14 | attributes?: { |
15 | "reference-id"?: string; |
16 | "account-status"?: string; |
17 | "selfie-photo"?: { data?: { data?: string; filename?: string } }; |
18 | tags?: string[]; |
19 | "country-code"?: string; |
20 | "social-security-number"?: string; |
21 | fields?: {}; |
22 | birthdate?: string; |
23 | "name-first"?: string; |
24 | "name-middle"?: string; |
25 | "name-last"?: string; |
26 | "phone-number"?: string; |
27 | "email-address"?: string; |
28 | "address-street-1"?: string; |
29 | "address-street-2"?: string; |
30 | "address-city"?: string; |
31 | "address-subdivision"?: string; |
32 | "address-postal-code"?: string; |
33 | }; |
34 | }; |
35 | }, |
36 | include?: string, |
37 | fields?: string, |
38 | Key_Inflection?: string, |
39 | Idempotency_Key?: string, |
40 | Persona_Version?: string, |
41 | ) { |
42 | const url = new URL( |
43 | `https://api.withpersona.com/api/v1/accounts/${account_id}`, |
44 | ); |
45 | for (const [k, v] of [ |
46 | ["include", include], |
47 | ["fields", fields], |
48 | ]) { |
49 | if (v !== undefined && v !== "" && k !== undefined) { |
50 | url.searchParams.append(k, v); |
51 | } |
52 | } |
53 | const headers: Record<string, string> = { |
54 | Authorization: `Bearer ${auth.apiKey}`, |
55 | "Content-Type": "application/json", |
56 | }; |
57 | if (Key_Inflection) { |
58 | headers["Key-Inflection"] = Key_Inflection; |
59 | } |
60 | if (Idempotency_Key) { |
61 | headers["Idempotency-Key"] = Idempotency_Key; |
62 | } |
63 | if (Persona_Version) { |
64 | headers["Persona-Version"] = Persona_Version; |
65 | } |
66 | const response = await fetch(url, { |
67 | method: "PATCH", |
68 | headers, |
69 | body: JSON.stringify(body), |
70 | }); |
71 | if (!response.ok) { |
72 | const text = await response.text(); |
73 | throw new Error(`${response.status} ${text}`); |
74 | } |
75 | return await response.json(); |
76 | } |
77 |
|