@kodelyth/msteams 2026.5.42 → 2026.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/klaw.plugin.json +726 -2
  2. package/package.json +18 -6
  3. package/api.ts +0 -3
  4. package/channel-config-api.ts +0 -1
  5. package/channel-plugin-api.ts +0 -2
  6. package/config-api.ts +0 -4
  7. package/contract-api.ts +0 -4
  8. package/index.ts +0 -20
  9. package/runtime-api.ts +0 -66
  10. package/secret-contract-api.ts +0 -5
  11. package/setup-entry.ts +0 -13
  12. package/setup-plugin-api.ts +0 -3
  13. package/src/ai-entity.ts +0 -7
  14. package/src/approval-auth.ts +0 -44
  15. package/src/attachments/bot-framework.test.ts +0 -506
  16. package/src/attachments/bot-framework.ts +0 -348
  17. package/src/attachments/download.ts +0 -328
  18. package/src/attachments/graph.test.ts +0 -441
  19. package/src/attachments/graph.ts +0 -489
  20. package/src/attachments/html.ts +0 -122
  21. package/src/attachments/payload.ts +0 -14
  22. package/src/attachments/remote-media.test.ts +0 -187
  23. package/src/attachments/remote-media.ts +0 -86
  24. package/src/attachments/shared.test.ts +0 -547
  25. package/src/attachments/shared.ts +0 -655
  26. package/src/attachments/types.ts +0 -47
  27. package/src/attachments.graph.test.ts +0 -414
  28. package/src/attachments.helpers.test.ts +0 -245
  29. package/src/attachments.test-helpers.ts +0 -17
  30. package/src/attachments.test.ts +0 -754
  31. package/src/attachments.ts +0 -18
  32. package/src/block-streaming-config.test.ts +0 -61
  33. package/src/channel-api.ts +0 -1
  34. package/src/channel.actions.test.ts +0 -797
  35. package/src/channel.directory.test.ts +0 -176
  36. package/src/channel.message-adapter.test.ts +0 -227
  37. package/src/channel.runtime.ts +0 -56
  38. package/src/channel.setup.ts +0 -77
  39. package/src/channel.test.ts +0 -136
  40. package/src/channel.ts +0 -1176
  41. package/src/config-schema.ts +0 -6
  42. package/src/config-ui-hints.ts +0 -40
  43. package/src/conversation-store-fs.test.ts +0 -81
  44. package/src/conversation-store-fs.ts +0 -149
  45. package/src/conversation-store-helpers.test.ts +0 -202
  46. package/src/conversation-store-helpers.ts +0 -105
  47. package/src/conversation-store-memory.ts +0 -51
  48. package/src/conversation-store.shared.test.ts +0 -260
  49. package/src/conversation-store.ts +0 -71
  50. package/src/directory-live.test.ts +0 -156
  51. package/src/directory-live.ts +0 -111
  52. package/src/doctor.ts +0 -27
  53. package/src/errors.test.ts +0 -154
  54. package/src/errors.ts +0 -270
  55. package/src/feedback-reflection-prompt.ts +0 -117
  56. package/src/feedback-reflection-store.ts +0 -113
  57. package/src/feedback-reflection.test.ts +0 -237
  58. package/src/feedback-reflection.ts +0 -268
  59. package/src/file-consent-helpers.test.ts +0 -328
  60. package/src/file-consent-helpers.ts +0 -115
  61. package/src/file-consent-invoke.ts +0 -150
  62. package/src/file-consent.test.ts +0 -378
  63. package/src/file-consent.ts +0 -223
  64. package/src/graph-chat.ts +0 -36
  65. package/src/graph-group-management.test.ts +0 -332
  66. package/src/graph-group-management.ts +0 -168
  67. package/src/graph-members.test.ts +0 -89
  68. package/src/graph-members.ts +0 -48
  69. package/src/graph-messages.actions.test.ts +0 -253
  70. package/src/graph-messages.read.test.ts +0 -391
  71. package/src/graph-messages.search.test.ts +0 -227
  72. package/src/graph-messages.test-helpers.ts +0 -50
  73. package/src/graph-messages.ts +0 -534
  74. package/src/graph-teams.test.ts +0 -222
  75. package/src/graph-teams.ts +0 -114
  76. package/src/graph-thread.test.ts +0 -252
  77. package/src/graph-thread.ts +0 -146
  78. package/src/graph-upload.test.ts +0 -253
  79. package/src/graph-upload.ts +0 -531
  80. package/src/graph-users.ts +0 -29
  81. package/src/graph.test.ts +0 -540
  82. package/src/graph.ts +0 -308
  83. package/src/inbound.test.ts +0 -221
  84. package/src/inbound.ts +0 -148
  85. package/src/index.ts +0 -4
  86. package/src/media-helpers.test.ts +0 -220
  87. package/src/media-helpers.ts +0 -105
  88. package/src/mentions.test.ts +0 -254
  89. package/src/mentions.ts +0 -114
  90. package/src/messenger.test.ts +0 -961
  91. package/src/messenger.ts +0 -608
  92. package/src/monitor-handler/access.ts +0 -136
  93. package/src/monitor-handler/inbound-media.test.ts +0 -314
  94. package/src/monitor-handler/inbound-media.ts +0 -180
  95. package/src/monitor-handler/message-handler-mock-support.test-support.ts +0 -28
  96. package/src/monitor-handler/message-handler.authz.test.ts +0 -739
  97. package/src/monitor-handler/message-handler.dm-media.test.ts +0 -54
  98. package/src/monitor-handler/message-handler.test-support.ts +0 -99
  99. package/src/monitor-handler/message-handler.thread-parent.test.ts +0 -225
  100. package/src/monitor-handler/message-handler.thread-session.test.ts +0 -132
  101. package/src/monitor-handler/message-handler.ts +0 -1003
  102. package/src/monitor-handler/reaction-handler.test.ts +0 -325
  103. package/src/monitor-handler/reaction-handler.ts +0 -122
  104. package/src/monitor-handler/thread-session.ts +0 -30
  105. package/src/monitor-handler.adaptive-card.test.ts +0 -158
  106. package/src/monitor-handler.feedback-authz.test.ts +0 -357
  107. package/src/monitor-handler.file-consent.test.ts +0 -443
  108. package/src/monitor-handler.sso.test.ts +0 -576
  109. package/src/monitor-handler.test-helpers.ts +0 -181
  110. package/src/monitor-handler.ts +0 -538
  111. package/src/monitor-handler.types.ts +0 -27
  112. package/src/monitor-types.ts +0 -6
  113. package/src/monitor.lifecycle.test.ts +0 -457
  114. package/src/monitor.test.ts +0 -119
  115. package/src/monitor.ts +0 -476
  116. package/src/oauth.flow.ts +0 -77
  117. package/src/oauth.shared.ts +0 -37
  118. package/src/oauth.test.ts +0 -350
  119. package/src/oauth.token.ts +0 -162
  120. package/src/oauth.ts +0 -130
  121. package/src/outbound.test.ts +0 -400
  122. package/src/outbound.ts +0 -198
  123. package/src/pending-uploads-fs.test.ts +0 -261
  124. package/src/pending-uploads-fs.ts +0 -235
  125. package/src/pending-uploads.test.ts +0 -186
  126. package/src/pending-uploads.ts +0 -121
  127. package/src/policy.test.ts +0 -156
  128. package/src/policy.ts +0 -245
  129. package/src/polls-store-memory.ts +0 -32
  130. package/src/polls.test.ts +0 -169
  131. package/src/polls.ts +0 -312
  132. package/src/presentation.ts +0 -93
  133. package/src/probe.test.ts +0 -79
  134. package/src/probe.ts +0 -132
  135. package/src/reply-dispatcher.test.ts +0 -543
  136. package/src/reply-dispatcher.ts +0 -523
  137. package/src/reply-stream-controller.test.ts +0 -424
  138. package/src/reply-stream-controller.ts +0 -334
  139. package/src/resolve-allowlist.test.ts +0 -253
  140. package/src/resolve-allowlist.ts +0 -309
  141. package/src/revoked-context.ts +0 -17
  142. package/src/runtime.ts +0 -12
  143. package/src/sdk-types.ts +0 -59
  144. package/src/sdk.test.ts +0 -727
  145. package/src/sdk.ts +0 -916
  146. package/src/secret-contract.ts +0 -49
  147. package/src/secret-input.ts +0 -7
  148. package/src/send-context.test.ts +0 -93
  149. package/src/send-context.ts +0 -269
  150. package/src/send.test.ts +0 -588
  151. package/src/send.ts +0 -697
  152. package/src/sent-message-cache.test.ts +0 -106
  153. package/src/sent-message-cache.ts +0 -174
  154. package/src/session-route.ts +0 -40
  155. package/src/setup-core.ts +0 -162
  156. package/src/setup-surface.test.ts +0 -175
  157. package/src/setup-surface.ts +0 -319
  158. package/src/sso-token-store.test.ts +0 -74
  159. package/src/sso-token-store.ts +0 -166
  160. package/src/sso.ts +0 -300
  161. package/src/storage.ts +0 -25
  162. package/src/store-fs.ts +0 -42
  163. package/src/streaming-message.test.ts +0 -323
  164. package/src/streaming-message.ts +0 -327
  165. package/src/test-runtime.ts +0 -16
  166. package/src/thread-parent-context.test.ts +0 -224
  167. package/src/thread-parent-context.ts +0 -159
  168. package/src/token-response.ts +0 -11
  169. package/src/token.test.ts +0 -268
  170. package/src/token.ts +0 -194
  171. package/src/user-agent.test.ts +0 -121
  172. package/src/user-agent.ts +0 -53
  173. package/src/webhook-timeouts.ts +0 -27
  174. package/src/welcome-card.test.ts +0 -104
  175. package/src/welcome-card.ts +0 -57
  176. package/test-api.ts +0 -1
  177. package/tsconfig.json +0 -16
