@openclaw/msteams 2026.5.2-beta.2 → 2026.5.3-beta.1

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 (197) hide show
  1. package/dist/api.js +3 -0
  2. package/dist/channel-D7hdreTh.js +984 -0
  3. package/dist/channel-config-api.js +2 -0
  4. package/dist/channel-plugin-api.js +2 -0
  5. package/dist/channel.runtime-BC1ruIfN.js +573 -0
  6. package/dist/config-schema-B8QezH6t.js +15 -0
  7. package/dist/contract-api.js +2 -0
  8. package/dist/graph-users-9uQJepqr.js +1354 -0
  9. package/dist/index.js +22 -0
  10. package/dist/oauth-BWJyilR1.js +114 -0
  11. package/dist/oauth.token-xxpoLWy5.js +115 -0
  12. package/dist/policy-DTnU2GR7.js +142 -0
  13. package/dist/probe-D_H8yFps.js +2194 -0
  14. package/dist/resolve-allowlist-D41JSziq.js +219 -0
  15. package/dist/runtime-api-DV1iVMn1.js +28 -0
  16. package/dist/runtime-api.js +2 -0
  17. package/dist/secret-contract-BuoEXmPS.js +35 -0
  18. package/dist/secret-contract-api.js +2 -0
  19. package/dist/setup-entry.js +15 -0
  20. package/dist/setup-plugin-api.js +64 -0
  21. package/dist/setup-surface-BLkFQYIQ.js +313 -0
  22. package/dist/src-CFp1QpFd.js +4064 -0
  23. package/dist/test-api.js +2 -0
  24. package/package.json +14 -6
  25. package/api.ts +0 -3
  26. package/channel-config-api.ts +0 -1
  27. package/channel-plugin-api.ts +0 -2
  28. package/config-api.ts +0 -4
  29. package/contract-api.ts +0 -4
  30. package/index.ts +0 -20
  31. package/runtime-api.ts +0 -73
  32. package/secret-contract-api.ts +0 -5
  33. package/setup-entry.ts +0 -13
  34. package/setup-plugin-api.ts +0 -3
  35. package/src/ai-entity.ts +0 -7
  36. package/src/approval-auth.ts +0 -44
  37. package/src/attachments/bot-framework.test.ts +0 -461
  38. package/src/attachments/bot-framework.ts +0 -362
  39. package/src/attachments/download.ts +0 -311
  40. package/src/attachments/graph.test.ts +0 -416
  41. package/src/attachments/graph.ts +0 -484
  42. package/src/attachments/html.ts +0 -122
  43. package/src/attachments/payload.ts +0 -14
  44. package/src/attachments/remote-media.test.ts +0 -137
  45. package/src/attachments/remote-media.ts +0 -112
  46. package/src/attachments/shared.test.ts +0 -530
  47. package/src/attachments/shared.ts +0 -626
  48. package/src/attachments/types.ts +0 -47
  49. package/src/attachments.graph.test.ts +0 -342
  50. package/src/attachments.helpers.test.ts +0 -246
  51. package/src/attachments.test-helpers.ts +0 -17
  52. package/src/attachments.test.ts +0 -687
  53. package/src/attachments.ts +0 -18
  54. package/src/block-streaming-config.test.ts +0 -61
  55. package/src/channel-api.ts +0 -1
  56. package/src/channel.actions.test.ts +0 -742
  57. package/src/channel.directory.test.ts +0 -200
  58. package/src/channel.runtime.ts +0 -56
  59. package/src/channel.setup.ts +0 -77
  60. package/src/channel.test.ts +0 -128
  61. package/src/channel.ts +0 -1136
  62. package/src/config-schema.ts +0 -6
  63. package/src/config-ui-hints.ts +0 -12
  64. package/src/conversation-store-fs.test.ts +0 -74
  65. package/src/conversation-store-fs.ts +0 -149
  66. package/src/conversation-store-helpers.test.ts +0 -202
  67. package/src/conversation-store-helpers.ts +0 -105
  68. package/src/conversation-store-memory.ts +0 -51
  69. package/src/conversation-store.shared.test.ts +0 -225
  70. package/src/conversation-store.ts +0 -71
  71. package/src/directory-live.test.ts +0 -156
  72. package/src/directory-live.ts +0 -111
  73. package/src/doctor.ts +0 -27
  74. package/src/errors.test.ts +0 -133
  75. package/src/errors.ts +0 -246
  76. package/src/feedback-reflection-prompt.ts +0 -117
  77. package/src/feedback-reflection-store.ts +0 -114
  78. package/src/feedback-reflection.test.ts +0 -237
  79. package/src/feedback-reflection.ts +0 -283
  80. package/src/file-consent-helpers.test.ts +0 -326
  81. package/src/file-consent-helpers.ts +0 -126
  82. package/src/file-consent-invoke.ts +0 -150
  83. package/src/file-consent.test.ts +0 -363
  84. package/src/file-consent.ts +0 -287
  85. package/src/graph-chat.ts +0 -55
  86. package/src/graph-group-management.test.ts +0 -318
  87. package/src/graph-group-management.ts +0 -168
  88. package/src/graph-members.test.ts +0 -89
  89. package/src/graph-members.ts +0 -48
  90. package/src/graph-messages.actions.test.ts +0 -243
  91. package/src/graph-messages.read.test.ts +0 -391
  92. package/src/graph-messages.search.test.ts +0 -213
  93. package/src/graph-messages.test-helpers.ts +0 -50
  94. package/src/graph-messages.ts +0 -534
  95. package/src/graph-teams.test.ts +0 -215
  96. package/src/graph-teams.ts +0 -114
  97. package/src/graph-thread.test.ts +0 -246
  98. package/src/graph-thread.ts +0 -146
  99. package/src/graph-upload.test.ts +0 -258
  100. package/src/graph-upload.ts +0 -531
  101. package/src/graph-users.ts +0 -29
  102. package/src/graph.test.ts +0 -516
  103. package/src/graph.ts +0 -293
  104. package/src/inbound.test.ts +0 -221
  105. package/src/inbound.ts +0 -148
  106. package/src/index.ts +0 -4
  107. package/src/media-helpers.test.ts +0 -202
  108. package/src/media-helpers.ts +0 -105
  109. package/src/mentions.test.ts +0 -244
  110. package/src/mentions.ts +0 -114
  111. package/src/messenger.test.ts +0 -865
  112. package/src/messenger.ts +0 -605
  113. package/src/monitor-handler/access.ts +0 -125
  114. package/src/monitor-handler/inbound-media.test.ts +0 -289
  115. package/src/monitor-handler/inbound-media.ts +0 -180
  116. package/src/monitor-handler/message-handler-mock-support.test-support.ts +0 -28
  117. package/src/monitor-handler/message-handler.authz.test.ts +0 -669
  118. package/src/monitor-handler/message-handler.dm-media.test.ts +0 -54
  119. package/src/monitor-handler/message-handler.test-support.ts +0 -100
  120. package/src/monitor-handler/message-handler.thread-parent.test.ts +0 -223
  121. package/src/monitor-handler/message-handler.thread-session.test.ts +0 -77
  122. package/src/monitor-handler/message-handler.ts +0 -1000
  123. package/src/monitor-handler/reaction-handler.test.ts +0 -267
  124. package/src/monitor-handler/reaction-handler.ts +0 -210
  125. package/src/monitor-handler/thread-session.ts +0 -17
  126. package/src/monitor-handler.adaptive-card.test.ts +0 -162
  127. package/src/monitor-handler.feedback-authz.test.ts +0 -314
  128. package/src/monitor-handler.file-consent.test.ts +0 -423
  129. package/src/monitor-handler.sso.test.ts +0 -563
  130. package/src/monitor-handler.test-helpers.ts +0 -180
  131. package/src/monitor-handler.ts +0 -534
  132. package/src/monitor-handler.types.ts +0 -27
  133. package/src/monitor-types.ts +0 -6
  134. package/src/monitor.lifecycle.test.ts +0 -278
  135. package/src/monitor.test.ts +0 -119
  136. package/src/monitor.ts +0 -442
  137. package/src/oauth.flow.ts +0 -77
  138. package/src/oauth.shared.ts +0 -37
  139. package/src/oauth.test.ts +0 -305
  140. package/src/oauth.token.ts +0 -158
  141. package/src/oauth.ts +0 -130
  142. package/src/outbound.test.ts +0 -130
  143. package/src/outbound.ts +0 -71
  144. package/src/pending-uploads-fs.test.ts +0 -246
  145. package/src/pending-uploads-fs.ts +0 -235
  146. package/src/pending-uploads.test.ts +0 -173
  147. package/src/pending-uploads.ts +0 -121
  148. package/src/policy.test.ts +0 -240
  149. package/src/policy.ts +0 -262
  150. package/src/polls-store-memory.ts +0 -32
  151. package/src/polls.test.ts +0 -160
  152. package/src/polls.ts +0 -323
  153. package/src/presentation.ts +0 -68
  154. package/src/probe.test.ts +0 -77
  155. package/src/probe.ts +0 -132
  156. package/src/reply-dispatcher.test.ts +0 -437
  157. package/src/reply-dispatcher.ts +0 -346
  158. package/src/reply-stream-controller.test.ts +0 -235
  159. package/src/reply-stream-controller.ts +0 -147
  160. package/src/resolve-allowlist.test.ts +0 -250
  161. package/src/resolve-allowlist.ts +0 -309
  162. package/src/revoked-context.ts +0 -17
  163. package/src/runtime.ts +0 -9
  164. package/src/sdk-types.ts +0 -59
  165. package/src/sdk.test.ts +0 -666
  166. package/src/sdk.ts +0 -884
  167. package/src/secret-contract.ts +0 -49
  168. package/src/secret-input.ts +0 -7
  169. package/src/send-context.ts +0 -231
  170. package/src/send.test.ts +0 -493
  171. package/src/send.ts +0 -637
  172. package/src/sent-message-cache.test.ts +0 -15
  173. package/src/sent-message-cache.ts +0 -56
  174. package/src/session-route.ts +0 -40
  175. package/src/setup-core.ts +0 -160
  176. package/src/setup-surface.test.ts +0 -202
  177. package/src/setup-surface.ts +0 -320
  178. package/src/sso-token-store.test.ts +0 -72
  179. package/src/sso-token-store.ts +0 -166
  180. package/src/sso.ts +0 -300
  181. package/src/storage.ts +0 -25
  182. package/src/store-fs.ts +0 -44
  183. package/src/streaming-message.test.ts +0 -262
  184. package/src/streaming-message.ts +0 -297
  185. package/src/test-runtime.ts +0 -16
  186. package/src/thread-parent-context.test.ts +0 -224
  187. package/src/thread-parent-context.ts +0 -159
  188. package/src/token-response.ts +0 -11
  189. package/src/token.test.ts +0 -259
  190. package/src/token.ts +0 -195
  191. package/src/user-agent.test.ts +0 -86
  192. package/src/user-agent.ts +0 -53
  193. package/src/webhook-timeouts.ts +0 -27
  194. package/src/welcome-card.test.ts +0 -81
  195. package/src/welcome-card.ts +0 -57
  196. package/test-api.ts +0 -1
  197. package/tsconfig.json +0 -16
