@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,260 +0,0 @@
1
- import fs from "node:fs";
2
- import os from "node:os";
3
- import path from "node:path";
4
- import { beforeEach, describe, expect, it, vi } from "vitest";
5
- import { createMSTeamsConversationStoreFs } from "./conversation-store-fs.js";
6
- import { createMSTeamsConversationStoreMemory } from "./conversation-store-memory.js";
7
- import type { MSTeamsConversationStore } from "./conversation-store.js";
8
- import { setMSTeamsRuntime } from "./runtime.js";
9
- import { msteamsRuntimeStub } from "./test-runtime.js";
10
-
11
- type StoreFactory = {
12
- name: string;
13
- createStore: () => Promise<MSTeamsConversationStore>;
14
- };
15
-
16
- const storeFactories: StoreFactory[] = [
17
- {
18
- name: "fs",
19
- createStore: async () => {
20
- const stateDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "klaw-msteams-store-"));
21
- return createMSTeamsConversationStoreFs({
22
- env: { ...process.env, KLAW_STATE_DIR: stateDir },
23
- ttlMs: 60_000,
24
- });
25
- },
26
- },
27
- {
28
- name: "memory",
29
- createStore: async () => createMSTeamsConversationStoreMemory(),
30
- },
31
- ];
32
-
33
- describe.each(storeFactories)("msteams conversation store ($name)", ({ createStore }) => {
34
- beforeEach(() => {
35
- setMSTeamsRuntime(msteamsRuntimeStub);
36
- });
37
-
38
- it("normalizes conversation ids consistently", async () => {
39
- const store = await createStore();
40
-
41
- await store.upsert("conv-norm;messageid=123", {
42
- conversation: { id: "conv-norm" },
43
- channelId: "msteams",
44
- serviceUrl: "https://service.example.com",
45
- user: { id: "u1" },
46
- });
47
-
48
- const normalized = await store.get("conv-norm");
49
- expect(normalized).toEqual({
50
- conversation: { id: "conv-norm" },
51
- channelId: "msteams",
52
- serviceUrl: "https://service.example.com",
53
- user: { id: "u1" },
54
- lastSeenAt: normalized?.lastSeenAt,
55
- });
56
- expect(typeof normalized?.lastSeenAt).toBe("string");
57
- await expect(store.remove("conv-norm")).resolves.toBe(true);
58
- await expect(store.get("conv-norm;messageid=123")).resolves.toBeNull();
59
- });
60
-
61
- it("upserts, lists, removes, and resolves users by both AAD and Bot Framework ids", async () => {
62
- const store = await createStore();
63
-
64
- vi.useFakeTimers();
65
- try {
66
- vi.setSystemTime(new Date("2026-03-25T20:00:00.000Z"));
67
- await store.upsert("conv-a", {
68
- conversation: { id: "conv-a" },
69
- channelId: "msteams",
70
- serviceUrl: "https://service.example.com",
71
- user: { id: "user-a", aadObjectId: "aad-a", name: "Alice" },
72
- });
73
-
74
- vi.setSystemTime(new Date("2026-03-25T20:00:30.000Z"));
75
- await store.upsert("conv-b", {
76
- conversation: { id: "conv-b" },
77
- channelId: "msteams",
78
- serviceUrl: "https://service.example.com",
79
- user: { id: "user-b", aadObjectId: "aad-b", name: "Bob" },
80
- });
81
-
82
- await expect(store.get("conv-a")).resolves.toEqual({
83
- conversation: { id: "conv-a" },
84
- channelId: "msteams",
85
- serviceUrl: "https://service.example.com",
86
- user: { id: "user-a", aadObjectId: "aad-a", name: "Alice" },
87
- lastSeenAt: "2026-03-25T20:00:00.000Z",
88
- });
89
-
90
- await expect(store.list()).resolves.toEqual([
91
- {
92
- conversationId: "conv-a",
93
- reference: {
94
- conversation: { id: "conv-a" },
95
- channelId: "msteams",
96
- serviceUrl: "https://service.example.com",
97
- user: { id: "user-a", aadObjectId: "aad-a", name: "Alice" },
98
- lastSeenAt: "2026-03-25T20:00:00.000Z",
99
- },
100
- },
101
- {
102
- conversationId: "conv-b",
103
- reference: {
104
- conversation: { id: "conv-b" },
105
- channelId: "msteams",
106
- serviceUrl: "https://service.example.com",
107
- user: { id: "user-b", aadObjectId: "aad-b", name: "Bob" },
108
- lastSeenAt: "2026-03-25T20:00:30.000Z",
109
- },
110
- },
111
- ]);
112
-
113
- await expect(store.findPreferredDmByUserId(" aad-b ")).resolves.toEqual({
114
- conversationId: "conv-b",
115
- reference: {
116
- conversation: { id: "conv-b" },
117
- channelId: "msteams",
118
- serviceUrl: "https://service.example.com",
119
- user: { id: "user-b", aadObjectId: "aad-b", name: "Bob" },
120
- lastSeenAt: "2026-03-25T20:00:30.000Z",
121
- },
122
- });
123
- await expect(store.findPreferredDmByUserId("user-a")).resolves.toEqual({
124
- conversationId: "conv-a",
125
- reference: {
126
- conversation: { id: "conv-a" },
127
- channelId: "msteams",
128
- serviceUrl: "https://service.example.com",
129
- user: { id: "user-a", aadObjectId: "aad-a", name: "Alice" },
130
- lastSeenAt: "2026-03-25T20:00:00.000Z",
131
- },
132
- });
133
- await expect(store.findByUserId("user-a")).resolves.toEqual(
134
- await store.findPreferredDmByUserId("user-a"),
135
- );
136
- await expect(store.findPreferredDmByUserId(" ")).resolves.toBeNull();
137
-
138
- await expect(store.remove("conv-a")).resolves.toBe(true);
139
- await expect(store.get("conv-a")).resolves.toBeNull();
140
- await expect(store.remove("missing")).resolves.toBe(false);
141
- } finally {
142
- vi.useRealTimers();
143
- }
144
- });
145
-
146
- it("preserves existing timezone when upsert omits timezone", async () => {
147
- const store = await createStore();
148
-
149
- vi.useFakeTimers();
150
- try {
151
- vi.setSystemTime(new Date("2026-03-25T20:00:00.000Z"));
152
- await store.upsert("conv-tz", {
153
- conversation: { id: "conv-tz" },
154
- channelId: "msteams",
155
- serviceUrl: "https://service.example.com",
156
- user: { id: "u1" },
157
- timezone: "Europe/London",
158
- });
159
-
160
- vi.setSystemTime(new Date("2026-03-25T20:01:00.000Z"));
161
- await store.upsert("conv-tz", {
162
- conversation: { id: "conv-tz" },
163
- channelId: "msteams",
164
- serviceUrl: "https://service.example.com",
165
- user: { id: "u1" },
166
- });
167
-
168
- await expect(store.get("conv-tz")).resolves.toEqual({
169
- conversation: { id: "conv-tz" },
170
- channelId: "msteams",
171
- serviceUrl: "https://service.example.com",
172
- user: { id: "u1" },
173
- timezone: "Europe/London",
174
- lastSeenAt: "2026-03-25T20:01:00.000Z",
175
- });
176
- } finally {
177
- vi.useRealTimers();
178
- }
179
- });
180
-
181
- it("preserves graphChatId across upserts that omit it", async () => {
182
- const store = await createStore();
183
-
184
- vi.useFakeTimers();
185
- try {
186
- vi.setSystemTime(new Date("2026-03-25T20:00:00.000Z"));
187
- await store.upsert("conv-graph", {
188
- conversation: { id: "conv-graph", conversationType: "personal" },
189
- channelId: "msteams",
190
- serviceUrl: "https://service.example.com",
191
- user: { id: "u1" },
192
- graphChatId: "19:resolved-chat-id@unq.gbl.spaces",
193
- });
194
-
195
- vi.setSystemTime(new Date("2026-03-25T20:01:00.000Z"));
196
- // Second upsert without graphChatId (normal activity-based upsert)
197
- await store.upsert("conv-graph", {
198
- conversation: { id: "conv-graph", conversationType: "personal" },
199
- channelId: "msteams",
200
- serviceUrl: "https://service.example.com",
201
- user: { id: "u1" },
202
- });
203
-
204
- await expect(store.get("conv-graph")).resolves.toEqual({
205
- conversation: { id: "conv-graph", conversationType: "personal" },
206
- channelId: "msteams",
207
- serviceUrl: "https://service.example.com",
208
- user: { id: "u1" },
209
- graphChatId: "19:resolved-chat-id@unq.gbl.spaces",
210
- lastSeenAt: "2026-03-25T20:01:00.000Z",
211
- });
212
- } finally {
213
- vi.useRealTimers();
214
- }
215
- });
216
-
217
- it("prefers the freshest personal conversation for repeated upserts of the same user", async () => {
218
- const store = await createStore();
219
-
220
- vi.useFakeTimers();
221
- try {
222
- vi.setSystemTime(new Date("2026-03-25T20:00:00.000Z"));
223
- await store.upsert("dm-old", {
224
- conversation: { id: "dm-old", conversationType: "personal" },
225
- channelId: "msteams",
226
- serviceUrl: "https://service.example.com",
227
- user: { id: "user-shared-old", aadObjectId: "aad-shared", name: "Old DM" },
228
- });
229
-
230
- vi.setSystemTime(new Date("2026-03-25T20:30:00.000Z"));
231
- await store.upsert("group-shared", {
232
- conversation: { id: "group-shared", conversationType: "groupChat" },
233
- channelId: "msteams",
234
- serviceUrl: "https://service.example.com",
235
- user: { id: "user-shared-group", aadObjectId: "aad-shared", name: "Group" },
236
- });
237
-
238
- vi.setSystemTime(new Date("2026-03-25T21:00:00.000Z"));
239
- await store.upsert("dm-new", {
240
- conversation: { id: "dm-new", conversationType: "personal" },
241
- channelId: "msteams",
242
- serviceUrl: "https://service.example.com",
243
- user: { id: "user-shared-new", aadObjectId: "aad-shared", name: "New DM" },
244
- });
245
-
246
- await expect(store.findPreferredDmByUserId("aad-shared")).resolves.toEqual({
247
- conversationId: "dm-new",
248
- reference: {
249
- conversation: { id: "dm-new", conversationType: "personal" },
250
- channelId: "msteams",
251
- serviceUrl: "https://service.example.com",
252
- user: { id: "user-shared-new", aadObjectId: "aad-shared", name: "New DM" },
253
- lastSeenAt: "2026-03-25T21:00:00.000Z",
254
- },
255
- });
256
- } finally {
257
- vi.useRealTimers();
258
- }
259
- });
260
- });
@@ -1,71 +0,0 @@
1
- /**
2
- * Conversation store for MS Teams proactive messaging.
3
- *
4
- * Stores ConversationReference-like objects keyed by conversation ID so we can
5
- * send proactive messages later (after the webhook turn has completed).
6
- */
7
-
8
- /** Minimal ConversationReference shape for proactive messaging */
9
- export type StoredConversationReference = {
10
- /** Timestamp when this reference was last seen/updated. */
11
- lastSeenAt?: string;
12
- /** Activity ID from the last message */
13
- activityId?: string;
14
- /** Channel thread root activity ID for threaded replies. */
15
- threadId?: string;
16
- /** User who sent the message */
17
- user?: { id?: string; name?: string; aadObjectId?: string };
18
- /** Agent/bot that received the message */
19
- agent?: { id?: string; name?: string; aadObjectId?: string } | null;
20
- /** @deprecated legacy field (pre-Agents SDK). Prefer `agent`. */
21
- bot?: { id?: string; name?: string };
22
- /** Conversation details */
23
- conversation?: { id?: string; conversationType?: string; tenantId?: string };
24
- /**
25
- * Tenant ID sourced from `activity.channelData.tenant.id` at inbound time.
26
- * Bot Framework requires this on outbound proactive messages so the connector
27
- * can route them to the correct Azure AD tenant; without it, the connector
28
- * rejects the request with HTTP 403. For channel activities, `conversation.tenantId`
29
- * is often unset, making `channelData.tenant.id` the reliable source.
30
- */
31
- tenantId?: string;
32
- /**
33
- * Azure AD object ID of the user who sent the last inbound activity,
34
- * mirrored from `activity.from.aadObjectId` so outbound proactive sends
35
- * can include it on the connector request (required for personal DMs).
36
- */
37
- aadObjectId?: string;
38
- /** Team ID for channel messages (when available). */
39
- teamId?: string;
40
- /** Channel ID (usually "msteams") */
41
- channelId?: string;
42
- /** Service URL for sending messages back */
43
- serviceUrl?: string;
44
- /** Locale */
45
- locale?: string;
46
- /**
47
- * Cached Graph API chat ID (format: `19:xxx@thread.tacv2` or `19:xxx@unq.gbl.spaces`).
48
- * Bot Framework conversation IDs for personal DMs use a different format (`a:1xxx` or
49
- * `8:orgid:xxx`) that the Graph API does not accept. This field caches the resolved
50
- * Graph-native chat ID so we don't need to re-query the API on every send.
51
- */
52
- graphChatId?: string;
53
- /** IANA timezone from Teams clientInfo entity (e.g. "America/New_York") */
54
- timezone?: string;
55
- };
56
-
57
- export type MSTeamsConversationStoreEntry = {
58
- conversationId: string;
59
- reference: StoredConversationReference;
60
- };
61
-
62
- export type MSTeamsConversationStore = {
63
- upsert: (conversationId: string, reference: StoredConversationReference) => Promise<void>;
64
- get: (conversationId: string) => Promise<StoredConversationReference | null>;
65
- list: () => Promise<MSTeamsConversationStoreEntry[]>;
66
- remove: (conversationId: string) => Promise<boolean>;
67
- /** Person-targeted proactive lookup: prefer the freshest personal DM reference. */
68
- findPreferredDmByUserId: (id: string) => Promise<MSTeamsConversationStoreEntry | null>;
69
- /** @deprecated Use `findPreferredDmByUserId` for proactive user-targeted sends. */
70
- findByUserId: (id: string) => Promise<MSTeamsConversationStoreEntry | null>;
71
- };
@@ -1,156 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
-
3
- const {
4
- searchGraphUsersMock,
5
- listTeamsByNameMock,
6
- listChannelsForTeamMock,
7
- normalizeQueryMock,
8
- resolveGraphTokenMock,
9
- } = vi.hoisted(() => {
10
- return {
11
- searchGraphUsersMock: vi.fn(),
12
- listTeamsByNameMock: vi.fn(),
13
- listChannelsForTeamMock: vi.fn(),
14
- normalizeQueryMock: vi.fn((value?: string | null) => value?.trim() ?? ""),
15
- resolveGraphTokenMock: vi.fn(),
16
- };
17
- });
18
-
19
- vi.mock("./graph-users.js", () => {
20
- return { searchGraphUsers: searchGraphUsersMock };
21
- });
22
-
23
- vi.mock("./graph.js", () => {
24
- return {
25
- listTeamsByName: listTeamsByNameMock,
26
- listChannelsForTeam: listChannelsForTeamMock,
27
- normalizeQuery: normalizeQueryMock,
28
- resolveGraphToken: resolveGraphTokenMock,
29
- };
30
- });
31
-
32
- import { listMSTeamsDirectoryGroupsLive, listMSTeamsDirectoryPeersLive } from "./directory-live.js";
33
-
34
- describe("msteams directory live", () => {
35
- beforeEach(() => {
36
- vi.clearAllMocks();
37
- normalizeQueryMock.mockImplementation((value?: string | null) => value?.trim() ?? "");
38
- });
39
-
40
- it("returns normalized peer entries and skips users without ids", async () => {
41
- resolveGraphTokenMock.mockResolvedValue("graph-token");
42
- searchGraphUsersMock.mockResolvedValue([
43
- {
44
- id: "user-1",
45
- displayName: "Alice",
46
- userPrincipalName: "alice@example.com",
47
- },
48
- {
49
- id: "user-2",
50
- displayName: "Bob",
51
- mail: "bob@example.com",
52
- },
53
- {
54
- displayName: "Missing Id",
55
- },
56
- ]);
57
-
58
- await expect(
59
- listMSTeamsDirectoryPeersLive({
60
- cfg: {},
61
- query: " ali ",
62
- }),
63
- ).resolves.toEqual([
64
- {
65
- kind: "user",
66
- id: "user:user-1",
67
- name: "Alice",
68
- handle: "@alice@example.com",
69
- raw: {
70
- id: "user-1",
71
- displayName: "Alice",
72
- userPrincipalName: "alice@example.com",
73
- },
74
- },
75
- {
76
- kind: "user",
77
- id: "user:user-2",
78
- name: "Bob",
79
- handle: "@bob@example.com",
80
- raw: {
81
- id: "user-2",
82
- displayName: "Bob",
83
- mail: "bob@example.com",
84
- },
85
- },
86
- ]);
87
-
88
- expect(searchGraphUsersMock).toHaveBeenCalledWith({
89
- token: "graph-token",
90
- query: "ali",
91
- top: 20,
92
- });
93
- });
94
-
95
- it("returns team entries without channel queries and honors limits", async () => {
96
- resolveGraphTokenMock.mockResolvedValue("graph-token");
97
- listTeamsByNameMock.mockResolvedValue([
98
- { id: "team-1", displayName: "Platform" },
99
- { id: "team-2", displayName: "Infra" },
100
- ]);
101
-
102
- await expect(
103
- listMSTeamsDirectoryGroupsLive({
104
- cfg: {},
105
- query: "platform",
106
- limit: 1,
107
- }),
108
- ).resolves.toEqual([
109
- {
110
- kind: "group",
111
- id: "team:team-1",
112
- name: "Platform",
113
- handle: "#Platform",
114
- raw: { id: "team-1", displayName: "Platform" },
115
- },
116
- ]);
117
- });
118
-
119
- it("searches channels within matching teams when a team/channel query is used", async () => {
120
- resolveGraphTokenMock.mockResolvedValue("graph-token");
121
- listTeamsByNameMock.mockResolvedValue([
122
- { id: "team-1", displayName: "Platform" },
123
- { id: "team-2", displayName: "Infra" },
124
- ]);
125
- listChannelsForTeamMock
126
- .mockResolvedValueOnce([
127
- { id: "chan-1", displayName: "Deployments" },
128
- { id: "chan-2", displayName: "General" },
129
- ])
130
- .mockResolvedValueOnce([{ id: "chan-3", displayName: "Deployments-West" }]);
131
-
132
- await expect(
133
- listMSTeamsDirectoryGroupsLive({
134
- cfg: {},
135
- query: "plat / deploy",
136
- }),
137
- ).resolves.toEqual([
138
- {
139
- kind: "group",
140
- id: "conversation:chan-1",
141
- name: "Platform/Deployments",
142
- handle: "#Deployments",
143
- raw: { id: "chan-1", displayName: "Deployments" },
144
- },
145
- {
146
- kind: "group",
147
- id: "conversation:chan-3",
148
- name: "Infra/Deployments-West",
149
- handle: "#Deployments-West",
150
- raw: { id: "chan-3", displayName: "Deployments-West" },
151
- },
152
- ]);
153
-
154
- expect(listTeamsByNameMock).toHaveBeenCalledWith("graph-token", "plat");
155
- });
156
- });
@@ -1,111 +0,0 @@
1
- import { normalizeLowercaseStringOrEmpty } from "klaw/plugin-sdk/string-coerce-runtime";
2
- import type { ChannelDirectoryEntry } from "../runtime-api.js";
3
- import { searchGraphUsers } from "./graph-users.js";
4
- import {
5
- listChannelsForTeam,
6
- listTeamsByName,
7
- normalizeQuery,
8
- resolveGraphToken,
9
- } from "./graph.js";
10
-
11
- export async function listMSTeamsDirectoryPeersLive(params: {
12
- cfg: unknown;
13
- query?: string | null;
14
- limit?: number | null;
15
- }): Promise<ChannelDirectoryEntry[]> {
16
- const query = normalizeQuery(params.query);
17
- if (!query) {
18
- return [];
19
- }
20
- const token = await resolveGraphToken(params.cfg);
21
- const limit = typeof params.limit === "number" && params.limit > 0 ? params.limit : 20;
22
-
23
- const users = await searchGraphUsers({ token, query, top: limit });
24
-
25
- return users
26
- .map((user) => {
27
- const id = user.id?.trim();
28
- if (!id) {
29
- return null;
30
- }
31
- const name = user.displayName?.trim();
32
- const handle = user.userPrincipalName?.trim() || user.mail?.trim();
33
- return {
34
- kind: "user",
35
- id: `user:${id}`,
36
- name: name || undefined,
37
- handle: handle ? `@${handle}` : undefined,
38
- raw: user,
39
- } satisfies ChannelDirectoryEntry;
40
- })
41
- .filter(Boolean) as ChannelDirectoryEntry[];
42
- }
43
-
44
- export async function listMSTeamsDirectoryGroupsLive(params: {
45
- cfg: unknown;
46
- query?: string | null;
47
- limit?: number | null;
48
- }): Promise<ChannelDirectoryEntry[]> {
49
- const rawQuery = normalizeQuery(params.query);
50
- if (!rawQuery) {
51
- return [];
52
- }
53
- const token = await resolveGraphToken(params.cfg);
54
- const limit = typeof params.limit === "number" && params.limit > 0 ? params.limit : 20;
55
- const [teamQuery, channelQuery] = rawQuery.includes("/")
56
- ? rawQuery
57
- .split("/", 2)
58
- .map((part) => part.trim())
59
- .filter(Boolean)
60
- : [rawQuery, null];
61
-
62
- const teams = await listTeamsByName(token, teamQuery);
63
- const results: ChannelDirectoryEntry[] = [];
64
-
65
- for (const team of teams) {
66
- const teamId = team.id?.trim();
67
- if (!teamId) {
68
- continue;
69
- }
70
- const teamName = team.displayName?.trim() || teamQuery;
71
- if (!channelQuery) {
72
- results.push({
73
- kind: "group",
74
- id: `team:${teamId}`,
75
- name: teamName,
76
- handle: teamName ? `#${teamName}` : undefined,
77
- raw: team,
78
- });
79
- if (results.length >= limit) {
80
- return results;
81
- }
82
- continue;
83
- }
84
- const channels = await listChannelsForTeam(token, teamId);
85
- for (const channel of channels) {
86
- const name = channel.displayName?.trim();
87
- if (!name) {
88
- continue;
89
- }
90
- if (
91
- !normalizeLowercaseStringOrEmpty(name).includes(
92
- normalizeLowercaseStringOrEmpty(channelQuery),
93
- )
94
- ) {
95
- continue;
96
- }
97
- results.push({
98
- kind: "group",
99
- id: `conversation:${channel.id}`,
100
- name: `${teamName}/${name}`,
101
- handle: `#${name}`,
102
- raw: channel,
103
- });
104
- if (results.length >= limit) {
105
- return results;
106
- }
107
- }
108
- }
109
-
110
- return results;
111
- }
package/src/doctor.ts DELETED
@@ -1,27 +0,0 @@
1
- import { createDangerousNameMatchingMutableAllowlistWarningCollector } from "klaw/plugin-sdk/channel-policy";
2
-
3
- function isMSTeamsMutableAllowEntry(raw: string): boolean {
4
- const text = raw.trim();
5
- if (!text || text === "*") {
6
- return false;
7
- }
8
-
9
- const withoutPrefix = text.replace(/^(msteams|user):/i, "").trim();
10
- return /\s/.test(withoutPrefix) || withoutPrefix.includes("@");
11
- }
12
-
13
- export const collectMSTeamsMutableAllowlistWarnings =
14
- createDangerousNameMatchingMutableAllowlistWarningCollector({
15
- channel: "msteams",
16
- detector: isMSTeamsMutableAllowEntry,
17
- collectLists: (scope) => [
18
- {
19
- pathLabel: `${scope.prefix}.allowFrom`,
20
- list: scope.account.allowFrom,
21
- },
22
- {
23
- pathLabel: `${scope.prefix}.groupAllowFrom`,
24
- list: scope.account.groupAllowFrom,
25
- },
26
- ],
27
- });