1 | |
2 | type Box = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Search for content |
7 | * Searches for files, folders, web links, and shared files across the |
8 | users content or across the entire enterprise. |
9 | */ |
10 | export async function main( |
11 | auth: Box, |
12 | query: string | undefined, |
13 | scope: "user_content" | "enterprise_content" | undefined, |
14 | file_extensions: string | undefined, |
15 | created_at_range: string | undefined, |
16 | updated_at_range: string | undefined, |
17 | size_range: string | undefined, |
18 | owner_user_ids: string | undefined, |
19 | recent_updater_user_ids: string | undefined, |
20 | ancestor_folder_ids: string | undefined, |
21 | content_types: string | undefined, |
22 | type: "file" | "folder" | "web_link" | undefined, |
23 | trash_content: "non_trashed_only" | "trashed_only" | "all_items" | undefined, |
24 | mdfilters: string | undefined, |
25 | sort: "modified_at" | "relevance" | undefined, |
26 | direction: "DESC" | "ASC" | undefined, |
27 | limit: string | undefined, |
28 | include_recent_shared_links: string | undefined, |
29 | fields: string | undefined, |
30 | offset: string | undefined, |
31 | deleted_user_ids: string | undefined, |
32 | deleted_at_range: string | undefined, |
33 | ) { |
34 | const url = new URL(`https://api.box.com/2.0/search`); |
35 | for (const [k, v] of [ |
36 | ["query", query], |
37 | ["scope", scope], |
38 | ["file_extensions", file_extensions], |
39 | ["created_at_range", created_at_range], |
40 | ["updated_at_range", updated_at_range], |
41 | ["size_range", size_range], |
42 | ["owner_user_ids", owner_user_ids], |
43 | ["recent_updater_user_ids", recent_updater_user_ids], |
44 | ["ancestor_folder_ids", ancestor_folder_ids], |
45 | ["content_types", content_types], |
46 | ["type", type], |
47 | ["trash_content", trash_content], |
48 | ["mdfilters", mdfilters], |
49 | ["sort", sort], |
50 | ["direction", direction], |
51 | ["limit", limit], |
52 | ["include_recent_shared_links", include_recent_shared_links], |
53 | ["fields", fields], |
54 | ["offset", offset], |
55 | ["deleted_user_ids", deleted_user_ids], |
56 | ["deleted_at_range", deleted_at_range], |
57 | ]) { |
58 | if (v !== undefined && v !== "" && k !== undefined) { |
59 | url.searchParams.append(k, v); |
60 | } |
61 | } |
62 | const response = await fetch(url, { |
63 | method: "GET", |
64 | headers: { |
65 | Authorization: "Bearer " + auth.token, |
66 | }, |
67 | body: undefined, |
68 | }); |
69 | if (!response.ok) { |
70 | const text = await response.text(); |
71 | throw new Error(`${response.status} ${text}`); |
72 | } |
73 | return await response.json(); |
74 | } |
75 |
|