@@ -1,146 +0,0 @@
1
- import { fetchGraphJson, type GraphResponse } from "./graph.js";
2
-
3
- export type GraphThreadMessage = {
4
- id?: string;
5
- from?: {
6
- user?: { displayName?: string; id?: string };
7
- application?: { displayName?: string; id?: string };
8
- };
9
- body?: { content?: string; contentType?: string };
10
- createdDateTime?: string;
11
- };
12
-
13
- // TTL cache for team ID -> group GUID mapping.
14
- const teamGroupIdCache = new Map<string, { groupId: string; expiresAt: number }>();
15
- const CACHE_TTL_MS = 10 * 60 * 1000; // 10 minutes
16
-
17
- /**
18
- * Strip HTML tags from Teams message content, preserving @mention display names.
19
- * Teams wraps mentions in <at>Name</at> tags.
20
- */
21
- export function stripHtmlFromTeamsMessage(html: string): string {
22
- // Preserve mention display names by replacing <at>Name</at> with @Name.
23
- let text = html.replace(/<at[^>]*>(.*?)<\/at>/gi, "@$1");
24
- // Strip remaining HTML tags.
25
- text = text.replace(/<[^>]*>/g, " ");
26
- // Decode common HTML entities.
27
- text = text
28
- .replace(/&amp;/g, "&")
29
- .replace(/&lt;/g, "<")
30
- .replace(/&gt;/g, ">")
31
- .replace(/&quot;/g, '"')
32
- .replace(/&#39;/g, "'")
33
- .replace(/&nbsp;/g, " ");
34
- // Normalize whitespace.
35
- return text.replace(/\s+/g, " ").trim();
36
- }
37
-
38
- /**
39
- * Resolve the Azure AD group GUID for a Teams conversation team ID.
40
- * Results are cached with a TTL to avoid repeated Graph API calls.
41
- */
42
- export async function resolveTeamGroupId(
43
- token: string,
44
- conversationTeamId: string,
45
- ): Promise<string> {
46
- const cached = teamGroupIdCache.get(conversationTeamId);
47
- if (cached && cached.expiresAt > Date.now()) {
48
- return cached.groupId;
49
- }
50
-
51
- // The team ID in channelData is typically the group ID itself for standard teams.
52
- // Validate by fetching /teams/{id} and returning the confirmed id.
53
- // Requires Team.ReadBasic.All permission; fall back to raw ID if missing.
54
- try {
55
- const path = `/teams/${encodeURIComponent(conversationTeamId)}?$select=id`;
56
- const team = await fetchGraphJson<{ id?: string }>({ token, path });
57
- const groupId = team.id ?? conversationTeamId;
58
-
59
- // Only cache when the Graph lookup succeeds — caching a fallback raw ID
60
- // can cause silent failures for the entire TTL if the ID is not a valid
61
- // Graph team GUID (e.g. Bot Framework conversation key).
62
- teamGroupIdCache.set(conversationTeamId, {
63
- groupId,
64
- expiresAt: Date.now() + CACHE_TTL_MS,
65
- });
66
-
67
- return groupId;
68
- } catch {
69
- // Fallback to raw team ID without caching so subsequent calls retry the
70
- // Graph lookup instead of using a potentially invalid cached value.
71
- return conversationTeamId;
72
- }
73
- }
74
-
75
- /**
76
- * Fetch a single channel message (the parent/root of a thread).
77
- * Returns undefined on error so callers can degrade gracefully.
78
- */
79
- export async function fetchChannelMessage(
80
- token: string,
81
- groupId: string,
82
- channelId: string,
83
- messageId: string,
84
- ): Promise<GraphThreadMessage | undefined> {
85
- const path = `/teams/${encodeURIComponent(groupId)}/channels/${encodeURIComponent(channelId)}/messages/${encodeURIComponent(messageId)}?$select=id,from,body,createdDateTime`;
86
- try {
87
- return await fetchGraphJson<GraphThreadMessage>({ token, path });
88
- } catch {
89
- return undefined;
90
- }
91
- }
92
-
93
- /**
94
- * Fetch thread replies for a channel message, ordered chronologically.
95
- *
96
- * **Limitation:** The Graph API replies endpoint (`/messages/{id}/replies`) does not
97
- * support `$orderby`, so results are always returned in ascending (oldest-first) order.
98
- * Combined with the `$top` cap of 50, this means only the **oldest 50 replies** are
99
- * returned for long threads — newer replies are silently omitted. There is currently no
100
- * Graph API workaround for this; pagination via `@odata.nextLink` can retrieve more
101
- * replies but still in ascending order only.
102
- */
103
- export async function fetchThreadReplies(
104
- token: string,
105
- groupId: string,
106
- channelId: string,
107
- messageId: string,
108
- limit = 50,
109
- ): Promise<GraphThreadMessage[]> {
110
- const top = Math.min(Math.max(limit, 1), 50);
111
- // NOTE: Graph replies endpoint returns oldest-first and does not support $orderby.
112
- // For threads with >50 replies, only the oldest 50 are returned. The most recent
113
- // replies (often the most relevant context) may be truncated.
114
- const path = `/teams/${encodeURIComponent(groupId)}/channels/${encodeURIComponent(channelId)}/messages/${encodeURIComponent(messageId)}/replies?$top=${top}&$select=id,from,body,createdDateTime`;
115
- const res = await fetchGraphJson<GraphResponse<GraphThreadMessage>>({ token, path });
116
- return res.value ?? [];
117
- }
118
-
119
- /**
120
- * Format thread messages into a context string for the agent.
121
- * Skips the current message (by id) and blank messages.
122
- */
123
- export function formatThreadContext(
124
- messages: GraphThreadMessage[],
125
- currentMessageId?: string,
126
- ): string {
127
- const lines: string[] = [];
128
- for (const msg of messages) {
129
- if (msg.id && msg.id === currentMessageId) {
130
- continue;
131
- } // Skip the triggering message.
132
- const sender = msg.from?.user?.displayName ?? msg.from?.application?.displayName ?? "unknown";
133
- const contentType = msg.body?.contentType ?? "text";
134
- const rawContent = msg.body?.content ?? "";
135
- const content =
136
- contentType === "html" ? stripHtmlFromTeamsMessage(rawContent) : rawContent.trim();
137
- if (!content) {
138
- continue;
139
- }
140
- lines.push(`${sender}: ${content}`);
141
- }
142
- return lines.join("\n");
143
- }
144
-
145
- // Exported for testing only.
146
- export { teamGroupIdCache as _teamGroupIdCacheForTest };
@@ -1,258 +0,0 @@
1
- import { withFetchPreconnect } from "openclaw/plugin-sdk/test-env";
2
- import { describe, expect, it, vi } from "vitest";
3
- import { buildTeamsFileInfoCard } from "./graph-chat.js";
4
- import { resolveGraphChatId, uploadToOneDrive, uploadToSharePoint } from "./graph-upload.js";
5
-
6
- describe("graph upload helpers", () => {
7
- const tokenProvider = {
8
- getAccessToken: vi.fn(async () => "graph-token"),
9
- };
10
-
11
- it("uploads to OneDrive with the personal drive path", async () => {
12
- const fetchFn = vi.fn(
13
- async () =>
14
- new Response(
15
- JSON.stringify({ id: "item-1", webUrl: "https://example.com/1", name: "a.txt" }),
16
- {
17
- status: 200,
18
- headers: { "content-type": "application/json" },
19
- },
20
- ),
21
- );
22
-
23
- const result = await uploadToOneDrive({
24
- buffer: Buffer.from("hello"),
25
- filename: "a.txt",
26
- tokenProvider,
27
- fetchFn: withFetchPreconnect(fetchFn),
28
- });
29
-
30
- expect(fetchFn).toHaveBeenCalledWith(
31
- "https://graph.microsoft.com/v1.0/me/drive/root:/OpenClawShared/a.txt:/content",
32
- expect.objectContaining({
33
- method: "PUT",
34
- headers: expect.objectContaining({
35
- Authorization: "Bearer graph-token",
36
- "Content-Type": "application/octet-stream",
37
- "User-Agent": expect.stringMatching(/^teams\.ts\[apps\]\/.+ OpenClaw\/.+$/),
38
- }),
39
- }),
40
- );
41
- expect(result).toEqual({
42
- id: "item-1",
43
- webUrl: "https://example.com/1",
44
- name: "a.txt",
45
- });
46
- });
47
-
48
- it("uploads to SharePoint with the site drive path", async () => {
49
- const fetchFn = vi.fn(
50
- async () =>
51
- new Response(
52
- JSON.stringify({ id: "item-2", webUrl: "https://example.com/2", name: "b.txt" }),
53
- {
54
- status: 200,
55
- headers: { "content-type": "application/json" },
56
- },
57
- ),
58
- );
59
-
60
- const result = await uploadToSharePoint({
61
- buffer: Buffer.from("world"),
62
- filename: "b.txt",
63
- siteId: "site-123",
64
- tokenProvider,
65
- fetchFn: withFetchPreconnect(fetchFn),
66
- });
67
-
68
- expect(fetchFn).toHaveBeenCalledWith(
69
- "https://graph.microsoft.com/v1.0/sites/site-123/drive/root:/OpenClawShared/b.txt:/content",
70
- expect.objectContaining({
71
- method: "PUT",
72
- headers: expect.objectContaining({
73
- Authorization: "Bearer graph-token",
74
- "Content-Type": "application/octet-stream",
75
- "User-Agent": expect.stringMatching(/^teams\.ts\[apps\]\/.+ OpenClaw\/.+$/),
76
- }),
77
- }),
78
- );
79
- expect(result).toEqual({
80
- id: "item-2",
81
- webUrl: "https://example.com/2",
82
- name: "b.txt",
83
- });
84
- });
85
-
86
- it("rejects upload responses missing required fields", async () => {
87
- const fetchFn = vi.fn(
88
- async () =>
89
- new Response(JSON.stringify({ id: "item-3" }), {
90
- status: 200,
91
- headers: { "content-type": "application/json" },
92
- }),
93
- );
94
-
95
- await expect(
96
- uploadToSharePoint({
97
- buffer: Buffer.from("world"),
98
- filename: "bad.txt",
99
- siteId: "site-123",
100
- tokenProvider,
101
- fetchFn: withFetchPreconnect(fetchFn),
102
- }),
103
- ).rejects.toThrow("SharePoint upload response missing required fields");
104
- });
105
- });
106
-
107
- describe("resolveGraphChatId", () => {
108
- const tokenProvider = {
109
- getAccessToken: vi.fn(async () => "graph-token"),
110
- };
111
-
112
- it("returns the ID directly when it already starts with 19:", async () => {
113
- const fetchFn = vi.fn();
114
- const result = await resolveGraphChatId({
115
- botFrameworkConversationId: "19:abc123@thread.tacv2",
116
- tokenProvider,
117
- fetchFn: withFetchPreconnect(fetchFn),
118
- });
119
- // Should short-circuit without making any API call
120
- expect(fetchFn).not.toHaveBeenCalled();
121
- expect(result).toBe("19:abc123@thread.tacv2");
122
- });
123
-
124
- it("resolves personal DM chat ID via Graph API using user AAD object ID", async () => {
125
- const fetchFn = vi.fn(
126
- async () =>
127
- new Response(JSON.stringify({ value: [{ id: "19:dm-chat-id@unq.gbl.spaces" }] }), {
128
- status: 200,
129
- headers: { "content-type": "application/json" },
130
- }),
131
- );
132
-
133
- const result = await resolveGraphChatId({
134
- botFrameworkConversationId: "a:1abc_bot_framework_dm_id",
135
- userAadObjectId: "user-aad-object-id-123",
136
- tokenProvider,
137
- fetchFn: withFetchPreconnect(fetchFn),
138
- });
139
-
140
- expect(fetchFn).toHaveBeenCalledWith(
141
- expect.stringContaining("/me/chats"),
142
- expect.objectContaining({
143
- headers: expect.objectContaining({
144
- Authorization: "Bearer graph-token",
145
- "User-Agent": expect.stringMatching(/^teams\.ts\[apps\]\/.+ OpenClaw\/.+$/),
146
- }),
147
- }),
148
- );
149
- const firstCall = fetchFn.mock.calls[0];
150
- if (!firstCall) {
151
- throw new Error("expected Graph chat lookup request");
152
- }
153
- const [callUrlRaw] = firstCall as unknown as [string, RequestInit?];
154
- const callUrl = new URL(callUrlRaw);
155
- expect(callUrl.origin).toBe("https://graph.microsoft.com");
156
- expect(callUrl.pathname).toBe("/v1.0/me/chats");
157
- expect(callUrl.searchParams.get("$filter")).toBe(
158
- "chatType eq 'oneOnOne' and members/any(m:m/microsoft.graph.aadUserConversationMember/userId eq 'user-aad-object-id-123')",
159
- );
160
- expect(callUrl.searchParams.get("$select")).toBe("id");
161
- expect(result).toBe("19:dm-chat-id@unq.gbl.spaces");
162
- });
163
-
164
- it("resolves personal DM chat ID without user AAD object ID (lists all 1:1 chats)", async () => {
165
- const fetchFn = vi.fn(
166
- async () =>
167
- new Response(JSON.stringify({ value: [{ id: "19:fallback-chat@unq.gbl.spaces" }] }), {
168
- status: 200,
169
- headers: { "content-type": "application/json" },
170
- }),
171
- );
172
-
173
- const result = await resolveGraphChatId({
174
- botFrameworkConversationId: "8:orgid:user-object-id",
175
- tokenProvider,
176
- fetchFn: withFetchPreconnect(fetchFn),
177
- });
178
-
179
- expect(fetchFn).toHaveBeenCalledOnce();
180
- expect(result).toBe("19:fallback-chat@unq.gbl.spaces");
181
- });
182
-
183
- it("returns null when Graph API returns no chats", async () => {
184
- const fetchFn = vi.fn(
185
- async () =>
186
- new Response(JSON.stringify({ value: [] }), {
187
- status: 200,
188
- headers: { "content-type": "application/json" },
189
- }),
190
- );
191
-
192
- const result = await resolveGraphChatId({
193
- botFrameworkConversationId: "a:1unknown_dm",
194
- userAadObjectId: "some-user",
195
- tokenProvider,
196
- fetchFn: withFetchPreconnect(fetchFn),
197
- });
198
-
199
- expect(result).toBeNull();
200
- });
201
-
202
- it("returns null when Graph API call fails", async () => {
203
- const fetchFn = vi.fn(
204
- async () =>
205
- new Response("Unauthorized", {
206
- status: 401,
207
- headers: { "content-type": "text/plain" },
208
- }),
209
- );
210
-
211
- const result = await resolveGraphChatId({
212
- botFrameworkConversationId: "a:1some_dm_id",
213
- userAadObjectId: "some-user",
214
- tokenProvider,
215
- fetchFn: withFetchPreconnect(fetchFn),
216
- });
217
-
218
- expect(result).toBeNull();
219
- });
220
- });
221
-
222
- describe("buildTeamsFileInfoCard", () => {
223
- it("extracts a unique id from quoted etags and lowercases file extensions", () => {
224
- expect(
225
- buildTeamsFileInfoCard({
226
- eTag: '"{ABC-123},42"',
227
- name: "Quarterly.Report.PDF",
228
- webDavUrl: "https://sharepoint.example.com/file.pdf",
229
- }),
230
- ).toEqual({
231
- contentType: "application/vnd.microsoft.teams.card.file.info",
232
- contentUrl: "https://sharepoint.example.com/file.pdf",
233
- name: "Quarterly.Report.PDF",
234
- content: {
235
- uniqueId: "ABC-123",
236
- fileType: "pdf",
237
- },
238
- });
239
- });
240
-
241
- it("keeps the raw etag when no version suffix exists and handles extensionless files", () => {
242
- expect(
243
- buildTeamsFileInfoCard({
244
- eTag: "plain-etag",
245
- name: "README",
246
- webDavUrl: "https://sharepoint.example.com/readme",
247
- }),
248
- ).toEqual({
249
- contentType: "application/vnd.microsoft.teams.card.file.info",
250
- contentUrl: "https://sharepoint.example.com/readme",
251
- name: "README",
252
- content: {
253
- uniqueId: "plain-etag",
254
- fileType: "",
255
- },
256
- });
257
- });
258
- });