1 | |
2 | type Clerk = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * List all users |
7 | * Returns a list of all users. |
8 | The users are returned sorted by creation date, with the newest users appearing first. |
9 | */ |
10 | export async function main( |
11 | auth: Clerk, |
12 | email_address: string | undefined, |
13 | phone_number: string | undefined, |
14 | external_id: string | undefined, |
15 | username: string | undefined, |
16 | web3_wallet: string | undefined, |
17 | user_id: string | undefined, |
18 | organization_id: string | undefined, |
19 | query: string | undefined, |
20 | email_address_query: string | undefined, |
21 | phone_number_query: string | undefined, |
22 | username_query: string | undefined, |
23 | name_query: string | undefined, |
24 | last_active_at_before: string | undefined, |
25 | last_active_at_after: string | undefined, |
26 | last_active_at_since: string | undefined, |
27 | created_at_before: string | undefined, |
28 | created_at_after: string | undefined, |
29 | limit: string | undefined, |
30 | offset: string | undefined, |
31 | order_by: string | undefined, |
32 | ) { |
33 | const url = new URL(`https://api.clerk.com/v1/users`); |
34 | for (const [k, v] of [ |
35 | ["email_address", email_address], |
36 | ["phone_number", phone_number], |
37 | ["external_id", external_id], |
38 | ["username", username], |
39 | ["web3_wallet", web3_wallet], |
40 | ["user_id", user_id], |
41 | ["organization_id", organization_id], |
42 | ["query", query], |
43 | ["email_address_query", email_address_query], |
44 | ["phone_number_query", phone_number_query], |
45 | ["username_query", username_query], |
46 | ["name_query", name_query], |
47 | ["last_active_at_before", last_active_at_before], |
48 | ["last_active_at_after", last_active_at_after], |
49 | ["last_active_at_since", last_active_at_since], |
50 | ["created_at_before", created_at_before], |
51 | ["created_at_after", created_at_after], |
52 | ["limit", limit], |
53 | ["offset", offset], |
54 | ["order_by", order_by], |
55 | ]) { |
56 | if (v !== undefined && v !== "" && k !== undefined) { |
57 | url.searchParams.append(k, v); |
58 | } |
59 | } |
60 | const response = await fetch(url, { |
61 | method: "GET", |
62 | headers: { |
63 | Authorization: "Bearer " + auth.apiKey, |
64 | }, |
65 | body: undefined, |
66 | }); |
67 | if (!response.ok) { |
68 | const text = await response.text(); |
69 | throw new Error(`${response.status} ${text}`); |
70 | } |
71 | return await response.json(); |
72 | } |
73 |
|