1 | |
2 | type Basistheory = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Logs Get |
7 | * Logs Get |
8 | */ |
9 | export async function main( |
10 | auth: Basistheory, |
11 | entity_type: string | undefined, |
12 | entity_id: string | undefined, |
13 | start_date: string | undefined, |
14 | end_date: string | undefined, |
15 | page: string | undefined, |
16 | start: string | undefined, |
17 | size: string | undefined, |
18 | ) { |
19 | const url = new URL(`https://api.basistheory.com/logs`); |
20 | for (const [k, v] of [ |
21 | ["entity_type", entity_type], |
22 | ["entity_id", entity_id], |
23 | ["start_date", start_date], |
24 | ["end_date", end_date], |
25 | ["page", page], |
26 | ["start", start], |
27 | ["size", size], |
28 | ]) { |
29 | if (v !== undefined && v !== "" && k !== undefined) { |
30 | url.searchParams.append(k, v); |
31 | } |
32 | } |
33 | const response = await fetch(url, { |
34 | method: "GET", |
35 | headers: { |
36 | "BT-API-KEY": auth.apiKey, |
37 | }, |
38 | body: undefined, |
39 | }); |
40 | if (!response.ok) { |
41 | const text = await response.text(); |
42 | throw new Error(`${response.status} ${text}`); |
43 | } |
44 | return await response.json(); |
45 | } |
46 |
|