1 | |
2 | type Box = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create Box Skill cards on file |
7 | * Applies one or more Box Skills metadata cards to a file. |
8 | */ |
9 | export async function main( |
10 | auth: Box, |
11 | file_id: string, |
12 | body: { |
13 | cards: |
14 | | { |
15 | created_at?: string; |
16 | type: "skill_card"; |
17 | skill_card_type: "keyword"; |
18 | skill_card_title?: { code?: string; message: string }; |
19 | skill: { type: "service"; id: string }; |
20 | invocation: { type: "skill_invocation"; id: string }; |
21 | entries: { text?: string }[]; |
22 | } |
23 | | { |
24 | created_at?: string; |
25 | type: "skill_card"; |
26 | skill_card_type: "timeline"; |
27 | skill_card_title?: { code?: string; message: string }; |
28 | skill: { type: "service"; id: string }; |
29 | invocation: { type: "skill_invocation"; id: string }; |
30 | duration?: number; |
31 | entries: { |
32 | text?: string; |
33 | appears?: { start?: number; end?: number }[]; |
34 | image_url?: string; |
35 | }[]; |
36 | } |
37 | | { |
38 | created_at?: string; |
39 | type: "skill_card"; |
40 | skill_card_type: "transcript"; |
41 | skill_card_title?: { code?: string; message: string }; |
42 | skill: { type: "service"; id: string }; |
43 | invocation: { type: "skill_invocation"; id: string }; |
44 | duration?: number; |
45 | entries: { text?: string; appears?: { start?: number }[] }[]; |
46 | } |
47 | | { |
48 | created_at?: string; |
49 | type: "skill_card"; |
50 | skill_card_type: "status"; |
51 | skill_card_title?: { code?: string; message: string }; |
52 | status: { |
53 | code: |
54 | | "invoked" |
55 | | "processing" |
56 | | "success" |
57 | | "transient_failure" |
58 | | "permanent_failure"; |
59 | message?: string; |
60 | }; |
61 | skill: { type: "service"; id: string }; |
62 | invocation: { type: "skill_invocation"; id: string }; |
63 | }[]; |
64 | }, |
65 | ) { |
66 | const url = new URL( |
67 | `https://api.box.com/2.0/files/${file_id}/metadata/global/boxSkillsCards`, |
68 | ); |
69 |
|
70 | const response = await fetch(url, { |
71 | method: "POST", |
72 | headers: { |
73 | "Content-Type": "application/json", |
74 | Authorization: "Bearer " + auth.token, |
75 | }, |
76 | body: JSON.stringify(body), |
77 | }); |
78 | if (!response.ok) { |
79 | const text = await response.text(); |
80 | throw new Error(`${response.status} ${text}`); |
81 | } |
82 | return await response.json(); |
83 | } |
84 |
|