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