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