|
9 | 9 | * - Getting chat members for per-user sharing |
10 | 10 | */ |
11 | 11 |
|
| 12 | +import { readProviderJsonResponse } from "openclaw/plugin-sdk/provider-http"; |
12 | 13 | import type { MSTeamsAccessTokenProvider } from "./attachments/types.js"; |
13 | 14 | import { createMSTeamsHttpError } from "./http-error.js"; |
14 | 15 | import { buildUserAgent } from "./user-agent.js"; |
@@ -54,11 +55,11 @@ export async function uploadToOneDrive(params: { |
54 | 55 | throw await createMSTeamsHttpError(res, "OneDrive upload failed"); |
55 | 56 | } |
56 | 57 |
|
57 | | - const data = (await res.json()) as { |
| 58 | + const data = await readProviderJsonResponse<{ |
58 | 59 | id?: string; |
59 | 60 | webUrl?: string; |
60 | 61 | name?: string; |
61 | | - }; |
| 62 | + }>(res, "msteams.graph-upload.uploadOneDriveFile"); |
62 | 63 |
|
63 | 64 | if (!data.id || !data.webUrl || !data.name) { |
64 | 65 | throw new Error("OneDrive upload response missing required fields"); |
@@ -106,9 +107,9 @@ async function createSharingLink(params: { |
106 | 107 | throw await createMSTeamsHttpError(res, "Create sharing link failed"); |
107 | 108 | } |
108 | 109 |
|
109 | | - const data = (await res.json()) as { |
| 110 | + const data = await readProviderJsonResponse<{ |
110 | 111 | link?: { webUrl?: string }; |
111 | | - }; |
| 112 | + }>(res, "msteams.graph-upload.createOneDriveSharingLink"); |
112 | 113 |
|
113 | 114 | if (!data.link?.webUrl) { |
114 | 115 | throw new Error("Create sharing link response missing webUrl"); |
@@ -200,11 +201,11 @@ export async function uploadToSharePoint(params: { |
200 | 201 | throw await createMSTeamsHttpError(res, "SharePoint upload failed"); |
201 | 202 | } |
202 | 203 |
|
203 | | - const data = (await res.json()) as { |
| 204 | + const data = await readProviderJsonResponse<{ |
204 | 205 | id?: string; |
205 | 206 | webUrl?: string; |
206 | 207 | name?: string; |
207 | | - }; |
| 208 | + }>(res, "msteams.graph-upload.uploadSharePointFile"); |
208 | 209 |
|
209 | 210 | if (!data.id || !data.webUrl || !data.name) { |
210 | 211 | throw new Error("SharePoint upload response missing required fields"); |
@@ -260,11 +261,11 @@ export async function getDriveItemProperties(params: { |
260 | 261 | throw await createMSTeamsHttpError(res, "Get driveItem properties failed"); |
261 | 262 | } |
262 | 263 |
|
263 | | - const data = (await res.json()) as { |
| 264 | + const data = await readProviderJsonResponse<{ |
264 | 265 | eTag?: string; |
265 | 266 | webDavUrl?: string; |
266 | 267 | name?: string; |
267 | | - }; |
| 268 | + }>(res, "msteams.graph-upload.getDriveItemProperties"); |
268 | 269 |
|
269 | 270 | if (!data.eTag || !data.webDavUrl || !data.name) { |
270 | 271 | throw new Error("DriveItem response missing required properties (eTag, webDavUrl, or name)"); |
@@ -331,9 +332,9 @@ export async function resolveGraphChatId(params: { |
331 | 332 | return null; |
332 | 333 | } |
333 | 334 |
|
334 | | - const data = (await res.json()) as { |
| 335 | + const data = await readProviderJsonResponse<{ |
335 | 336 | value?: Array<{ id?: string }>; |
336 | | - }; |
| 337 | + }>(res, "msteams.graph-upload.getOneOnOneChatId"); |
337 | 338 |
|
338 | 339 | const chats = data.value ?? []; |
339 | 340 |
|
@@ -371,12 +372,12 @@ async function getChatMembers(params: { |
371 | 372 | throw await createMSTeamsHttpError(res, "Get chat members failed"); |
372 | 373 | } |
373 | 374 |
|
374 | | - const data = (await res.json()) as { |
| 375 | + const data = await readProviderJsonResponse<{ |
375 | 376 | value?: Array<{ |
376 | 377 | userId?: string; |
377 | 378 | displayName?: string; |
378 | 379 | }>; |
379 | | - }; |
| 380 | + }>(res, "msteams.graph-upload.getChatMembers"); |
380 | 381 |
|
381 | 382 | return (data.value ?? []) |
382 | 383 | .map((m) => ({ |
@@ -435,9 +436,9 @@ async function createSharePointSharingLink(params: { |
435 | 436 | throw await createMSTeamsHttpError(res, "Create SharePoint sharing link failed"); |
436 | 437 | } |
437 | 438 |
|
438 | | - const data = (await res.json()) as { |
| 439 | + const data = await readProviderJsonResponse<{ |
439 | 440 | link?: { webUrl?: string }; |
440 | | - }; |
| 441 | + }>(res, "msteams.graph-upload.createSharePointSharingLink"); |
441 | 442 |
|
442 | 443 | if (!data.link?.webUrl) { |
443 | 444 | throw new Error("Create SharePoint sharing link response missing webUrl"); |
|
0 commit comments