@kodelyth/msteams 2026.5.42 → 2026.6.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 (177) hide show
  1. package/klaw.plugin.json +726 -2
  2. package/package.json +16 -4
  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,332 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
- import type { KlawConfig } from "../runtime-api.js";
3
- import {
4
- addParticipantMSTeams,
5
- removeParticipantMSTeams,
6
- renameGroupMSTeams,
7
- } from "./graph-group-management.js";
8
-
9
- const mockState = vi.hoisted(() => ({
10
- resolveGraphToken: vi.fn(),
11
- fetchGraphJson: vi.fn(),
12
- postGraphJson: vi.fn(),
13
- deleteGraphRequest: vi.fn(),
14
- patchGraphJson: vi.fn(),
15
- findPreferredDmByUserId: vi.fn(),
16
- }));
17
-
18
- vi.mock("./graph.js", async (importOriginal) => {
19
- const actual = await importOriginal<typeof import("./graph.js")>();
20
- return {
21
- ...actual,
22
- resolveGraphToken: mockState.resolveGraphToken,
23
- fetchGraphJson: mockState.fetchGraphJson,
24
- postGraphJson: mockState.postGraphJson,
25
- deleteGraphRequest: mockState.deleteGraphRequest,
26
- patchGraphJson: mockState.patchGraphJson,
27
- };
28
- });
29
-
30
- vi.mock("./conversation-store-fs.js", () => ({
31
- createMSTeamsConversationStoreFs: () => ({
32
- findPreferredDmByUserId: mockState.findPreferredDmByUserId,
33
- }),
34
- }));
35
-
36
- const TOKEN = "test-graph-token";
37
- const CHAT_ID = "19:abc@thread.tacv2";
38
- const CHANNEL_TO = "team-id-1/channel-id-1";
39
-
40
- function postGraphBodyAt(index: number): Record<string, unknown> {
41
- const call = mockState.postGraphJson.mock.calls[index];
42
- if (!call) {
43
- throw new Error(`expected Graph post call ${index}`);
44
- }
45
- const body = call[0]?.body;
46
- if (!body || typeof body !== "object" || Array.isArray(body)) {
47
- throw new Error(`expected Graph post call ${index} body`);
48
- }
49
- return body as Record<string, unknown>;
50
- }
51
-
52
- describe("addParticipantMSTeams", () => {
53
- beforeEach(() => {
54
- vi.clearAllMocks();
55
- mockState.resolveGraphToken.mockResolvedValue(TOKEN);
56
- });
57
-
58
- it("adds member to a chat with default role", async () => {
59
- mockState.postGraphJson.mockResolvedValue({});
60
-
61
- const result = await addParticipantMSTeams({
62
- cfg: {} as KlawConfig,
63
- to: CHAT_ID,
64
- userId: "user-aad-id-1",
65
- });
66
-
67
- expect(result).toEqual({ added: { userId: "user-aad-id-1", chatId: CHAT_ID } });
68
- expect(mockState.postGraphJson).toHaveBeenCalledWith({
69
- token: TOKEN,
70
- path: `/chats/${encodeURIComponent(CHAT_ID)}/members`,
71
- body: {
72
- "@odata.type": "#microsoft.graph.aadUserConversationMember",
73
- roles: ["member"],
74
- "user@odata.bind": "https://graph.microsoft.com/v1.0/users('user-aad-id-1')",
75
- },
76
- });
77
- });
78
-
79
- it("adds member to a chat with owner role", async () => {
80
- mockState.postGraphJson.mockResolvedValue({});
81
-
82
- const result = await addParticipantMSTeams({
83
- cfg: {} as KlawConfig,
84
- to: CHAT_ID,
85
- userId: "user-aad-id-2",
86
- role: "owner",
87
- });
88
-
89
- expect(result).toEqual({ added: { userId: "user-aad-id-2", chatId: CHAT_ID } });
90
- expect(mockState.postGraphJson).toHaveBeenCalledWith({
91
- token: TOKEN,
92
- path: `/chats/${encodeURIComponent(CHAT_ID)}/members`,
93
- body: {
94
- "@odata.type": "#microsoft.graph.aadUserConversationMember",
95
- roles: ["owner"],
96
- "user@odata.bind": "https://graph.microsoft.com/v1.0/users('user-aad-id-2')",
97
- },
98
- });
99
- });
100
-
101
- it("normalizes role casing and whitespace", async () => {
102
- mockState.postGraphJson.mockResolvedValue({});
103
-
104
- await addParticipantMSTeams({
105
- cfg: {} as KlawConfig,
106
- to: CHAT_ID,
107
- userId: "user-aad-id-2",
108
- role: " OWNER ",
109
- });
110
-
111
- expect(mockState.postGraphJson).toHaveBeenCalledWith({
112
- token: TOKEN,
113
- path: `/chats/${encodeURIComponent(CHAT_ID)}/members`,
114
- body: {
115
- "@odata.type": "#microsoft.graph.aadUserConversationMember",
116
- roles: ["owner"],
117
- "user@odata.bind": "https://graph.microsoft.com/v1.0/users('user-aad-id-2')",
118
- },
119
- });
120
- });
121
-
122
- it("rejects unknown roles", async () => {
123
- await expect(
124
- addParticipantMSTeams({
125
- cfg: {} as KlawConfig,
126
- to: CHAT_ID,
127
- userId: "user-aad-id-2",
128
- role: "admin",
129
- }),
130
- ).rejects.toThrow('role must be "member" or "owner"');
131
-
132
- expect(mockState.postGraphJson).not.toHaveBeenCalled();
133
- });
134
-
135
- it("constructs correct user@odata.bind URL", async () => {
136
- mockState.postGraphJson.mockResolvedValue({});
137
-
138
- await addParticipantMSTeams({
139
- cfg: {} as KlawConfig,
140
- to: CHAT_ID,
141
- userId: "abc-def-123",
142
- });
143
-
144
- const calledBody = postGraphBodyAt(0);
145
- expect(calledBody["user@odata.bind"]).toBe(
146
- "https://graph.microsoft.com/v1.0/users('abc-def-123')",
147
- );
148
- });
149
-
150
- it("escapes user ids before building the OData bind URL", async () => {
151
- mockState.postGraphJson.mockResolvedValue({});
152
-
153
- await addParticipantMSTeams({
154
- cfg: {} as KlawConfig,
155
- to: CHAT_ID,
156
- userId: "o'hara@example.com",
157
- });
158
-
159
- const calledBody = postGraphBodyAt(0);
160
- expect(calledBody["user@odata.bind"]).toBe(
161
- "https://graph.microsoft.com/v1.0/users('o''hara@example.com')",
162
- );
163
- });
164
-
165
- it("adds member to a channel", async () => {
166
- mockState.postGraphJson.mockResolvedValue({});
167
-
168
- const result = await addParticipantMSTeams({
169
- cfg: {} as KlawConfig,
170
- to: CHANNEL_TO,
171
- userId: "user-aad-id-3",
172
- });
173
-
174
- expect(result).toEqual({ added: { userId: "user-aad-id-3", chatId: CHANNEL_TO } });
175
- expect(mockState.postGraphJson).toHaveBeenCalledWith({
176
- token: TOKEN,
177
- path: "/teams/team-id-1/channels/channel-id-1/members",
178
- body: {
179
- "@odata.type": "#microsoft.graph.aadUserConversationMember",
180
- roles: ["member"],
181
- "user@odata.bind": "https://graph.microsoft.com/v1.0/users('user-aad-id-3')",
182
- },
183
- });
184
- });
185
- });
186
-
187
- describe("removeParticipantMSTeams", () => {
188
- beforeEach(() => {
189
- vi.clearAllMocks();
190
- mockState.resolveGraphToken.mockResolvedValue(TOKEN);
191
- });
192
-
193
- it("lists members, finds match, deletes by membershipId", async () => {
194
- mockState.fetchGraphJson.mockResolvedValue({
195
- value: [
196
- { id: "membership-1", userId: "user-aad-id-1" },
197
- { id: "membership-2", userId: "user-aad-id-2" },
198
- ],
199
- });
200
- mockState.deleteGraphRequest.mockResolvedValue(undefined);
201
-
202
- const result = await removeParticipantMSTeams({
203
- cfg: {} as KlawConfig,
204
- to: CHAT_ID,
205
- userId: "user-aad-id-2",
206
- });
207
-
208
- expect(result).toEqual({ removed: { userId: "user-aad-id-2", chatId: CHAT_ID } });
209
- expect(mockState.fetchGraphJson).toHaveBeenCalledWith({
210
- token: TOKEN,
211
- path: `/chats/${encodeURIComponent(CHAT_ID)}/members`,
212
- });
213
- expect(mockState.deleteGraphRequest).toHaveBeenCalledWith({
214
- token: TOKEN,
215
- path: `/chats/${encodeURIComponent(CHAT_ID)}/members/membership-2`,
216
- });
217
- });
218
-
219
- it("throws when user not found in member list", async () => {
220
- mockState.fetchGraphJson.mockResolvedValue({
221
- value: [
222
- { id: "membership-1", userId: "user-aad-id-1" },
223
- { id: "membership-3", userId: "user-aad-id-3" },
224
- ],
225
- });
226
-
227
- await expect(
228
- removeParticipantMSTeams({
229
- cfg: {} as KlawConfig,
230
- to: CHAT_ID,
231
- userId: "user-not-in-list",
232
- }),
233
- ).rejects.toThrow("User user-not-in-list is not a member of this conversation");
234
- });
235
-
236
- it("removes member from a channel", async () => {
237
- mockState.fetchGraphJson.mockResolvedValue({
238
- value: [{ id: "membership-5", userId: "user-aad-id-5" }],
239
- });
240
- mockState.deleteGraphRequest.mockResolvedValue(undefined);
241
-
242
- const result = await removeParticipantMSTeams({
243
- cfg: {} as KlawConfig,
244
- to: CHANNEL_TO,
245
- userId: "user-aad-id-5",
246
- });
247
-
248
- expect(result).toEqual({ removed: { userId: "user-aad-id-5", chatId: CHANNEL_TO } });
249
- expect(mockState.fetchGraphJson).toHaveBeenCalledWith({
250
- token: TOKEN,
251
- path: "/teams/team-id-1/channels/channel-id-1/members",
252
- });
253
- expect(mockState.deleteGraphRequest).toHaveBeenCalledWith({
254
- token: TOKEN,
255
- path: "/teams/team-id-1/channels/channel-id-1/members/membership-5",
256
- });
257
- });
258
-
259
- it("follows member pagination before concluding the user is missing", async () => {
260
- mockState.fetchGraphJson
261
- .mockResolvedValueOnce({
262
- value: [{ id: "membership-1", userId: "user-aad-id-1" }],
263
- "@odata.nextLink":
264
- "https://graph.microsoft.com/v1.0/chats/19%3Aabc%40thread.tacv2/members?$skip=2",
265
- })
266
- .mockResolvedValueOnce({
267
- value: [{ id: "membership-9", userId: "user-aad-id-9" }],
268
- });
269
- mockState.deleteGraphRequest.mockResolvedValue(undefined);
270
-
271
- const result = await removeParticipantMSTeams({
272
- cfg: {} as KlawConfig,
273
- to: CHAT_ID,
274
- userId: "user-aad-id-9",
275
- });
276
-
277
- expect(result).toEqual({ removed: { userId: "user-aad-id-9", chatId: CHAT_ID } });
278
- expect(mockState.fetchGraphJson).toHaveBeenNthCalledWith(1, {
279
- token: TOKEN,
280
- path: `/chats/${encodeURIComponent(CHAT_ID)}/members`,
281
- });
282
- expect(mockState.fetchGraphJson).toHaveBeenNthCalledWith(2, {
283
- token: TOKEN,
284
- path: `/chats/${encodeURIComponent(CHAT_ID)}/members?$skip=2`,
285
- });
286
- expect(mockState.deleteGraphRequest).toHaveBeenCalledWith({
287
- token: TOKEN,
288
- path: `/chats/${encodeURIComponent(CHAT_ID)}/members/membership-9`,
289
- });
290
- });
291
- });
292
-
293
- describe("renameGroupMSTeams", () => {
294
- beforeEach(() => {
295
- vi.clearAllMocks();
296
- mockState.resolveGraphToken.mockResolvedValue(TOKEN);
297
- });
298
-
299
- it("renames a chat with topic", async () => {
300
- mockState.patchGraphJson.mockResolvedValue(undefined);
301
-
302
- const result = await renameGroupMSTeams({
303
- cfg: {} as KlawConfig,
304
- to: CHAT_ID,
305
- name: "New Chat Name",
306
- });
307
-
308
- expect(result).toEqual({ renamed: { chatId: CHAT_ID, newName: "New Chat Name" } });
309
- expect(mockState.patchGraphJson).toHaveBeenCalledWith({
310
- token: TOKEN,
311
- path: `/chats/${encodeURIComponent(CHAT_ID)}`,
312
- body: { topic: "New Chat Name" },
313
- });
314
- });
315
-
316
- it("renames a channel with displayName", async () => {
317
- mockState.patchGraphJson.mockResolvedValue(undefined);
318
-
319
- const result = await renameGroupMSTeams({
320
- cfg: {} as KlawConfig,
321
- to: CHANNEL_TO,
322
- name: "New Channel Name",
323
- });
324
-
325
- expect(result).toEqual({ renamed: { chatId: CHANNEL_TO, newName: "New Channel Name" } });
326
- expect(mockState.patchGraphJson).toHaveBeenCalledWith({
327
- token: TOKEN,
328
- path: "/teams/team-id-1/channels/channel-id-1",
329
- body: { displayName: "New Channel Name" },
330
- });
331
- });
332
- });
@@ -1,168 +0,0 @@
1
- import type { KlawConfig } from "../runtime-api.js";
2
- import { resolveConversationPath, resolveGraphConversationId } from "./graph-messages.js";
3
- import {
4
- deleteGraphRequest,
5
- escapeOData,
6
- fetchGraphJson,
7
- patchGraphJson,
8
- postGraphJson,
9
- resolveGraphToken,
10
- } from "./graph.js";
11
-
12
- // ---------------------------------------------------------------------------
13
- // Add Participant
14
- // ---------------------------------------------------------------------------
15
-
16
- type AddParticipantMSTeamsParams = {
17
- cfg: KlawConfig;
18
- to: string;
19
- userId: string;
20
- role?: string;
21
- };
22
-
23
- type AddParticipantMSTeamsResult = {
24
- added: { userId: string; chatId: string };
25
- };
26
-
27
- type ConversationMemberRole = "member" | "owner";
28
-
29
- function normalizeConversationMemberRole(role: string | undefined): ConversationMemberRole {
30
- const normalized = role?.trim().toLowerCase() ?? "";
31
- if (!normalized) {
32
- return "member";
33
- }
34
- if (normalized === "member" || normalized === "owner") {
35
- return normalized;
36
- }
37
- throw new Error('MS Teams participant role must be "member" or "owner".');
38
- }
39
-
40
- /**
41
- * Add a user to a chat or channel via Graph API.
42
- */
43
- export async function addParticipantMSTeams(
44
- params: AddParticipantMSTeamsParams,
45
- ): Promise<AddParticipantMSTeamsResult> {
46
- const token = await resolveGraphToken(params.cfg);
47
- const conversationId = await resolveGraphConversationId(params.to);
48
- const conv = resolveConversationPath(conversationId);
49
-
50
- const body = {
51
- "@odata.type": "#microsoft.graph.aadUserConversationMember",
52
- roles: [normalizeConversationMemberRole(params.role)],
53
- "user@odata.bind": `https://graph.microsoft.com/v1.0/users('${escapeOData(params.userId)}')`,
54
- };
55
-
56
- await postGraphJson<unknown>({
57
- token,
58
- path: `${conv.basePath}/members`,
59
- body,
60
- });
61
-
62
- return { added: { userId: params.userId, chatId: conversationId } };
63
- }
64
-
65
- // ---------------------------------------------------------------------------
66
- // Remove Participant
67
- // ---------------------------------------------------------------------------
68
-
69
- type RemoveParticipantMSTeamsParams = {
70
- cfg: KlawConfig;
71
- to: string;
72
- userId: string;
73
- };
74
-
75
- type RemoveParticipantMSTeamsResult = {
76
- removed: { userId: string; chatId: string };
77
- };
78
-
79
- type GraphConversationMember = {
80
- id?: string;
81
- userId?: string;
82
- };
83
-
84
- type GraphConversationMemberResponse = {
85
- value?: GraphConversationMember[];
86
- "@odata.nextLink"?: string;
87
- };
88
-
89
- /**
90
- * Remove a user from a chat or channel via Graph API.
91
- * Lists members first to resolve the membership ID, then deletes.
92
- */
93
- export async function removeParticipantMSTeams(
94
- params: RemoveParticipantMSTeamsParams,
95
- ): Promise<RemoveParticipantMSTeamsResult> {
96
- const token = await resolveGraphToken(params.cfg);
97
- const conversationId = await resolveGraphConversationId(params.to);
98
- const conv = resolveConversationPath(conversationId);
99
-
100
- // List members to find the membership ID for the target user. Graph can
101
- // paginate large chats/channels, so walk `@odata.nextLink` before concluding
102
- // the user is missing.
103
- const MAX_PAGES = 10;
104
- let nextPath: string | undefined = `${conv.basePath}/members`;
105
- let page = 0;
106
- let member: GraphConversationMember | undefined;
107
- while (nextPath && page < MAX_PAGES && !member) {
108
- const membersRes: GraphConversationMemberResponse =
109
- await fetchGraphJson<GraphConversationMemberResponse>({
110
- token,
111
- path: nextPath,
112
- });
113
- member = (membersRes.value ?? []).find(
114
- (candidate: GraphConversationMember) => candidate.userId === params.userId,
115
- );
116
- if (member) {
117
- break;
118
- }
119
- const nextLink: string | undefined = membersRes["@odata.nextLink"];
120
- nextPath = nextLink ? nextLink.replace("https://graph.microsoft.com/v1.0", "") : undefined;
121
- page++;
122
- }
123
- if (!member?.id) {
124
- throw new Error(`User ${params.userId} is not a member of this conversation`);
125
- }
126
-
127
- await deleteGraphRequest({
128
- token,
129
- path: `${conv.basePath}/members/${encodeURIComponent(member.id)}`,
130
- });
131
-
132
- return { removed: { userId: params.userId, chatId: conversationId } };
133
- }
134
-
135
- // ---------------------------------------------------------------------------
136
- // Rename Group
137
- // ---------------------------------------------------------------------------
138
-
139
- type RenameGroupMSTeamsParams = {
140
- cfg: KlawConfig;
141
- to: string;
142
- name: string;
143
- };
144
-
145
- type RenameGroupMSTeamsResult = {
146
- renamed: { chatId: string; newName: string };
147
- };
148
-
149
- /**
150
- * Rename a chat (topic) or channel (displayName) via Graph API.
151
- */
152
- export async function renameGroupMSTeams(
153
- params: RenameGroupMSTeamsParams,
154
- ): Promise<RenameGroupMSTeamsResult> {
155
- const token = await resolveGraphToken(params.cfg);
156
- const conversationId = await resolveGraphConversationId(params.to);
157
- const conv = resolveConversationPath(conversationId);
158
-
159
- const body = conv.kind === "chat" ? { topic: params.name } : { displayName: params.name };
160
-
161
- await patchGraphJson<unknown>({
162
- token,
163
- path: conv.basePath,
164
- body,
165
- });
166
-
167
- return { renamed: { chatId: conversationId, newName: params.name } };
168
- }
@@ -1,89 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
- import type { KlawConfig } from "../runtime-api.js";
3
- import { getMemberInfoMSTeams } from "./graph-members.js";
4
-
5
- const mockState = vi.hoisted(() => ({
6
- resolveGraphToken: vi.fn(),
7
- fetchGraphJson: vi.fn(),
8
- }));
9
-
10
- vi.mock("./graph.js", () => {
11
- return {
12
- resolveGraphToken: mockState.resolveGraphToken,
13
- fetchGraphJson: mockState.fetchGraphJson,
14
- };
15
- });
16
-
17
- const TOKEN = "test-graph-token";
18
-
19
- describe("getMemberInfoMSTeams", () => {
20
- beforeEach(() => {
21
- vi.clearAllMocks();
22
- mockState.resolveGraphToken.mockResolvedValue(TOKEN);
23
- });
24
-
25
- it("fetches user profile and maps all fields", async () => {
26
- mockState.fetchGraphJson.mockResolvedValue({
27
- id: "user-123",
28
- displayName: "Alice Smith",
29
- mail: "alice@contoso.com",
30
- jobTitle: "Engineer",
31
- userPrincipalName: "alice@contoso.com",
32
- officeLocation: "Building 1",
33
- });
34
-
35
- const result = await getMemberInfoMSTeams({
36
- cfg: {} as KlawConfig,
37
- userId: "user-123",
38
- });
39
-
40
- expect(result).toEqual({
41
- user: {
42
- id: "user-123",
43
- displayName: "Alice Smith",
44
- mail: "alice@contoso.com",
45
- jobTitle: "Engineer",
46
- userPrincipalName: "alice@contoso.com",
47
- officeLocation: "Building 1",
48
- },
49
- });
50
- expect(mockState.fetchGraphJson).toHaveBeenCalledWith({
51
- token: TOKEN,
52
- path: `/users/${encodeURIComponent("user-123")}?$select=id,displayName,mail,jobTitle,userPrincipalName,officeLocation`,
53
- });
54
- });
55
-
56
- it("handles sparse data with some fields undefined", async () => {
57
- mockState.fetchGraphJson.mockResolvedValue({
58
- id: "user-456",
59
- displayName: "Bob",
60
- });
61
-
62
- const result = await getMemberInfoMSTeams({
63
- cfg: {} as KlawConfig,
64
- userId: "user-456",
65
- });
66
-
67
- expect(result).toEqual({
68
- user: {
69
- id: "user-456",
70
- displayName: "Bob",
71
- mail: undefined,
72
- jobTitle: undefined,
73
- userPrincipalName: undefined,
74
- officeLocation: undefined,
75
- },
76
- });
77
- });
78
-
79
- it("propagates Graph API errors", async () => {
80
- mockState.fetchGraphJson.mockRejectedValue(new Error("Graph API 404: user not found"));
81
-
82
- await expect(
83
- getMemberInfoMSTeams({
84
- cfg: {} as KlawConfig,
85
- userId: "nonexistent-user",
86
- }),
87
- ).rejects.toThrow("Graph API 404: user not found");
88
- });
89
- });
@@ -1,48 +0,0 @@
1
- import type { KlawConfig } from "../runtime-api.js";
2
- import { fetchGraphJson, resolveGraphToken } from "./graph.js";
3
-
4
- type GraphUserProfile = {
5
- id?: string;
6
- displayName?: string;
7
- mail?: string;
8
- jobTitle?: string;
9
- userPrincipalName?: string;
10
- officeLocation?: string;
11
- };
12
-
13
- type GetMemberInfoMSTeamsParams = {
14
- cfg: KlawConfig;
15
- userId: string;
16
- };
17
-
18
- type GetMemberInfoMSTeamsResult = {
19
- user: {
20
- id: string | undefined;
21
- displayName: string | undefined;
22
- mail: string | undefined;
23
- jobTitle: string | undefined;
24
- userPrincipalName: string | undefined;
25
- officeLocation: string | undefined;
26
- };
27
- };
28
-
29
- /**
30
- * Fetch a user profile from Microsoft Graph by user ID.
31
- */
32
- export async function getMemberInfoMSTeams(
33
- params: GetMemberInfoMSTeamsParams,
34
- ): Promise<GetMemberInfoMSTeamsResult> {
35
- const token = await resolveGraphToken(params.cfg);
36
- const path = `/users/${encodeURIComponent(params.userId)}?$select=id,displayName,mail,jobTitle,userPrincipalName,officeLocation`;
37
- const user = await fetchGraphJson<GraphUserProfile>({ token, path });
38
- return {
39
- user: {
40
- id: user.id,
41
- displayName: user.displayName,
42
- mail: user.mail,
43
- jobTitle: user.jobTitle,
44
- userPrincipalName: user.userPrincipalName,
45
- officeLocation: user.officeLocation,
46
- },
47
- };
48
- }