@aidalinfo/m365-mcp 0.1.0 → 0.3.0
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.
- package/LICENSE +21 -0
- package/README.md +279 -37
- package/dist/audit.js +11 -1
- package/dist/auth/token-provider.js +79 -3
- package/dist/config.js +77 -7
- package/dist/confirm.js +1 -1
- package/dist/context.js +48 -2
- package/dist/errors.js +1 -1
- package/dist/external/activity.js +253 -0
- package/dist/external/client.js +140 -0
- package/dist/external/exchange.js +104 -0
- package/dist/external/sharepoint.js +79 -0
- package/dist/graph-client.js +108 -4
- package/dist/index.js +1 -1
- package/dist/permissions.js +189 -1
- package/dist/register.js +23 -1
- package/dist/reports.js +138 -0
- package/dist/review/collect.js +238 -0
- package/dist/review/model.js +152 -0
- package/dist/tools/access-review.js +98 -0
- package/dist/tools/applications.js +101 -0
- package/dist/tools/capabilities.js +53 -11
- package/dist/tools/common.js +77 -1
- package/dist/tools/devices.js +40 -0
- package/dist/tools/entra-applications-write.js +193 -0
- package/dist/tools/entra-applications.js +239 -0
- package/dist/tools/phase2.js +235 -0
- package/dist/tools/reports.js +151 -0
- package/dist/tools/security.js +275 -0
- package/dist/tools/sites.js +231 -0
- package/dist/tools/teams-write.js +2 -1
- package/dist/tools/teams.js +39 -1
- package/dist/tools/write-flow.js +25 -6
- package/package.json +10 -6
package/dist/permissions.js
CHANGED
|
@@ -90,6 +90,131 @@ export const TOOL_SPECS = [
|
|
|
90
90
|
alternatives: ["TeamMember.ReadWrite.All", "Directory.Read.All"],
|
|
91
91
|
rsc: ["TeamMember.Read.Group"],
|
|
92
92
|
},
|
|
93
|
+
{
|
|
94
|
+
tool: "m365_channel_members",
|
|
95
|
+
access: "read",
|
|
96
|
+
endpoints: ["GET /teams/{id}/channels/{channelId}/members"],
|
|
97
|
+
permissions: ["ChannelMember.Read.All"],
|
|
98
|
+
alternatives: ["ChannelMember.ReadWrite.All", "Directory.Read.All"],
|
|
99
|
+
rsc: ["ChannelMember.Read.Group"],
|
|
100
|
+
note: "private and shared channels have their own members, absent from m365_team_members",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
tool: "m365_usage_reports",
|
|
104
|
+
access: "read",
|
|
105
|
+
endpoints: [
|
|
106
|
+
"GET /reports/getMailboxUsageDetail(period='D7')",
|
|
107
|
+
"GET /reports/getOneDriveUsageAccountDetail(period=…)",
|
|
108
|
+
"GET /reports/getSharePointSiteUsageDetail(period=…)",
|
|
109
|
+
"GET /reports/getOffice365ActiveUserDetail(period=…)",
|
|
110
|
+
],
|
|
111
|
+
permissions: ["Reports.Read.All"],
|
|
112
|
+
note: "CSV through a 302 to a pre-authenticated Microsoft download URL (fetched without the Graph token, never returned). Concealed names (admin center → Reports setting) are detected and flagged",
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
tool: "m365_service_health",
|
|
116
|
+
access: "read",
|
|
117
|
+
endpoints: ["GET /admin/serviceAnnouncement/healthOverviews", "GET /admin/serviceAnnouncement/issues", "GET /admin/serviceAnnouncement/messages"],
|
|
118
|
+
permissions: ["ServiceHealth.Read.All"],
|
|
119
|
+
extras: [{ part: "view=messages (message center)", permissions: ["ServiceMessage.Read.All"] }],
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
tool: "m365_sites",
|
|
123
|
+
access: "read",
|
|
124
|
+
endpoints: ["GET /sites/getAllSites", "GET /sites?search=… (fallback: search=*)"],
|
|
125
|
+
permissions: ["Sites.Read.All"],
|
|
126
|
+
alternatives: ["Sites.ReadWrite.All", "Sites.FullControl.All"],
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
tool: "m365_site_info",
|
|
130
|
+
access: "read",
|
|
131
|
+
endpoints: ["GET /sites/{id} | /sites/{host}:/{path}: | /groups/{id}/sites/root", "GET /sites/{id}/drives"],
|
|
132
|
+
permissions: ["Sites.Read.All"],
|
|
133
|
+
alternatives: ["Sites.ReadWrite.All", "Sites.FullControl.All"],
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
tool: "m365_sharing_links",
|
|
137
|
+
access: "read",
|
|
138
|
+
endpoints: ["GET /drives/{driveId}/root:/{path}:", "GET /drives/{driveId}/items/{itemId}/children", "GET /drives/{driveId}/items/{itemId}/permissions"],
|
|
139
|
+
permissions: ["Sites.Read.All"],
|
|
140
|
+
alternatives: ["Sites.ReadWrite.All", "Files.Read.All"],
|
|
141
|
+
note: "bounded walk (depth ≤ 3, ≤ 200 items, target folder required); link URLs are never returned",
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
tool: "m365_directory_roles",
|
|
145
|
+
access: "read",
|
|
146
|
+
endpoints: ["GET /roleManagement/directory/roleAssignments?$expand=principal", "GET /roleManagement/directory/roleDefinitions", "GET /roleManagement/directory/roleEligibilityScheduleInstances (view=eligible)"],
|
|
147
|
+
permissions: ["RoleManagement.Read.Directory"],
|
|
148
|
+
alternatives: ["RoleManagement.Read.All", "Directory.Read.All"],
|
|
149
|
+
extras: [{ part: "view=eligible (PIM)", permissions: ["RoleManagement.Read.Directory"], requires: "Entra ID P2" }],
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
tool: "m365_user_auth_methods",
|
|
153
|
+
access: "read",
|
|
154
|
+
endpoints: ["GET /users/{id}/authentication/methods", "GET /reports/authenticationMethods/userRegistrationDetails (tenant view)"],
|
|
155
|
+
permissions: ["UserAuthenticationMethod.Read.All"],
|
|
156
|
+
extras: [{ part: "tenant view (without user)", permissions: ["AuditLog.Read.All"], requires: "Entra ID P1" }],
|
|
157
|
+
note: "method types only — phone numbers, e-mails and keys are never returned",
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
tool: "m365_user_activity",
|
|
161
|
+
access: "read",
|
|
162
|
+
endpoints: ["GET /users?$select=…,signInActivity"],
|
|
163
|
+
permissions: ["AuditLog.Read.All", "User.Read.All"],
|
|
164
|
+
requires: "Entra ID P1",
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
tool: "m365_directory_audit",
|
|
168
|
+
access: "read",
|
|
169
|
+
endpoints: ["GET /auditLogs/directoryAudits"],
|
|
170
|
+
permissions: ["AuditLog.Read.All"],
|
|
171
|
+
note: "retention 7 days without Entra ID P1, 30 days with; modified property values are never returned",
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
tool: "m365_applications",
|
|
175
|
+
access: "read",
|
|
176
|
+
endpoints: ["GET /servicePrincipals", "GET /servicePrincipals/{id}/appRoleAssignments", "GET /oauth2PermissionGrants (view=delegated_grants)"],
|
|
177
|
+
permissions: ["Application.Read.All"],
|
|
178
|
+
alternatives: ["Directory.Read.All"],
|
|
179
|
+
extras: [{ part: "view=delegated_grants", permissions: ["DelegatedPermissionGrant.Read.All"] }],
|
|
180
|
+
note: "read identity; distinct from the entra-applications write family",
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
tool: "m365_conditional_access",
|
|
184
|
+
access: "read",
|
|
185
|
+
endpoints: ["GET /identity/conditionalAccess/policies", "GET /policies/identitySecurityDefaultsEnforcementPolicy"],
|
|
186
|
+
permissions: ["Policy.Read.All"],
|
|
187
|
+
extras: [{ part: "Conditional Access policies", permissions: ["Policy.Read.All"], requires: "Entra ID P1" }],
|
|
188
|
+
note: "without Entra ID P1 the policies part answers unsupported_by_tenant and the security defaults are still read",
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
tool: "m365_intune_devices",
|
|
192
|
+
access: "read",
|
|
193
|
+
endpoints: ["GET /deviceManagement/managedDevices"],
|
|
194
|
+
permissions: ["DeviceManagementManagedDevices.Read.All"],
|
|
195
|
+
requires: "Intune",
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
tool: "m365_access_review_snapshot",
|
|
199
|
+
access: "read",
|
|
200
|
+
endpoints: ["(aggregate) the endpoints of the users, groups, channel members, roles, MFA, applications and usage-report tools"],
|
|
201
|
+
permissions: [
|
|
202
|
+
"User.Read.All",
|
|
203
|
+
"GroupMember.Read.All",
|
|
204
|
+
"LicenseAssignment.Read.All",
|
|
205
|
+
"ChannelMember.Read.All",
|
|
206
|
+
"Channel.ReadBasic.All",
|
|
207
|
+
"RoleManagement.Read.Directory",
|
|
208
|
+
"UserAuthenticationMethod.Read.All",
|
|
209
|
+
"Application.Read.All",
|
|
210
|
+
"Reports.Read.All",
|
|
211
|
+
],
|
|
212
|
+
extras: [
|
|
213
|
+
{ part: "last sign-in + tenant MFA report", permissions: ["AuditLog.Read.All"], requires: "Entra ID P1" },
|
|
214
|
+
{ part: "delegated consents", permissions: ["DelegatedPermissionGrant.Read.All"] },
|
|
215
|
+
],
|
|
216
|
+
note: "writes a dated JSON file (0600) in M365_SNAPSHOT_DIR; a section that cannot be read is reported, never left empty",
|
|
217
|
+
},
|
|
93
218
|
{
|
|
94
219
|
tool: "m365_audit_signins",
|
|
95
220
|
access: "read",
|
|
@@ -97,6 +222,42 @@ export const TOOL_SPECS = [
|
|
|
97
222
|
permissions: ["AuditLog.Read.All"],
|
|
98
223
|
note: "registered only with M365_ENABLE_SIGNIN_AUDIT=true; needs Entra ID P1/P2 (else unsupported_by_tenant). Microsoft documents Directory.Read.All alongside AuditLog.Read.All for this API — add it if Graph answers 403",
|
|
99
224
|
},
|
|
225
|
+
// ---- phase 2 (audit identity, APIs outside Graph, each feature opt-in)
|
|
226
|
+
{
|
|
227
|
+
tool: "m365_mailbox_permissions",
|
|
228
|
+
access: "read",
|
|
229
|
+
identity: "audit",
|
|
230
|
+
api: "exchange",
|
|
231
|
+
endpoints: ["POST https://outlook.office365.com/adminapi/beta/{tenant}/InvokeCommand — Get-Mailbox, Get-MailboxPermission, Get-RecipientPermission only"],
|
|
232
|
+
permissions: ["Exchange.ManageAsApp (Office 365 Exchange Online)"],
|
|
233
|
+
note: "plus a READ-ONLY Exchange role: custom role group with View-Only Recipients (preferred) or Entra Global Reader. Endpoint used by the ExchangeOnlineManagement v3 module, not otherwise documented — validate on the tenant",
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
tool: "m365_activity_collect",
|
|
237
|
+
access: "read",
|
|
238
|
+
identity: "audit",
|
|
239
|
+
api: "activity",
|
|
240
|
+
endpoints: ["GET https://manage.office.com/api/v1.0/{tenant}/activity/feed/subscriptions/list | /subscriptions/content | /audit/{blob}", "POST …/subscriptions/start (only with M365_ACTIVITY_START_SUBSCRIPTIONS=true)"],
|
|
241
|
+
permissions: ["ActivityFeed.Read (Office 365 Management APIs)"],
|
|
242
|
+
note: "unified audit must be on (Purview); Microsoft keeps 7 days — schedule the collection; local store M365_ACTIVITY_DIR purged after M365_ACTIVITY_RETENTION_DAYS (180)",
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
tool: "m365_activity_search",
|
|
246
|
+
access: "read",
|
|
247
|
+
identity: "audit",
|
|
248
|
+
api: "activity",
|
|
249
|
+
endpoints: ["(local store of m365_activity_collect)"],
|
|
250
|
+
permissions: ["ActivityFeed.Read (Office 365 Management APIs)"],
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
tool: "m365_site_permissions",
|
|
254
|
+
access: "read",
|
|
255
|
+
identity: "audit",
|
|
256
|
+
api: "sharepoint",
|
|
257
|
+
endpoints: ["GET https://{M365_SHAREPOINT_HOST}/{site}/_api/web, /roleassignments, /sitegroups/GetById(n)/users, /siteusers, /lists, /lists(guid'…')/roleassignments"],
|
|
258
|
+
permissions: ["Sites.Selected (SharePoint) + per-site fullcontrol grant"],
|
|
259
|
+
note: "reading role assignments needs full control on the site: grant it per reviewed site (Sites.Selected), never tenant-wide. Sites.FullControl.All is accepted only with M365_SHAREPOINT_ALLOW_FULLCONTROL_ALL=true",
|
|
260
|
+
},
|
|
100
261
|
// ---- writes (write identity, M365_MODE=full)
|
|
101
262
|
{
|
|
102
263
|
tool: "m365_user_update",
|
|
@@ -193,12 +354,39 @@ export const TOOL_SPECS = [
|
|
|
193
354
|
permissions: ["TeamSettings.ReadWrite.All"],
|
|
194
355
|
rsc: ["TeamSettings.ReadWrite.Group"],
|
|
195
356
|
},
|
|
357
|
+
{ tool: "m365_entra_applications", access: "read", identity: "entra", family: "entra-applications", endpoints: ["GET /applications"], permissions: ["Application.ReadWrite.OwnedBy"] },
|
|
358
|
+
{ tool: "m365_entra_application_info", access: "read", identity: "entra", family: "entra-applications", endpoints: ["GET /applications/{id}"], permissions: ["Application.ReadWrite.OwnedBy"] },
|
|
359
|
+
{ tool: "m365_entra_service_principals", access: "read", identity: "entra", family: "entra-applications", endpoints: ["GET /servicePrincipals"], permissions: ["Application.ReadWrite.OwnedBy"] },
|
|
360
|
+
{ tool: "m365_entra_service_principal_info", access: "read", identity: "entra", family: "entra-applications", endpoints: ["GET /servicePrincipals/{id}"], permissions: ["Application.ReadWrite.OwnedBy"] },
|
|
361
|
+
{ tool: "m365_entra_application_requested_permissions", access: "read", identity: "entra", family: "entra-applications", endpoints: ["GET /applications/{id}", "GET /servicePrincipals"], permissions: ["Application.ReadWrite.OwnedBy"] },
|
|
362
|
+
{ tool: "m365_entra_service_principal_effective_permissions", access: "read", identity: "entra", family: "entra-applications", endpoints: ["GET /servicePrincipals/{id}/appRoleAssignments", "GET /oauth2PermissionGrants"], permissions: ["Application.ReadWrite.OwnedBy", "Directory.Read.All"], note: "Directory.Read.All is read-only here and is required to inspect delegated OAuth2 grants" },
|
|
363
|
+
{ tool: "m365_entra_application_federated_credentials", access: "read", identity: "entra", family: "entra-applications", endpoints: ["GET /applications/{id}/federatedIdentityCredentials"], permissions: ["Application.ReadWrite.OwnedBy"] },
|
|
364
|
+
{ tool: "m365_entra_application_create", access: "write", identity: "entra", family: "entra-applications", planPermissions: ["Application.ReadWrite.OwnedBy"], endpoints: ["PATCH /applications(uniqueName='{uniqueName}') + Prefer: create-if-missing"], permissions: ["Application.ReadWrite.OwnedBy"] },
|
|
365
|
+
{ tool: "m365_entra_application_update", access: "write", identity: "entra", family: "entra-applications", planPermissions: ["Application.ReadWrite.OwnedBy"], endpoints: ["PATCH /applications/{id}"], permissions: ["Application.ReadWrite.OwnedBy"] },
|
|
366
|
+
{ tool: "m365_entra_service_principal_create", access: "write", identity: "entra", family: "entra-applications", planPermissions: ["Application.ReadWrite.OwnedBy"], endpoints: ["PATCH /servicePrincipals(appId='{appId}') + Prefer: create-if-missing", "POST /servicePrincipals/{id}/owners/$ref when Graph did not establish ownership"], permissions: ["Application.ReadWrite.OwnedBy"] },
|
|
367
|
+
{ tool: "m365_entra_service_principal_update", access: "write", identity: "entra", family: "entra-applications", planPermissions: ["Application.ReadWrite.OwnedBy"], endpoints: ["PATCH /servicePrincipals/{id}"], permissions: ["Application.ReadWrite.OwnedBy"] },
|
|
196
368
|
];
|
|
197
369
|
export const specOf = (tool) => TOOL_SPECS.find((s) => s.tool === tool);
|
|
370
|
+
/** Equivalences Microsoft documents between read permissions (the broader one is sufficient). */
|
|
371
|
+
const IMPLIED = {
|
|
372
|
+
"RoleManagement.Read.Directory": ["RoleManagement.Read.All", "Directory.Read.All"],
|
|
373
|
+
"Channel.ReadBasic.All": ["Directory.Read.All"],
|
|
374
|
+
"ChannelMember.Read.All": ["Directory.Read.All"],
|
|
375
|
+
"GroupMember.Read.All": ["Group.Read.All", "Directory.Read.All"],
|
|
376
|
+
"User.Read.All": ["Directory.Read.All"],
|
|
377
|
+
"Application.Read.All": ["Directory.Read.All"],
|
|
378
|
+
"LicenseAssignment.Read.All": ["Organization.Read.All", "Directory.Read.All"],
|
|
379
|
+
};
|
|
380
|
+
const hasPermission = (has, p) => has.has(p) || (IMPLIED[p] ?? []).some((q) => has.has(q));
|
|
381
|
+
/** Status of each extra part of a tool. */
|
|
382
|
+
export function extraStatus(spec, roles) {
|
|
383
|
+
const has = new Set(roles);
|
|
384
|
+
return (spec.extras ?? []).map((e) => ({ part: e.part, needs: e.permissions.join(" + "), status: e.permissions.every((p) => hasPermission(has, p)) ? "granted" : "missing", ...(e.requires ? { requires: e.requires } : {}) }));
|
|
385
|
+
}
|
|
198
386
|
/** Does this set of token roles satisfy the tool? RSC grants are invisible in the token: "unknown" then. */
|
|
199
387
|
export function permissionStatus(spec, roles) {
|
|
200
388
|
const has = new Set(roles);
|
|
201
|
-
if (spec.permissions.every((p) => has
|
|
389
|
+
if (spec.permissions.every((p) => hasPermission(has, p)))
|
|
202
390
|
return "granted";
|
|
203
391
|
if (spec.alternatives?.some((p) => has.has(p)))
|
|
204
392
|
return "granted";
|
package/dist/register.js
CHANGED
|
@@ -8,11 +8,20 @@ import { registerUserWriteTools } from "./tools/users-write.js";
|
|
|
8
8
|
import { registerLicenseWriteTools } from "./tools/licenses-write.js";
|
|
9
9
|
import { registerGroupWriteTools } from "./tools/groups-write.js";
|
|
10
10
|
import { registerTeamWriteTools } from "./tools/teams-write.js";
|
|
11
|
+
import { registerEntraApplicationReadTools } from "./tools/entra-applications.js";
|
|
12
|
+
import { registerEntraApplicationWriteTools } from "./tools/entra-applications-write.js";
|
|
13
|
+
import { registerReportTools } from "./tools/reports.js";
|
|
14
|
+
import { registerSiteTools } from "./tools/sites.js";
|
|
15
|
+
import { registerSecurityTools } from "./tools/security.js";
|
|
16
|
+
import { registerApplicationTools } from "./tools/applications.js";
|
|
17
|
+
import { registerDeviceTools } from "./tools/devices.js";
|
|
18
|
+
import { registerAccessReviewTools } from "./tools/access-review.js";
|
|
19
|
+
import { registerPhase2Tools } from "./tools/phase2.js";
|
|
11
20
|
/**
|
|
12
21
|
* Read tools always register. Write tools register only in full mode, with a write identity,
|
|
13
22
|
* and per family (M365_WRITE_FAMILIES) — in readonly mode they do not exist at all.
|
|
14
23
|
*/
|
|
15
|
-
export function registerTools(server, ctx) {
|
|
24
|
+
export function registerTools(server, ctx, serverVersion) {
|
|
16
25
|
const names = [];
|
|
17
26
|
const tracking = new Proxy(server, {
|
|
18
27
|
get(target, prop, receiver) {
|
|
@@ -31,6 +40,13 @@ export function registerTools(server, ctx) {
|
|
|
31
40
|
registerLicenseTools(tracking, ctx);
|
|
32
41
|
registerGroupTools(tracking, ctx);
|
|
33
42
|
registerTeamTools(tracking, ctx);
|
|
43
|
+
registerReportTools(tracking, ctx);
|
|
44
|
+
registerSiteTools(tracking, ctx);
|
|
45
|
+
registerSecurityTools(tracking, ctx);
|
|
46
|
+
registerApplicationTools(tracking, ctx);
|
|
47
|
+
registerDeviceTools(tracking, ctx);
|
|
48
|
+
registerAccessReviewTools(tracking, ctx, serverVersion);
|
|
49
|
+
registerPhase2Tools(tracking, ctx);
|
|
34
50
|
if (ctx.config.signInAudit)
|
|
35
51
|
registerSignInTools(tracking, ctx);
|
|
36
52
|
if (ctx.config.mode === "full") {
|
|
@@ -45,6 +61,12 @@ export function registerTools(server, ctx) {
|
|
|
45
61
|
registerGroupWriteTools(tracking, ctx);
|
|
46
62
|
if (f.has("teams"))
|
|
47
63
|
registerTeamWriteTools(tracking, ctx);
|
|
64
|
+
if (f.has("entra-applications")) {
|
|
65
|
+
if (!ctx.identities.entra || !ctx.graph.hasEntra)
|
|
66
|
+
throw new Error("entra-applications requires the dedicated identity (M365_ENTRA_*)");
|
|
67
|
+
registerEntraApplicationReadTools(tracking, ctx);
|
|
68
|
+
registerEntraApplicationWriteTools(tracking, ctx);
|
|
69
|
+
}
|
|
48
70
|
}
|
|
49
71
|
ctx.registered.splice(0, ctx.registered.length, ...names);
|
|
50
72
|
return names;
|
package/dist/reports.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
export const REPORTS = {
|
|
2
|
+
mailbox: { endpoint: "getMailboxUsageDetail", title: "Mailbox usage" },
|
|
3
|
+
onedrive: { endpoint: "getOneDriveUsageAccountDetail", title: "OneDrive usage" },
|
|
4
|
+
sharepoint: { endpoint: "getSharePointSiteUsageDetail", title: "SharePoint site usage" },
|
|
5
|
+
active_users: { endpoint: "getOffice365ActiveUserDetail", title: "Microsoft 365 active users" },
|
|
6
|
+
};
|
|
7
|
+
export const reportPath = (kind, period) => `/reports/${REPORTS[kind].endpoint}(period='${period}')`;
|
|
8
|
+
/** RFC 4180 CSV → rows of strings (quoted fields, "" escapes, CRLF, leading BOM). */
|
|
9
|
+
export function parseCsv(text) {
|
|
10
|
+
const rows = [];
|
|
11
|
+
let row = [];
|
|
12
|
+
let field = "";
|
|
13
|
+
let quoted = false;
|
|
14
|
+
const s = text.replace(/^/, "");
|
|
15
|
+
for (let i = 0; i < s.length; i++) {
|
|
16
|
+
const c = s[i];
|
|
17
|
+
if (quoted) {
|
|
18
|
+
if (c === '"') {
|
|
19
|
+
if (s[i + 1] === '"') {
|
|
20
|
+
field += '"';
|
|
21
|
+
i++;
|
|
22
|
+
}
|
|
23
|
+
else
|
|
24
|
+
quoted = false;
|
|
25
|
+
}
|
|
26
|
+
else
|
|
27
|
+
field += c;
|
|
28
|
+
}
|
|
29
|
+
else if (c === '"')
|
|
30
|
+
quoted = true;
|
|
31
|
+
else if (c === ",") {
|
|
32
|
+
row.push(field);
|
|
33
|
+
field = "";
|
|
34
|
+
}
|
|
35
|
+
else if (c === "\n" || c === "\r") {
|
|
36
|
+
if (c === "\r" && s[i + 1] === "\n")
|
|
37
|
+
i++;
|
|
38
|
+
row.push(field);
|
|
39
|
+
if (row.some((f) => f !== ""))
|
|
40
|
+
rows.push(row);
|
|
41
|
+
row = [];
|
|
42
|
+
field = "";
|
|
43
|
+
}
|
|
44
|
+
else
|
|
45
|
+
field += c;
|
|
46
|
+
}
|
|
47
|
+
row.push(field);
|
|
48
|
+
if (row.some((f) => f !== ""))
|
|
49
|
+
rows.push(row);
|
|
50
|
+
return rows;
|
|
51
|
+
}
|
|
52
|
+
/** CSV with a header line → records keyed by column name. */
|
|
53
|
+
export function csvRecords(text) {
|
|
54
|
+
const [header, ...rows] = parseCsv(text);
|
|
55
|
+
if (!header)
|
|
56
|
+
return [];
|
|
57
|
+
return rows.map((r) => Object.fromEntries(header.map((h, i) => [h.trim(), (r[i] ?? "").trim()])));
|
|
58
|
+
}
|
|
59
|
+
/** A concealed name: 32 hex characters (MD5), with no "@" nor space. */
|
|
60
|
+
export const isConcealed = (v) => Boolean(v && /^[0-9A-F]{32}$/i.test(v));
|
|
61
|
+
const num = (v) => (v === undefined || v === "" ? undefined : Number(v));
|
|
62
|
+
const bool = (v) => (v === undefined || v === "" ? undefined : v.toLowerCase() === "true");
|
|
63
|
+
const str = (v) => (v === undefined || v === "" ? undefined : v);
|
|
64
|
+
export function normaliseRow(kind, r) {
|
|
65
|
+
const upn = str(r["User Principal Name"] ?? r["Owner Principal Name"]);
|
|
66
|
+
const displayName = str(r["Display Name"] ?? r["Owner Display Name"]);
|
|
67
|
+
switch (kind) {
|
|
68
|
+
case "mailbox":
|
|
69
|
+
return {
|
|
70
|
+
key: upn ?? "",
|
|
71
|
+
upn,
|
|
72
|
+
displayName,
|
|
73
|
+
isDeleted: bool(r["Is Deleted"]),
|
|
74
|
+
lastActivityDate: str(r["Last Activity Date"]),
|
|
75
|
+
storageUsedBytes: num(r["Storage Used (Byte)"]),
|
|
76
|
+
storageAllocatedBytes: num(r["Prohibit Send/Receive Quota (Byte)"]),
|
|
77
|
+
itemCount: num(r["Item Count"]),
|
|
78
|
+
recipientType: str(r["Recipient Type"]),
|
|
79
|
+
hasArchive: bool(r["Has Archive"]),
|
|
80
|
+
concealed: isConcealed(upn) || isConcealed(displayName),
|
|
81
|
+
};
|
|
82
|
+
case "onedrive":
|
|
83
|
+
return {
|
|
84
|
+
key: upn ?? str(r["Site URL"]) ?? "",
|
|
85
|
+
upn,
|
|
86
|
+
displayName,
|
|
87
|
+
siteUrl: str(r["Site URL"]),
|
|
88
|
+
isDeleted: bool(r["Is Deleted"]),
|
|
89
|
+
lastActivityDate: str(r["Last Activity Date"]),
|
|
90
|
+
storageUsedBytes: num(r["Storage Used (Byte)"]),
|
|
91
|
+
storageAllocatedBytes: num(r["Storage Allocated (Byte)"]),
|
|
92
|
+
itemCount: num(r["File Count"]),
|
|
93
|
+
concealed: isConcealed(upn) || isConcealed(displayName) || (!r["Site URL"] && Boolean(upn)),
|
|
94
|
+
};
|
|
95
|
+
case "sharepoint":
|
|
96
|
+
return {
|
|
97
|
+
key: str(r["Site URL"]) ?? str(r["Site Id"]) ?? "",
|
|
98
|
+
upn,
|
|
99
|
+
displayName,
|
|
100
|
+
siteUrl: str(r["Site URL"]),
|
|
101
|
+
siteId: str(r["Site Id"]),
|
|
102
|
+
isDeleted: bool(r["Is Deleted"]),
|
|
103
|
+
lastActivityDate: str(r["Last Activity Date"]),
|
|
104
|
+
storageUsedBytes: num(r["Storage Used (Byte)"]),
|
|
105
|
+
storageAllocatedBytes: num(r["Storage Allocated (Byte)"]),
|
|
106
|
+
itemCount: num(r["File Count"]),
|
|
107
|
+
template: str(r["Root Web Template"]),
|
|
108
|
+
concealed: isConcealed(upn) || isConcealed(displayName) || (!r["Site URL"] && Boolean(r["Site Id"])),
|
|
109
|
+
};
|
|
110
|
+
case "active_users":
|
|
111
|
+
return {
|
|
112
|
+
key: upn ?? "",
|
|
113
|
+
upn,
|
|
114
|
+
displayName,
|
|
115
|
+
isDeleted: bool(r["Is Deleted"]),
|
|
116
|
+
services: {
|
|
117
|
+
exchange: str(r["Exchange Last Activity Date"]),
|
|
118
|
+
onedrive: str(r["OneDrive Last Activity Date"]),
|
|
119
|
+
sharepoint: str(r["SharePoint Last Activity Date"]),
|
|
120
|
+
teams: str(r["Teams Last Activity Date"]),
|
|
121
|
+
},
|
|
122
|
+
lastActivityDate: [r["Exchange Last Activity Date"], r["OneDrive Last Activity Date"], r["SharePoint Last Activity Date"], r["Teams Last Activity Date"]]
|
|
123
|
+
.filter(Boolean)
|
|
124
|
+
.sort()
|
|
125
|
+
.pop(),
|
|
126
|
+
assignedProducts: str(r["Assigned Products"])?.split("+").map((p) => p.trim()).filter(Boolean),
|
|
127
|
+
concealed: isConcealed(upn) || isConcealed(displayName),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export async function fetchUsageReport(graph, kind, period) {
|
|
132
|
+
const { csv, requestId } = await graph.getReportCsv(reportPath(kind, period));
|
|
133
|
+
const records = csvRecords(csv);
|
|
134
|
+
const rows = records.map((r) => normaliseRow(kind, r));
|
|
135
|
+
return { kind, period, rows, concealed: rows.some((r) => r.concealed), refreshDate: records[0]?.["Report Refresh Date"], requestId };
|
|
136
|
+
}
|
|
137
|
+
export const CONCEALED_WARNING = "⚠ Names are concealed in this report (user, group and site names replaced by hashes). To see real names, a Global or Reports administrator must untick " +
|
|
138
|
+
"\"Display concealed user, group, and site names in all reports\" in the Microsoft 365 admin center (Settings → Org settings → Services → Reports).";
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { toM365Error } from "../errors.js";
|
|
2
|
+
import { fetchUsageReport } from "../reports.js";
|
|
3
|
+
import { appPermissions, MICROSOFT_TENANTS, ownerOf, roleResolver } from "../tools/applications.js";
|
|
4
|
+
import { collectAll, mapLimit, tenantHas } from "../tools/common.js";
|
|
5
|
+
import { isMfaMethod, principalType, roleAssignments, roleNames, userMethods } from "../tools/security.js";
|
|
6
|
+
import { asList, fullAccess, sendAs } from "../external/exchange.js";
|
|
7
|
+
import { SNAPSHOT_SCHEMA } from "./model.js";
|
|
8
|
+
const ADVANCED = { ConsistencyLevel: "eventual" };
|
|
9
|
+
const CONCURRENCY = 4;
|
|
10
|
+
const MAX_USERS = 10_000;
|
|
11
|
+
const MAX_GROUPS = 2_000;
|
|
12
|
+
const MAX_MEMBERS = 5_000;
|
|
13
|
+
const MAX_APPS = 300;
|
|
14
|
+
/** Run one section: its status is recorded, its failure never aborts the others nor looks like "nothing". */
|
|
15
|
+
async function section(sections, name, fn) {
|
|
16
|
+
try {
|
|
17
|
+
const r = await fn();
|
|
18
|
+
sections[name] = { ok: true, ...(r.truncated ? { truncated: true } : {}), ...(r.note ? { note: r.note } : {}) };
|
|
19
|
+
return r;
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
const e = toM365Error(err);
|
|
23
|
+
sections[name] = { ok: false, error: `${e.code}: ${e.message}`.slice(0, 400) };
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const groupKind = (g) => g.groupTypes?.includes("Unified") ? "microsoft365" : g.mailEnabled && g.securityEnabled ? "mailEnabledSecurity" : g.mailEnabled ? "distribution" : "security";
|
|
28
|
+
export async function collectSnapshot(ctx, opts = {}) {
|
|
29
|
+
const sections = {};
|
|
30
|
+
const generatedAt = (opts.now?.() ?? new Date()).toISOString();
|
|
31
|
+
const skus = (await section(sections, "skus", async () => ({ list: await ctx.skus.list(true) })))?.list ?? [];
|
|
32
|
+
const skuName = new Map(skus.map((s) => [s.skuId, s.skuPartNumber]));
|
|
33
|
+
const [entraP1, entraP2, intune] = await Promise.all([tenantHas(ctx, "Entra ID P1"), tenantHas(ctx, "Entra ID P2"), tenantHas(ctx, "Intune")]);
|
|
34
|
+
const baseSelect = "id,userPrincipalName,displayName,accountEnabled,userType,createdDateTime,assignedLicenses";
|
|
35
|
+
const rawUsers = await section(sections, "users", async () => {
|
|
36
|
+
if (entraP1) {
|
|
37
|
+
try {
|
|
38
|
+
// signInActivity caps the page size at 120
|
|
39
|
+
const r = await collectAll(ctx, "/users", { $select: `${baseSelect},signInActivity` }, { top: 120, max: MAX_USERS });
|
|
40
|
+
return { ...r, withSignIn: true };
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
sections.signInActivity = { ok: false, error: toM365Error(err).message.slice(0, 400) };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return { ...(await collectAll(ctx, "/users", { $select: baseSelect }, { max: MAX_USERS })), withSignIn: false };
|
|
47
|
+
});
|
|
48
|
+
const users = (rawUsers?.items ?? []).map((u) => {
|
|
49
|
+
const a = u.signInActivity ?? {};
|
|
50
|
+
const last = [a.lastSignInDateTime, a.lastNonInteractiveSignInDateTime].filter(Boolean).sort().pop() ?? null;
|
|
51
|
+
return {
|
|
52
|
+
id: u.id,
|
|
53
|
+
upn: u.userPrincipalName,
|
|
54
|
+
displayName: u.displayName,
|
|
55
|
+
accountEnabled: u.accountEnabled,
|
|
56
|
+
userType: u.userType,
|
|
57
|
+
createdDateTime: u.createdDateTime,
|
|
58
|
+
licenses: (u.assignedLicenses ?? []).map((l) => skuName.get(l.skuId) ?? l.skuId),
|
|
59
|
+
...(rawUsers?.withSignIn ? { lastSignIn: last } : {}),
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
const byId = new Map(users.map((u) => [u.id, u]));
|
|
63
|
+
const byUpn = new Map(users.filter((u) => u.upn).map((u) => [u.upn.toLowerCase(), u]));
|
|
64
|
+
const groups = (await section(sections, "groups", async () => {
|
|
65
|
+
const { items, truncated } = await collectAll(ctx, "/groups", { $select: "id,displayName,groupTypes,mailEnabled,securityEnabled,visibility,resourceProvisioningOptions" }, { max: MAX_GROUPS });
|
|
66
|
+
let memberTruncated = false;
|
|
67
|
+
const list = await mapLimit(items, CONCURRENCY, async (g) => {
|
|
68
|
+
const [owners, members] = await Promise.all([
|
|
69
|
+
collectAll(ctx, `/groups/${g.id}/owners`, { $select: "id" }, { max: 500 }),
|
|
70
|
+
collectAll(ctx, `/groups/${g.id}/members`, { $select: "id" }, { max: MAX_MEMBERS }),
|
|
71
|
+
]);
|
|
72
|
+
if (owners.truncated || members.truncated)
|
|
73
|
+
memberTruncated = true;
|
|
74
|
+
return {
|
|
75
|
+
id: g.id,
|
|
76
|
+
displayName: g.displayName,
|
|
77
|
+
kind: groupKind(g),
|
|
78
|
+
isTeam: Boolean(g.resourceProvisioningOptions?.includes("Team")),
|
|
79
|
+
dynamic: Boolean(g.groupTypes?.includes("DynamicMembership")),
|
|
80
|
+
visibility: g.visibility,
|
|
81
|
+
owners: owners.items.map((o) => o.id),
|
|
82
|
+
members: members.items.map((m) => m.id),
|
|
83
|
+
...(owners.truncated || members.truncated ? { truncated: true } : {}),
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
return { list, truncated: truncated || memberTruncated };
|
|
87
|
+
}))?.list ?? [];
|
|
88
|
+
// private and shared channels: their members are not the team's
|
|
89
|
+
const channels = (await section(sections, "channels", async () => {
|
|
90
|
+
const teams = groups.filter((g) => g.isTeam);
|
|
91
|
+
const perTeam = await mapLimit(teams, CONCURRENCY, async (t) => {
|
|
92
|
+
const { items } = await collectAll(ctx, `/teams/${t.id}/channels`, { $select: "id,displayName,membershipType", $filter: "membershipType ne 'standard'" }, { top: false, max: 500 });
|
|
93
|
+
return mapLimit(items, CONCURRENCY, async (c) => {
|
|
94
|
+
const { items: m } = await collectAll(ctx, `/teams/${t.id}/channels/${encodeURIComponent(c.id)}/members`, {}, { top: false, max: MAX_MEMBERS });
|
|
95
|
+
const ids = (x) => x.map((y) => y.userId).filter((y) => Boolean(y));
|
|
96
|
+
return { teamId: t.id, teamName: t.displayName, channelId: c.id, displayName: c.displayName, membershipType: c.membershipType, owners: ids(m.filter((y) => y.roles?.includes("owner"))), members: ids(m) };
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
return { list: perTeam.flat() };
|
|
100
|
+
}))?.list ?? [];
|
|
101
|
+
// admin roles
|
|
102
|
+
const roles = (await section(sections, "roles", async () => {
|
|
103
|
+
const [names, assignments] = await Promise.all([roleNames(ctx), roleAssignments(ctx)]);
|
|
104
|
+
return {
|
|
105
|
+
list: assignments.map((a) => ({
|
|
106
|
+
role: names.get(a.roleDefinitionId)?.displayName ?? a.roleDefinitionId,
|
|
107
|
+
roleId: a.roleDefinitionId,
|
|
108
|
+
principalId: a.principalId,
|
|
109
|
+
principalType: principalType(a.principal),
|
|
110
|
+
principalName: a.principal?.userPrincipalName ?? a.principal?.displayName,
|
|
111
|
+
scope: !a.directoryScopeId || a.directoryScopeId === "/" ? "tenant" : a.directoryScopeId,
|
|
112
|
+
})),
|
|
113
|
+
};
|
|
114
|
+
}))?.list ?? [];
|
|
115
|
+
// MFA: the tenant report with P1; otherwise the methods of each admin user (few calls)
|
|
116
|
+
await section(sections, "mfa", async () => {
|
|
117
|
+
if (entraP1) {
|
|
118
|
+
try {
|
|
119
|
+
const { items, truncated } = await collectAll(ctx, "/reports/authenticationMethods/userRegistrationDetails", { $select: "id,isMfaRegistered" }, { max: MAX_USERS });
|
|
120
|
+
for (const r of items) {
|
|
121
|
+
const u = byId.get(r.id);
|
|
122
|
+
if (u && typeof r.isMfaRegistered === "boolean")
|
|
123
|
+
u.mfaRegistered = r.isMfaRegistered;
|
|
124
|
+
}
|
|
125
|
+
return { truncated, note: "MFA registration report (all users)" };
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
/* fall back to the admins' methods */
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const admins = [...new Set(roles.filter((r) => r.principalType === "user").map((r) => r.principalId))];
|
|
132
|
+
await mapLimit(admins, CONCURRENCY, async (id) => {
|
|
133
|
+
const methods = await userMethods(ctx, id);
|
|
134
|
+
const u = byId.get(id);
|
|
135
|
+
if (u)
|
|
136
|
+
u.mfaRegistered = methods.some((m) => isMfaMethod(m.type));
|
|
137
|
+
});
|
|
138
|
+
return { note: `authentication methods of the ${admins.length} admin user(s) only (no tenant MFA report${entraP1 === false ? ": no Entra ID P1" : ""})` };
|
|
139
|
+
});
|
|
140
|
+
// applications: third-party and own enterprise apps, their application permissions and delegated consents
|
|
141
|
+
const applications = (await section(sections, "applications", async () => {
|
|
142
|
+
const resolver = roleResolver(ctx);
|
|
143
|
+
const tenant = ctx.config.tenantId;
|
|
144
|
+
const notMicrosoft = MICROSOFT_TENANTS.map((t) => `appOwnerOrganizationId ne ${t}`).join(" and ");
|
|
145
|
+
const { items: sps, truncated } = await collectAll(ctx, "/servicePrincipals", { $select: "id,appId,displayName,appOwnerOrganizationId", $filter: `tags/any(t:t eq 'WindowsAzureActiveDirectoryIntegratedApp') and ${notMicrosoft}`, $count: "true" }, { headers: ADVANCED, max: MAX_APPS });
|
|
146
|
+
const apps = new Map();
|
|
147
|
+
await mapLimit(sps, CONCURRENCY, async (sp) => {
|
|
148
|
+
const perms = await appPermissions(ctx, sp.id, resolver);
|
|
149
|
+
apps.set(sp.id, { id: sp.id, appId: sp.appId, displayName: sp.displayName, owner: ownerOf(sp, tenant), appPermissions: perms.items.map((p) => `${p.resource}: ${p.permission}`).sort(), delegatedGrants: [] });
|
|
150
|
+
});
|
|
151
|
+
let note;
|
|
152
|
+
try {
|
|
153
|
+
const { items: grants } = await collectAll(ctx, "/oauth2PermissionGrants", {}, { top: false, max: 5000 });
|
|
154
|
+
for (const g of grants) {
|
|
155
|
+
let app = apps.get(g.clientId);
|
|
156
|
+
if (!app) {
|
|
157
|
+
app = { id: g.clientId, displayName: await resolver.name(g.clientId), owner: "consented client", appPermissions: [], delegatedGrants: [] };
|
|
158
|
+
apps.set(g.clientId, app);
|
|
159
|
+
}
|
|
160
|
+
const resource = await resolver.name(g.resourceId);
|
|
161
|
+
for (const scope of (g.scope ?? "").trim().split(/\s+/).filter(Boolean)) {
|
|
162
|
+
app.delegatedGrants.push(`${resource}: ${scope} (${g.consentType === "AllPrincipals" ? "admin" : `user ${g.principalId}`})`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
note = `delegated consents not read — ${toM365Error(err).code} (needs DelegatedPermissionGrant.Read.All)`;
|
|
168
|
+
sections.delegatedGrants = { ok: false, error: toM365Error(err).message.slice(0, 400) };
|
|
169
|
+
}
|
|
170
|
+
for (const a of apps.values())
|
|
171
|
+
a.delegatedGrants.sort();
|
|
172
|
+
return { list: [...apps.values()], truncated, note };
|
|
173
|
+
}))?.list ?? [];
|
|
174
|
+
// storage and mailbox types from the usage reports
|
|
175
|
+
let concealed = false;
|
|
176
|
+
await section(sections, "mailboxes", async () => {
|
|
177
|
+
const r = await fetchUsageReport(ctx.graph, "mailbox", "D7");
|
|
178
|
+
concealed ||= r.concealed;
|
|
179
|
+
for (const row of r.rows) {
|
|
180
|
+
const u = row.upn ? byUpn.get(row.upn.toLowerCase()) : undefined;
|
|
181
|
+
if (u && !row.isDeleted) {
|
|
182
|
+
u.mailboxType = row.recipientType;
|
|
183
|
+
u.mailboxBytes = row.storageUsedBytes;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return { note: r.concealed ? "names concealed in reports" : undefined };
|
|
187
|
+
});
|
|
188
|
+
await section(sections, "onedrive", async () => {
|
|
189
|
+
const r = await fetchUsageReport(ctx.graph, "onedrive", "D7");
|
|
190
|
+
concealed ||= r.concealed;
|
|
191
|
+
for (const row of r.rows) {
|
|
192
|
+
const u = row.upn ? byUpn.get(row.upn.toLowerCase()) : undefined;
|
|
193
|
+
if (u && !row.isDeleted)
|
|
194
|
+
u.oneDriveBytes = row.storageUsedBytes;
|
|
195
|
+
}
|
|
196
|
+
return {};
|
|
197
|
+
});
|
|
198
|
+
const sites = (await section(sections, "sites", async () => {
|
|
199
|
+
const r = await fetchUsageReport(ctx.graph, "sharepoint", "D7");
|
|
200
|
+
concealed ||= r.concealed;
|
|
201
|
+
return { list: r.rows.filter((x) => !x.isDeleted).map((x) => ({ key: x.key, siteUrl: x.siteUrl, template: x.template, storageBytes: x.storageUsedBytes, lastActivityDate: x.lastActivityDate })) };
|
|
202
|
+
}))?.list ?? [];
|
|
203
|
+
// phase 2: who can use each shared mailbox (only with the exchange feature of the audit identity)
|
|
204
|
+
let mailboxAccess;
|
|
205
|
+
const exchange = ctx.ext.exchange;
|
|
206
|
+
if (exchange) {
|
|
207
|
+
mailboxAccess =
|
|
208
|
+
(await section(sections, "mailboxAccess", async () => {
|
|
209
|
+
const { items, truncated } = await exchange.invoke("Get-Mailbox", { RecipientTypeDetails: "SharedMailbox", ResultSize: 1000 });
|
|
210
|
+
const boxes = items.slice(0, 300);
|
|
211
|
+
const list = await mapLimit(boxes, 3, async (m) => {
|
|
212
|
+
const id = m.PrimarySmtpAddress ?? m.UserPrincipalName ?? m.ExternalDirectoryObjectId;
|
|
213
|
+
const key = m.ExternalDirectoryObjectId || id;
|
|
214
|
+
const [fa, sa] = await Promise.all([exchange.invoke("Get-MailboxPermission", { Identity: key }), exchange.invoke("Get-RecipientPermission", { Identity: key, AccessRights: "SendAs" })]);
|
|
215
|
+
const grants = [...fullAccess(fa.items).map((u) => `FullAccess: ${u}`), ...sendAs(sa.items).map((u) => `SendAs: ${u}`), ...asList(m.GrantSendOnBehalfTo).map((u) => `SendOnBehalf: ${u}`)].sort();
|
|
216
|
+
return { mailbox: id.toLowerCase(), displayName: m.DisplayName, grants };
|
|
217
|
+
});
|
|
218
|
+
return { list, truncated: truncated || items.length > 300 };
|
|
219
|
+
}))?.list ?? [];
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
schema: SNAPSHOT_SCHEMA,
|
|
223
|
+
tenantId: ctx.config.tenantId,
|
|
224
|
+
generatedAt,
|
|
225
|
+
serverVersion: opts.serverVersion,
|
|
226
|
+
tenantFeatures: { entraP1, entraP2, intune },
|
|
227
|
+
sections,
|
|
228
|
+
skus: skus.map((s) => ({ skuId: s.skuId, skuPartNumber: s.skuPartNumber, purchased: s.prepaidUnits?.enabled ?? 0, consumed: s.consumedUnits ?? 0 })),
|
|
229
|
+
users,
|
|
230
|
+
groups,
|
|
231
|
+
channels,
|
|
232
|
+
roles,
|
|
233
|
+
applications,
|
|
234
|
+
sites,
|
|
235
|
+
...(mailboxAccess ? { mailboxAccess } : {}),
|
|
236
|
+
...(concealed ? { reportsConcealed: true } : {}),
|
|
237
|
+
};
|
|
238
|
+
}
|