@@ -1,506 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
- import { setMSTeamsRuntime } from "../runtime.js";
3
- import {
4
- downloadMSTeamsBotFrameworkAttachment,
5
- downloadMSTeamsBotFrameworkAttachments,
6
- isBotFrameworkPersonalChatId,
7
- } from "./bot-framework.js";
8
- import type { MSTeamsAccessTokenProvider } from "./types.js";
9
-
10
- type SavedCall = {
11
- buffer: Buffer;
12
- contentType?: string;
13
- direction: string;
14
- maxBytes: number;
15
- originalFilename?: string;
16
- };
17
-
18
- type MockRuntime = {
19
- saveCalls: SavedCall[];
20
- savePath: string;
21
- savedContentType: string;
22
- };
23
-
24
- function installRuntime(): MockRuntime {
25
- const state: MockRuntime = {
26
- saveCalls: [],
27
- savePath: "/tmp/bf-attachment.bin",
28
- savedContentType: "application/pdf",
29
- };
30
- setMSTeamsRuntime({
31
- media: {
32
- detectMime: async ({ headerMime }: { headerMime?: string }) =>
33
- headerMime ?? "application/pdf",
34
- },
35
- channel: {
36
- media: {
37
- saveMediaBuffer: async (
38
- buffer: Buffer,
39
- contentType: string | undefined,
40
- direction: string,
41
- maxBytes: number,
42
- originalFilename?: string,
43
- ) => {
44
- state.saveCalls.push({
45
- buffer,
46
- contentType,
47
- direction,
48
- maxBytes,
49
- originalFilename,
50
- });
51
- return { path: state.savePath, contentType: state.savedContentType };
52
- },
53
- readRemoteMediaBuffer: async () => ({ buffer: Buffer.alloc(0), contentType: undefined }),
54
- saveRemoteMedia: async () => ({
55
- path: state.savePath,
56
- contentType: state.savedContentType,
57
- }),
58
- saveResponseMedia: async (
59
- response: Response,
60
- options: {
61
- fallbackContentType?: string;
62
- subdir?: string;
63
- maxBytes?: number;
64
- originalFilename?: string;
65
- },
66
- ) => {
67
- const buffer = Buffer.from(await response.arrayBuffer());
68
- state.saveCalls.push({
69
- buffer,
70
- contentType: options.fallbackContentType,
71
- direction: options.subdir ?? "inbound",
72
- maxBytes: options.maxBytes ?? 0,
73
- originalFilename: options.originalFilename,
74
- });
75
- return { path: state.savePath, contentType: state.savedContentType };
76
- },
77
- },
78
- },
79
- } as unknown as Parameters<typeof setMSTeamsRuntime>[0]);
80
- return state;
81
- }
82
-
83
- function createMockFetch(entries: Array<{ match: RegExp; response: Response }>): typeof fetch {
84
- return (async (input: RequestInfo | URL) => {
85
- const url =
86
- typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
87
- const entry = entries.find((e) => e.match.test(url));
88
- if (!entry) {
89
- return new Response("not found", { status: 404 });
90
- }
91
- return entry.response.clone();
92
- }) as typeof fetch;
93
- }
94
-
95
- function buildTokenProvider(): MSTeamsAccessTokenProvider {
96
- return {
97
- getAccessToken: vi.fn(async (scope: string) => {
98
- if (scope.includes("botframework.com")) {
99
- return "bf-token";
100
- }
101
- return "graph-token";
102
- }),
103
- };
104
- }
105
-
106
- function firstMockCall(mock: ReturnType<typeof vi.fn>, label: string): unknown[] {
107
- const [call] = mock.mock.calls;
108
- if (!call) {
109
- throw new Error(`expected ${label} call`);
110
- }
111
- return call;
112
- }
113
-
114
- async function resolvePublicHost(): Promise<{ address: string }> {
115
- return { address: "93.184.216.34" };
116
- }
117
-
118
- describe("isBotFrameworkPersonalChatId", () => {
119
- it("detects a: prefix personal chat IDs", () => {
120
- expect(isBotFrameworkPersonalChatId("a:1dRsHCobZ1AxURzY05Dc")).toBe(true);
121
- });
122
-
123
- it("detects 8:orgid: prefix chat IDs", () => {
124
- expect(isBotFrameworkPersonalChatId("8:orgid:12345678-1234-1234-1234-123456789abc")).toBe(true);
125
- });
126
-
127
- it("returns false for Graph-compatible 19: thread IDs", () => {
128
- expect(isBotFrameworkPersonalChatId("19:abc@thread.tacv2")).toBe(false);
129
- });
130
-
131
- it("returns false for synthetic DM Graph IDs", () => {
132
- expect(isBotFrameworkPersonalChatId("19:aad-user-id_bot-app-id@unq.gbl.spaces")).toBe(false);
133
- });
134
-
135
- it("returns false for null/undefined/empty", () => {
136
- expect(isBotFrameworkPersonalChatId(null)).toBe(false);
137
- expect(isBotFrameworkPersonalChatId(undefined)).toBe(false);
138
- expect(isBotFrameworkPersonalChatId("")).toBe(false);
139
- });
140
- });
141
-
142
- describe("downloadMSTeamsBotFrameworkAttachment", () => {
143
- let runtime: MockRuntime;
144
- beforeEach(() => {
145
- runtime = installRuntime();
146
- });
147
-
148
- it("fetches attachment info then view and saves media", async () => {
149
- const info = {
150
- name: "report.pdf",
151
- type: "application/pdf",
152
- views: [{ viewId: "original", size: 1024 }],
153
- };
154
- const fileBytes = Buffer.from("PDFBYTES", "utf-8");
155
- const fetchFn = createMockFetch([
156
- {
157
- match: /\/v3\/attachments\/att-1$/,
158
- response: new Response(JSON.stringify(info), {
159
- status: 200,
160
- headers: { "content-type": "application/json" },
161
- }),
162
- },
163
- {
164
- match: /\/v3\/attachments\/att-1\/views\/original$/,
165
- response: new Response(fileBytes, {
166
- status: 200,
167
- headers: { "content-length": String(fileBytes.byteLength) },
168
- }),
169
- },
170
- ]);
171
-
172
- const media = await downloadMSTeamsBotFrameworkAttachment({
173
- serviceUrl: "https://smba.trafficmanager.net/amer/",
174
- attachmentId: "att-1",
175
- tokenProvider: buildTokenProvider(),
176
- maxBytes: 10_000_000,
177
- fetchFn,
178
- resolveFn: resolvePublicHost,
179
- });
180
-
181
- expect(media?.path).toBe(runtime.savePath);
182
- expect(media?.contentType).toBe(runtime.savedContentType);
183
- expect(runtime.saveCalls).toHaveLength(1);
184
- expect(runtime.saveCalls[0].buffer.toString("utf-8")).toBe("PDFBYTES");
185
- });
186
-
187
- it("returns undefined when attachment info fetch fails", async () => {
188
- const fetchFn = createMockFetch([
189
- {
190
- match: /\/v3\/attachments\//,
191
- response: new Response("unauthorized", { status: 401 }),
192
- },
193
- ]);
194
-
195
- const media = await downloadMSTeamsBotFrameworkAttachment({
196
- serviceUrl: "https://smba.trafficmanager.net/amer",
197
- attachmentId: "att-1",
198
- tokenProvider: buildTokenProvider(),
199
- maxBytes: 10_000_000,
200
- fetchFn,
201
- resolveFn: resolvePublicHost,
202
- });
203
-
204
- expect(media).toBeUndefined();
205
- expect(runtime.saveCalls).toHaveLength(0);
206
- });
207
-
208
- it("skips when attachment view size exceeds maxBytes", async () => {
209
- const info = {
210
- name: "huge.bin",
211
- type: "application/octet-stream",
212
- views: [{ viewId: "original", size: 50_000_000 }],
213
- };
214
- const fetchFn = createMockFetch([
215
- {
216
- match: /\/v3\/attachments\/big-1$/,
217
- response: new Response(JSON.stringify(info), { status: 200 }),
218
- },
219
- ]);
220
-
221
- const media = await downloadMSTeamsBotFrameworkAttachment({
222
- serviceUrl: "https://smba.trafficmanager.net/amer",
223
- attachmentId: "big-1",
224
- tokenProvider: buildTokenProvider(),
225
- maxBytes: 10_000_000,
226
- fetchFn,
227
- resolveFn: resolvePublicHost,
228
- });
229
-
230
- expect(media).toBeUndefined();
231
- expect(runtime.saveCalls).toHaveLength(0);
232
- });
233
-
234
- it("returns undefined when no views are returned", async () => {
235
- const info = { name: "nothing", type: "application/pdf", views: [] };
236
- const fetchFn = createMockFetch([
237
- {
238
- match: /\/v3\/attachments\/empty-1$/,
239
- response: new Response(JSON.stringify(info), { status: 200 }),
240
- },
241
- ]);
242
-
243
- const media = await downloadMSTeamsBotFrameworkAttachment({
244
- serviceUrl: "https://smba.trafficmanager.net/amer",
245
- attachmentId: "empty-1",
246
- tokenProvider: buildTokenProvider(),
247
- maxBytes: 10_000_000,
248
- fetchFn,
249
- resolveFn: resolvePublicHost,
250
- });
251
-
252
- expect(media).toBeUndefined();
253
- });
254
-
255
- it("returns undefined without a tokenProvider", async () => {
256
- const fetchFn = vi.fn();
257
- const media = await downloadMSTeamsBotFrameworkAttachment({
258
- serviceUrl: "https://smba.trafficmanager.net/amer",
259
- attachmentId: "att-1",
260
- tokenProvider: undefined,
261
- maxBytes: 10_000_000,
262
- fetchFn: fetchFn as unknown as typeof fetch,
263
- });
264
- expect(media).toBeUndefined();
265
- expect(fetchFn).not.toHaveBeenCalled();
266
- });
267
-
268
- describe("Node 24+ dispatcher bypass (issue #63396)", () => {
269
- it("drives the caller's fetchFn directly without the pinned undici dispatcher", async () => {
270
- // Regression: before the fix, fetchBotFrameworkAttachment* routed
271
- // through `fetchWithSsrFGuard`, which installs a `createPinnedDispatcher`
272
- // incompatible with Node 24+'s built-in undici v7. Downloads failed with
273
- // "invalid onRequestStart method". The fix switches to
274
- // `safeFetchWithPolicy`, which calls the supplied `fetchFn` directly
275
- // and never attaches a pinned dispatcher. Verify the caller's `fetchFn`
276
- // is invoked (no dispatcher in init).
277
- const fileBytes = Buffer.from("BFBYTES", "utf-8");
278
- const fetchCalls: Array<{ url: string; init?: RequestInit }> = [];
279
- const fetchFn: typeof fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
280
- const url =
281
- typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
282
- fetchCalls.push({ url, init });
283
- if (url.endsWith("/v3/attachments/att-1")) {
284
- return new Response(
285
- JSON.stringify({
286
- name: "doc.pdf",
287
- type: "application/pdf",
288
- views: [{ viewId: "original", size: fileBytes.byteLength }],
289
- }),
290
- { status: 200, headers: { "content-type": "application/json" } },
291
- );
292
- }
293
- if (url.endsWith("/v3/attachments/att-1/views/original")) {
294
- return new Response(fileBytes, {
295
- status: 200,
296
- headers: { "content-length": String(fileBytes.byteLength) },
297
- });
298
- }
299
- return new Response("not found", { status: 404 });
300
- }) as typeof fetch;
301
-
302
- const media = await downloadMSTeamsBotFrameworkAttachment({
303
- serviceUrl: "https://smba.trafficmanager.net/amer",
304
- attachmentId: "att-1",
305
- tokenProvider: buildTokenProvider(),
306
- maxBytes: 10_000_000,
307
- fetchFn,
308
- resolveFn: resolvePublicHost,
309
- });
310
-
311
- expect(media?.path).toBe(runtime.savePath);
312
- expect(media?.contentType).toBe(runtime.savedContentType);
313
- // Both the attachment info call and the view call should be observed,
314
- // confirming the direct fetch path was taken (no dispatcher interception).
315
- expect(fetchCalls).toHaveLength(2);
316
- expect(fetchCalls[0].url.endsWith("/v3/attachments/att-1")).toBe(true);
317
- expect(fetchCalls[1].url.endsWith("/v3/attachments/att-1/views/original")).toBe(true);
318
- // Verify no pinned undici dispatcher is attached on either request.
319
- for (const call of fetchCalls) {
320
- const init = call.init as RequestInit & { dispatcher?: unknown };
321
- expect(init?.dispatcher).toBeUndefined();
322
- }
323
- });
324
-
325
- it("logs a warning when the attachmentInfo fetch throws (no longer silently swallowed)", async () => {
326
- const warn = vi.fn();
327
- const logger = { warn };
328
- const error = new TypeError("fetch failed | invalid onRequestStart method");
329
- const fetchFn: typeof fetch = (async () => {
330
- throw error;
331
- }) as typeof fetch;
332
-
333
- const media = await downloadMSTeamsBotFrameworkAttachment({
334
- serviceUrl: "https://smba.trafficmanager.net/amer",
335
- attachmentId: "att-1",
336
- tokenProvider: buildTokenProvider(),
337
- maxBytes: 10_000_000,
338
- fetchFn,
339
- resolveFn: resolvePublicHost,
340
- logger,
341
- });
342
-
343
- expect(media).toBeUndefined();
344
- expect(warn).toHaveBeenCalledTimes(1);
345
- expect(firstMockCall(warn, "logger.warn")).toStrictEqual([
346
- "msteams botFramework attachmentInfo fetch failed",
347
- { error: "fetch failed | invalid onRequestStart method" },
348
- ]);
349
- });
350
-
351
- it("logs a warning when the attachmentView fetch throws", async () => {
352
- const warn = vi.fn();
353
- const logger = { warn };
354
- const fetchFn: typeof fetch = (async (input: RequestInfo | URL) => {
355
- const url =
356
- typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
357
- if (url.endsWith("/v3/attachments/att-1")) {
358
- return new Response(
359
- JSON.stringify({
360
- name: "doc.pdf",
361
- type: "application/pdf",
362
- views: [{ viewId: "original", size: 10 }],
363
- }),
364
- { status: 200 },
365
- );
366
- }
367
- throw new TypeError("fetch failed");
368
- }) as typeof fetch;
369
-
370
- const media = await downloadMSTeamsBotFrameworkAttachment({
371
- serviceUrl: "https://smba.trafficmanager.net/amer",
372
- attachmentId: "att-1",
373
- tokenProvider: buildTokenProvider(),
374
- maxBytes: 10_000_000,
375
- fetchFn,
376
- resolveFn: resolvePublicHost,
377
- logger,
378
- });
379
-
380
- expect(media).toBeUndefined();
381
- expect(warn).toHaveBeenCalledTimes(1);
382
- expect(firstMockCall(warn, "logger.warn")).toStrictEqual([
383
- "msteams botFramework attachmentView fetch failed",
384
- { error: "fetch failed" },
385
- ]);
386
- });
387
-
388
- it("logs a warning on non-ok attachmentInfo response", async () => {
389
- const warn = vi.fn();
390
- const fetchFn = createMockFetch([
391
- {
392
- match: /\/v3\/attachments\/att-1$/,
393
- response: new Response("server error", { status: 500 }),
394
- },
395
- ]);
396
-
397
- const media = await downloadMSTeamsBotFrameworkAttachment({
398
- serviceUrl: "https://smba.trafficmanager.net/amer",
399
- attachmentId: "att-1",
400
- tokenProvider: buildTokenProvider(),
401
- maxBytes: 10_000_000,
402
- fetchFn,
403
- resolveFn: resolvePublicHost,
404
- logger: { warn },
405
- });
406
-
407
- expect(media).toBeUndefined();
408
- expect(warn).toHaveBeenCalledTimes(1);
409
- expect(firstMockCall(warn, "logger.warn")).toStrictEqual([
410
- "msteams botFramework attachmentInfo non-ok",
411
- { status: 500 },
412
- ]);
413
- });
414
- });
415
- });
416
-
417
- describe("downloadMSTeamsBotFrameworkAttachments", () => {
418
- beforeEach(() => {
419
- installRuntime();
420
- });
421
-
422
- it("fetches every unique attachment id and returns combined media", async () => {
423
- const mkInfo = (viewId: string) => ({
424
- name: `file-${viewId}.pdf`,
425
- type: "application/pdf",
426
- views: [{ viewId, size: 10 }],
427
- });
428
- const fetchFn = createMockFetch([
429
- {
430
- match: /\/v3\/attachments\/att-1$/,
431
- response: new Response(JSON.stringify(mkInfo("original")), { status: 200 }),
432
- },
433
- {
434
- match: /\/v3\/attachments\/att-1\/views\/original$/,
435
- response: new Response(Buffer.from("A"), { status: 200 }),
436
- },
437
- {
438
- match: /\/v3\/attachments\/att-2$/,
439
- response: new Response(JSON.stringify(mkInfo("original")), { status: 200 }),
440
- },
441
- {
442
- match: /\/v3\/attachments\/att-2\/views\/original$/,
443
- response: new Response(Buffer.from("B"), { status: 200 }),
444
- },
445
- ]);
446
-
447
- const result = await downloadMSTeamsBotFrameworkAttachments({
448
- serviceUrl: "https://smba.trafficmanager.net/amer",
449
- attachmentIds: ["att-1", "att-2", "att-1"],
450
- tokenProvider: buildTokenProvider(),
451
- maxBytes: 10_000,
452
- fetchFn,
453
- resolveFn: resolvePublicHost,
454
- });
455
-
456
- expect(result.media).toHaveLength(2);
457
- expect(result.attachmentCount).toBe(2);
458
- });
459
-
460
- it("returns empty when no valid attachment ids", async () => {
461
- const result = await downloadMSTeamsBotFrameworkAttachments({
462
- serviceUrl: "https://smba.trafficmanager.net/amer",
463
- attachmentIds: [],
464
- tokenProvider: buildTokenProvider(),
465
- maxBytes: 10_000,
466
- fetchFn: vi.fn() as unknown as typeof fetch,
467
- });
468
- expect(result.media).toStrictEqual([]);
469
- });
470
-
471
- it("continues past a per-attachment failure", async () => {
472
- const fetchFn = createMockFetch([
473
- {
474
- match: /\/v3\/attachments\/ok$/,
475
- response: new Response(
476
- JSON.stringify({
477
- name: "ok.pdf",
478
- type: "application/pdf",
479
- views: [{ viewId: "original", size: 1 }],
480
- }),
481
- { status: 200 },
482
- ),
483
- },
484
- {
485
- match: /\/v3\/attachments\/ok\/views\/original$/,
486
- response: new Response(Buffer.from("OK"), { status: 200 }),
487
- },
488
- {
489
- match: /\/v3\/attachments\/bad$/,
490
- response: new Response("nope", { status: 500 }),
491
- },
492
- ]);
493
-
494
- const result = await downloadMSTeamsBotFrameworkAttachments({
495
- serviceUrl: "https://smba.trafficmanager.net/amer",
496
- attachmentIds: ["bad", "ok"],
497
- tokenProvider: buildTokenProvider(),
498
- maxBytes: 10_000,
499
- fetchFn,
500
- resolveFn: resolvePublicHost,
501
- });
502
-
503
- expect(result.media).toHaveLength(1);
504
- expect(result.attachmentCount).toBe(2);
505
- });
506
- });