@softeria/ms-365-mcp-server 0.182.2 → 0.183.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/.gitattributes +1 -0
- package/PRESETS.md +15 -9
- package/README.md +1 -1
- package/dist/__tests__/log-safe.test.js +153 -0
- package/dist/app-mode.js +1 -0
- package/dist/attachment-route.js +11 -4
- package/dist/audit-log.js +2 -0
- package/dist/auth.js +4 -1
- package/dist/crash-logging.js +27 -13
- package/dist/endpoints.json +12 -2
- package/dist/generated/client.js +59 -0
- package/dist/graph-client.js +6 -5
- package/dist/graph-tools.js +25 -14
- package/dist/lib/bounded-file-transport.js +99 -0
- package/dist/lib/log-limits.js +12 -0
- package/dist/lib/log-safe.js +405 -0
- package/dist/lib/microsoft-auth.js +99 -1
- package/dist/logger.js +11 -4
- package/dist/server.js +38 -5
- package/package.json +1 -1
- package/src/endpoints.json +12 -2
package/dist/graph-tools.js
CHANGED
|
@@ -92,6 +92,13 @@ import {
|
|
|
92
92
|
userFieldEnforcement
|
|
93
93
|
} from "./lib/user-field-policy.js";
|
|
94
94
|
import logger from "./logger.js";
|
|
95
|
+
import {
|
|
96
|
+
describeError,
|
|
97
|
+
describeShape,
|
|
98
|
+
describeText,
|
|
99
|
+
describeUrl,
|
|
100
|
+
serializedSize
|
|
101
|
+
} from "./lib/log-safe.js";
|
|
95
102
|
import { getRequestTokens } from "./request-context.js";
|
|
96
103
|
import { TOOL_CATEGORIES } from "./tool-categories.js";
|
|
97
104
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -309,7 +316,9 @@ function normalizeSearchQueryParam(queryParams, path2, toolAlias) {
|
|
|
309
316
|
if (inner === "") return noSearchableText();
|
|
310
317
|
const normalized = `"${inner}"`;
|
|
311
318
|
if (normalized !== raw) {
|
|
312
|
-
logger.info(
|
|
319
|
+
logger.info(
|
|
320
|
+
`Auto-corrected parameter '$search': normalized KQL quoting ${describeText(normalized)}`
|
|
321
|
+
);
|
|
313
322
|
queryParams["$search"] = normalized;
|
|
314
323
|
}
|
|
315
324
|
}
|
|
@@ -1904,11 +1913,7 @@ function hasOwn(obj, key) {
|
|
|
1904
1913
|
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
1905
1914
|
}
|
|
1906
1915
|
function describeParamsForLog(params) {
|
|
1907
|
-
|
|
1908
|
-
return JSON.stringify(params);
|
|
1909
|
-
} catch (error) {
|
|
1910
|
-
return `[unserializable: ${error instanceof Error ? error.name : "unknown error"}]`;
|
|
1911
|
-
}
|
|
1916
|
+
return describeShape(params);
|
|
1912
1917
|
}
|
|
1913
1918
|
function escapeIfStringLiteral(template, names, value) {
|
|
1914
1919
|
const quoted = names.some((n) => template.includes(`'{${n}}'`) || template.includes(`':${n}'`));
|
|
@@ -2111,7 +2116,7 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
|
|
|
2111
2116
|
}
|
|
2112
2117
|
} else if (paramName === "body") {
|
|
2113
2118
|
body = paramValue;
|
|
2114
|
-
logger.info(`Set body param: ${
|
|
2119
|
+
logger.info(`Set body param: ${describeShape(body)} (${serializedSize(body)} bytes)`);
|
|
2115
2120
|
} else if (path2.includes(`:${paramName}`) || path2.includes(`{${paramName}}`) || path2.includes(`:${camelCaseParamName}`) || path2.includes(`{${camelCaseParamName}}`)) {
|
|
2116
2121
|
const encodedValue = encodeURIComponent(
|
|
2117
2122
|
escapeIfStringLiteral(tool.path, [paramName, camelCaseParamName], paramValue)
|
|
@@ -2127,7 +2132,9 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
|
|
|
2127
2132
|
}
|
|
2128
2133
|
} else if (isOdataParam) {
|
|
2129
2134
|
queryParams[fixedParamName] = `${paramValue}`;
|
|
2130
|
-
logger.info(
|
|
2135
|
+
logger.info(
|
|
2136
|
+
`OData param fallback: forwarded ${fixedParamName} ${describeText(String(paramValue))}`
|
|
2137
|
+
);
|
|
2131
2138
|
} else if (bodyShape && (hasOwn(bodyShape, paramName) || hasOwn(bodyShape, camelCaseParamName)) && !READ_ONLY_BODY_FIELDS.has(hasOwn(bodyShape, paramName) ? paramName : camelCaseParamName)) {
|
|
2132
2139
|
const fieldName = hasOwn(bodyShape, paramName) ? paramName : camelCaseParamName;
|
|
2133
2140
|
strayBodyFields[fieldName] = paramValue;
|
|
@@ -2135,7 +2142,9 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
|
|
|
2135
2142
|
`Body field fallback: merging top-level param '${fieldName}' into request body`
|
|
2136
2143
|
);
|
|
2137
2144
|
} else {
|
|
2138
|
-
logger.warn(
|
|
2145
|
+
logger.warn(
|
|
2146
|
+
`Dropping unrecognized parameter ${describeText(paramName)} for tool ${tool.alias}`
|
|
2147
|
+
);
|
|
2139
2148
|
}
|
|
2140
2149
|
}
|
|
2141
2150
|
if (!isUnalteredGraphPath(path2)) {
|
|
@@ -2333,7 +2342,7 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
|
|
|
2333
2342
|
});
|
|
2334
2343
|
const { accessToken: _redacted, ...safeOptions } = options;
|
|
2335
2344
|
logger.info(
|
|
2336
|
-
`Making graph request to ${path2} with options: ${
|
|
2345
|
+
`Making graph request to ${describeUrl(path2)} [${options.method || "GET"}] with options: ${describeShape(safeOptions)}${_redacted ? " [accessToken=REDACTED]" : ""}`
|
|
2337
2346
|
);
|
|
2338
2347
|
const fetchAllPages = params.fetchAllPages === true;
|
|
2339
2348
|
const paginationEnabled = paginationAllowed();
|
|
@@ -2389,7 +2398,7 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
|
|
|
2389
2398
|
const maxItems = positiveIntFromEnv("MS365_MCP_MAX_ITEMS", DEFAULT_MAX_ITEMS);
|
|
2390
2399
|
let deltaLink = combinedResponse["@odata.deltaLink"];
|
|
2391
2400
|
while (nextLink && pageCount < maxPages && allItems.length < maxItems) {
|
|
2392
|
-
logger.info(`Fetching page ${pageCount + 1} from: ${nextLink}`);
|
|
2401
|
+
logger.info(`Fetching page ${pageCount + 1} from: ${describeUrl(nextLink)}`);
|
|
2393
2402
|
const url = new URL(nextLink);
|
|
2394
2403
|
const nextPath = url.pathname.replace(/^\/(v1\.0|beta)/, "") + url.search;
|
|
2395
2404
|
const nextOptions = { ...options };
|
|
@@ -2450,7 +2459,7 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
|
|
|
2450
2459
|
}
|
|
2451
2460
|
}
|
|
2452
2461
|
} catch (e) {
|
|
2453
|
-
logger.error(`Error during pagination: ${e}`);
|
|
2462
|
+
logger.error(`Error during pagination: ${describeError(e)}`);
|
|
2454
2463
|
}
|
|
2455
2464
|
if (combinedResponse !== void 0) {
|
|
2456
2465
|
const merged = applyMemberFilter(
|
|
@@ -2495,7 +2504,9 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
|
|
|
2495
2504
|
logger.info(`Response contains ${jsonResponse.value.length} items`);
|
|
2496
2505
|
}
|
|
2497
2506
|
if (jsonResponse["@odata.nextLink"]) {
|
|
2498
|
-
logger.info(
|
|
2507
|
+
logger.info(
|
|
2508
|
+
`Response has pagination nextLink: ${describeUrl(jsonResponse["@odata.nextLink"])}`
|
|
2509
|
+
);
|
|
2499
2510
|
}
|
|
2500
2511
|
} catch {
|
|
2501
2512
|
}
|
|
@@ -2522,7 +2533,7 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
|
|
|
2522
2533
|
};
|
|
2523
2534
|
} catch (error) {
|
|
2524
2535
|
const err = error;
|
|
2525
|
-
logger.error(`Error in tool ${tool.alias}: ${error
|
|
2536
|
+
logger.error(`Error in tool ${tool.alias}: ${describeError(error)}`);
|
|
2526
2537
|
auditLog({
|
|
2527
2538
|
event: "tool.call",
|
|
2528
2539
|
request_id: requestId,
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import winston from "winston";
|
|
4
|
+
const Transport = winston.Transport;
|
|
5
|
+
const MIN_BYTES = 1024;
|
|
6
|
+
class BoundedFileTransport extends Transport {
|
|
7
|
+
constructor(opts) {
|
|
8
|
+
super(opts);
|
|
9
|
+
this.stopped = false;
|
|
10
|
+
this.filename = opts.filename;
|
|
11
|
+
this.maxBytes = Math.max(MIN_BYTES, opts.maxBytes);
|
|
12
|
+
this.maxFiles = Math.max(1, opts.maxFiles);
|
|
13
|
+
this.mode = opts.mode ?? 384;
|
|
14
|
+
fs.mkdirSync(path.dirname(this.filename), { recursive: true, mode: 448 });
|
|
15
|
+
this.size = this.currentSize();
|
|
16
|
+
}
|
|
17
|
+
currentSize() {
|
|
18
|
+
try {
|
|
19
|
+
return fs.statSync(this.filename).size;
|
|
20
|
+
} catch {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
rotated(n) {
|
|
25
|
+
return `${this.filename}.${n}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* `<name>.<maxFiles-1>` is removed, every older file shifts up, the live file
|
|
29
|
+
* becomes `.1`. Returns false when the live file could neither be moved aside
|
|
30
|
+
* nor cut to zero.
|
|
31
|
+
*/
|
|
32
|
+
rotate() {
|
|
33
|
+
try {
|
|
34
|
+
fs.rmSync(this.rotated(this.maxFiles - 1), { force: true });
|
|
35
|
+
for (let n = this.maxFiles - 2; n >= 1; n--) {
|
|
36
|
+
if (fs.existsSync(this.rotated(n))) fs.renameSync(this.rotated(n), this.rotated(n + 1));
|
|
37
|
+
}
|
|
38
|
+
} catch {
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
if (this.maxFiles > 1 && fs.existsSync(this.filename)) {
|
|
42
|
+
fs.renameSync(this.filename, this.rotated(1));
|
|
43
|
+
} else {
|
|
44
|
+
fs.rmSync(this.filename, { force: true });
|
|
45
|
+
}
|
|
46
|
+
} catch {
|
|
47
|
+
try {
|
|
48
|
+
fs.truncateSync(this.filename, 0);
|
|
49
|
+
} catch {
|
|
50
|
+
this.size = this.currentSize();
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
this.size = this.currentSize();
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
/** A single record never exceeds the file bound; the excess is replaced by a note. */
|
|
58
|
+
fit(line) {
|
|
59
|
+
const bytes = Buffer.byteLength(line);
|
|
60
|
+
if (bytes <= this.maxBytes) return line;
|
|
61
|
+
const note = ` \u2026[${bytes - this.maxBytes} bytes dropped]
|
|
62
|
+
`;
|
|
63
|
+
const room = Math.max(0, this.maxBytes - Buffer.byteLength(note));
|
|
64
|
+
const head = Buffer.from(line).subarray(0, room).toString("utf8").replace(/�+$/, "");
|
|
65
|
+
return `${head}${note}`;
|
|
66
|
+
}
|
|
67
|
+
log(info, callback) {
|
|
68
|
+
setImmediate(() => this.emit("logged", info));
|
|
69
|
+
if (this.stopped) {
|
|
70
|
+
callback();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const line = this.fit(`${String(info[/* @__PURE__ */ Symbol.for("message")] ?? "")}
|
|
74
|
+
`);
|
|
75
|
+
const bytes = Buffer.byteLength(line);
|
|
76
|
+
if (this.size + bytes > this.maxBytes && !this.rotate()) {
|
|
77
|
+
this.stopped = true;
|
|
78
|
+
console.error(
|
|
79
|
+
`[ms365-mcp] log file ${path.basename(this.filename)} cannot be bounded; writing stopped`
|
|
80
|
+
);
|
|
81
|
+
callback();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (this.size + bytes > this.maxBytes) {
|
|
85
|
+
this.stopped = true;
|
|
86
|
+
callback();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
fs.appendFileSync(this.filename, line, { mode: this.mode, flag: "a" });
|
|
91
|
+
this.size += bytes;
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
callback();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export {
|
|
98
|
+
BoundedFileTransport
|
|
99
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function boundedInt(name, fallback) {
|
|
2
|
+
const raw = process.env[name];
|
|
3
|
+
if (raw === void 0 || raw === "") return fallback;
|
|
4
|
+
const n = Number(raw);
|
|
5
|
+
return Number.isInteger(n) && n > 0 ? n : fallback;
|
|
6
|
+
}
|
|
7
|
+
const LOG_MAX_BYTES = boundedInt("MS365_MCP_LOG_MAX_BYTES", 10 * 1024 * 1024);
|
|
8
|
+
const LOG_MAX_FILES = boundedInt("MS365_MCP_LOG_MAX_FILES", 5);
|
|
9
|
+
export {
|
|
10
|
+
LOG_MAX_BYTES,
|
|
11
|
+
LOG_MAX_FILES
|
|
12
|
+
};
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import { redactionEnabled } from "./log-redactor.js";
|
|
2
|
+
const MAX_LISTED = 40;
|
|
3
|
+
const KNOWN_PARAM_NAMES = /* @__PURE__ */ new Set([
|
|
4
|
+
"top",
|
|
5
|
+
"skip",
|
|
6
|
+
"skiptoken",
|
|
7
|
+
"search",
|
|
8
|
+
"filter",
|
|
9
|
+
"count",
|
|
10
|
+
"orderby",
|
|
11
|
+
"select",
|
|
12
|
+
"expand",
|
|
13
|
+
"fetchAllPages",
|
|
14
|
+
"includeHeaders",
|
|
15
|
+
"excludeResponse",
|
|
16
|
+
"includeHiddenMessages",
|
|
17
|
+
"confirm",
|
|
18
|
+
"timezone",
|
|
19
|
+
"expandExtendedProperties",
|
|
20
|
+
"body",
|
|
21
|
+
"rawResponse",
|
|
22
|
+
"blobOutput",
|
|
23
|
+
"forceJsonOutput",
|
|
24
|
+
"method",
|
|
25
|
+
"apiVersion",
|
|
26
|
+
"queryParams",
|
|
27
|
+
"headers",
|
|
28
|
+
"accessToken",
|
|
29
|
+
"maxChars",
|
|
30
|
+
"maxPages",
|
|
31
|
+
"maxItems",
|
|
32
|
+
"messageId",
|
|
33
|
+
"messageIds",
|
|
34
|
+
"mailFolderId",
|
|
35
|
+
"folderId",
|
|
36
|
+
"eventId",
|
|
37
|
+
"calendarId",
|
|
38
|
+
"contactId",
|
|
39
|
+
"contactFolderId",
|
|
40
|
+
"attachmentId",
|
|
41
|
+
"driveId",
|
|
42
|
+
"driveItemId",
|
|
43
|
+
"itemId",
|
|
44
|
+
"siteId",
|
|
45
|
+
"listId",
|
|
46
|
+
"userId",
|
|
47
|
+
"teamId",
|
|
48
|
+
"channelId",
|
|
49
|
+
"chatId",
|
|
50
|
+
"planId",
|
|
51
|
+
"taskId",
|
|
52
|
+
"bucketId",
|
|
53
|
+
"notebookId",
|
|
54
|
+
"sectionId",
|
|
55
|
+
"pageId",
|
|
56
|
+
"subscriptionId",
|
|
57
|
+
"target",
|
|
58
|
+
"name",
|
|
59
|
+
"contentType",
|
|
60
|
+
"If-Match",
|
|
61
|
+
"Prefer",
|
|
62
|
+
"outputFormat",
|
|
63
|
+
"skipEncoding"
|
|
64
|
+
]);
|
|
65
|
+
const KNOWN_PATH_SEGMENTS = /* @__PURE__ */ new Set([
|
|
66
|
+
"v1.0",
|
|
67
|
+
"beta",
|
|
68
|
+
"me",
|
|
69
|
+
"users",
|
|
70
|
+
"messages",
|
|
71
|
+
"mailFolders",
|
|
72
|
+
"childFolders",
|
|
73
|
+
"attachments",
|
|
74
|
+
"events",
|
|
75
|
+
"calendar",
|
|
76
|
+
"calendars",
|
|
77
|
+
"calendarView",
|
|
78
|
+
"calendarGroups",
|
|
79
|
+
"instances",
|
|
80
|
+
"contacts",
|
|
81
|
+
"contactFolders",
|
|
82
|
+
"drive",
|
|
83
|
+
"drives",
|
|
84
|
+
"items",
|
|
85
|
+
"root",
|
|
86
|
+
"children",
|
|
87
|
+
"content",
|
|
88
|
+
"thumbnails",
|
|
89
|
+
"delta",
|
|
90
|
+
"search",
|
|
91
|
+
"sites",
|
|
92
|
+
"lists",
|
|
93
|
+
"columns",
|
|
94
|
+
"contentTypes",
|
|
95
|
+
"teams",
|
|
96
|
+
"channels",
|
|
97
|
+
"chats",
|
|
98
|
+
"members",
|
|
99
|
+
"tabs",
|
|
100
|
+
"planner",
|
|
101
|
+
"plans",
|
|
102
|
+
"buckets",
|
|
103
|
+
"tasks",
|
|
104
|
+
"todo",
|
|
105
|
+
"onenote",
|
|
106
|
+
"notebooks",
|
|
107
|
+
"sections",
|
|
108
|
+
"pages",
|
|
109
|
+
"people",
|
|
110
|
+
"photo",
|
|
111
|
+
"mailboxSettings",
|
|
112
|
+
"subscriptions",
|
|
113
|
+
"outlook",
|
|
114
|
+
"masterCategories",
|
|
115
|
+
"inbox",
|
|
116
|
+
"drafts",
|
|
117
|
+
"sentitems",
|
|
118
|
+
"deleteditems",
|
|
119
|
+
"archive",
|
|
120
|
+
"junkemail",
|
|
121
|
+
"sendMail",
|
|
122
|
+
"reply",
|
|
123
|
+
"replyAll",
|
|
124
|
+
"forward",
|
|
125
|
+
"move",
|
|
126
|
+
"copy",
|
|
127
|
+
"send",
|
|
128
|
+
"createReply",
|
|
129
|
+
"createReplyAll",
|
|
130
|
+
"createForward",
|
|
131
|
+
"accept",
|
|
132
|
+
"decline",
|
|
133
|
+
"tentativelyAccept",
|
|
134
|
+
"cancel",
|
|
135
|
+
"getSchedule",
|
|
136
|
+
"findMeetingTimes",
|
|
137
|
+
"createUploadSession",
|
|
138
|
+
"invite",
|
|
139
|
+
"permissions",
|
|
140
|
+
"joinedTeams",
|
|
141
|
+
"memberOf",
|
|
142
|
+
"getMemberGroups",
|
|
143
|
+
"extensions",
|
|
144
|
+
"organization",
|
|
145
|
+
"reminderView",
|
|
146
|
+
"workbook",
|
|
147
|
+
"worksheets",
|
|
148
|
+
"tables",
|
|
149
|
+
"range",
|
|
150
|
+
"usedRange",
|
|
151
|
+
"presence",
|
|
152
|
+
"onlineMeetings",
|
|
153
|
+
"$batch",
|
|
154
|
+
"$value",
|
|
155
|
+
"$count",
|
|
156
|
+
"$ref"
|
|
157
|
+
]);
|
|
158
|
+
const KNOWN_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
159
|
+
"BadRequest",
|
|
160
|
+
"Unauthorized",
|
|
161
|
+
"Forbidden",
|
|
162
|
+
"NotFound",
|
|
163
|
+
"Conflict",
|
|
164
|
+
"TooManyRequests",
|
|
165
|
+
"ServiceUnavailable",
|
|
166
|
+
"InternalServerError",
|
|
167
|
+
"InvalidAuthenticationToken",
|
|
168
|
+
"InvalidRequest",
|
|
169
|
+
"ResourceNotFound",
|
|
170
|
+
"itemNotFound",
|
|
171
|
+
"invalidRequest",
|
|
172
|
+
"accessDenied",
|
|
173
|
+
"generalException",
|
|
174
|
+
"serviceNotAvailable",
|
|
175
|
+
"activityLimitReached",
|
|
176
|
+
"quotaLimitReached",
|
|
177
|
+
"unauthenticated",
|
|
178
|
+
"notAllowed",
|
|
179
|
+
"notSupported",
|
|
180
|
+
"nameAlreadyExists",
|
|
181
|
+
"invalidRange",
|
|
182
|
+
"malwareDetected",
|
|
183
|
+
"resyncRequired",
|
|
184
|
+
"SearchWithFilter",
|
|
185
|
+
"InefficientFilter",
|
|
186
|
+
"RequestBroker--ParseUri",
|
|
187
|
+
"ErrorAccessDenied",
|
|
188
|
+
"ErrorItemNotFound",
|
|
189
|
+
"ErrorInvalidIdMalformed",
|
|
190
|
+
"ErrorInvalidMailboxItemId",
|
|
191
|
+
"ErrorInvalidRequest",
|
|
192
|
+
"ErrorInvalidUser",
|
|
193
|
+
"ErrorInvalidRecipients",
|
|
194
|
+
"ErrorSendAsDenied",
|
|
195
|
+
"ErrorPropertyValidationFailure",
|
|
196
|
+
"ErrorInvalidPropertyRequest",
|
|
197
|
+
"ErrorMessageSizeExceeded",
|
|
198
|
+
"ErrorQuotaExceeded",
|
|
199
|
+
"ErrorMailboxNotEnabledForRESTAPI",
|
|
200
|
+
"MailboxNotEnabledForRESTAPI",
|
|
201
|
+
"ErrorInvalidOperation",
|
|
202
|
+
"ErrorObjectTypeChanged",
|
|
203
|
+
"ErrorIrresolvableConflict",
|
|
204
|
+
"ErrorInternalServerError",
|
|
205
|
+
"ErrorTimeoutExpired",
|
|
206
|
+
"ErrorServerBusy",
|
|
207
|
+
"ApplicationThrottled",
|
|
208
|
+
"MailboxConcurrency",
|
|
209
|
+
"ErrorInvalidAttachmentId",
|
|
210
|
+
"ErrorAttachmentSizeLimitExceeded",
|
|
211
|
+
"ErrorCalendarMeetingRequestIsOutOfDate",
|
|
212
|
+
"ErrorCalendarIsOrganizer",
|
|
213
|
+
"ErrorCalendarIsNotOrganizer",
|
|
214
|
+
"ErrorOccurrenceCrossingBoundary",
|
|
215
|
+
"ErrorSchemaValidation",
|
|
216
|
+
"ErrorInvalidPropertySet",
|
|
217
|
+
"invalid_grant",
|
|
218
|
+
"invalid_client",
|
|
219
|
+
"invalid_request",
|
|
220
|
+
"invalid_scope",
|
|
221
|
+
"unauthorized_client",
|
|
222
|
+
"interaction_required",
|
|
223
|
+
"consent_required",
|
|
224
|
+
"login_required",
|
|
225
|
+
"access_denied",
|
|
226
|
+
"temporarily_unavailable",
|
|
227
|
+
"ECONNRESET",
|
|
228
|
+
"ECONNREFUSED",
|
|
229
|
+
"ETIMEDOUT",
|
|
230
|
+
"ENOTFOUND",
|
|
231
|
+
"EAI_AGAIN",
|
|
232
|
+
"EPIPE",
|
|
233
|
+
"EHOSTUNREACH",
|
|
234
|
+
"ENETUNREACH",
|
|
235
|
+
"ERR_NETWORK",
|
|
236
|
+
"ERR_SOCKET_TIMEOUT",
|
|
237
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
238
|
+
"UND_ERR_HEADERS_TIMEOUT",
|
|
239
|
+
"UND_ERR_BODY_TIMEOUT",
|
|
240
|
+
"UND_ERR_SOCKET",
|
|
241
|
+
"ABORT_ERR",
|
|
242
|
+
"ERR_FR_TOO_MANY_REDIRECTS"
|
|
243
|
+
]);
|
|
244
|
+
function describeValue(value) {
|
|
245
|
+
if (value === null) return "null";
|
|
246
|
+
if (value === void 0) return "undefined";
|
|
247
|
+
if (typeof value === "string") return `string(${value.length})`;
|
|
248
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
249
|
+
if (typeof value === "boolean") return String(value);
|
|
250
|
+
if (Array.isArray(value)) return `array(${value.length})`;
|
|
251
|
+
if (typeof value === "object") return `object(${Object.keys(value).length} keys)`;
|
|
252
|
+
return typeof value;
|
|
253
|
+
}
|
|
254
|
+
function describeShape(value) {
|
|
255
|
+
if (!redactionEnabled()) return stringify(value);
|
|
256
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
257
|
+
return describeValue(value);
|
|
258
|
+
}
|
|
259
|
+
const entries = Object.entries(value);
|
|
260
|
+
const shown = [];
|
|
261
|
+
let other = 0;
|
|
262
|
+
for (const [k, v] of entries) {
|
|
263
|
+
if (KNOWN_PARAM_NAMES.has(k) && shown.length < MAX_LISTED)
|
|
264
|
+
shown.push(`${k}: ${describeValue(v)}`);
|
|
265
|
+
else other += 1;
|
|
266
|
+
}
|
|
267
|
+
if (other > 0) shown.push(`+${other} other`);
|
|
268
|
+
return `{${shown.join(", ")}}`;
|
|
269
|
+
}
|
|
270
|
+
function describeText(value) {
|
|
271
|
+
return redactionEnabled() ? `(${value.length} chars)` : value;
|
|
272
|
+
}
|
|
273
|
+
function stringify(value) {
|
|
274
|
+
try {
|
|
275
|
+
return JSON.stringify(value) ?? String(value);
|
|
276
|
+
} catch (error) {
|
|
277
|
+
return `[unserializable: ${error instanceof Error ? error.name : "unknown error"}]`;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function serializedSize(value) {
|
|
281
|
+
try {
|
|
282
|
+
return Buffer.byteLength(JSON.stringify(value) ?? "");
|
|
283
|
+
} catch {
|
|
284
|
+
return -1;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function describeUrl(url) {
|
|
288
|
+
if (typeof url !== "string") return typeof url;
|
|
289
|
+
if (!redactionEnabled()) return url;
|
|
290
|
+
let origin = "";
|
|
291
|
+
let rest = url;
|
|
292
|
+
const schemeEnd = url.indexOf("://");
|
|
293
|
+
if (schemeEnd > 0) {
|
|
294
|
+
const pathStart = url.indexOf("/", schemeEnd + 3);
|
|
295
|
+
origin = pathStart === -1 ? url : url.slice(0, pathStart);
|
|
296
|
+
rest = pathStart === -1 ? "" : url.slice(pathStart);
|
|
297
|
+
}
|
|
298
|
+
const q = rest.indexOf("?");
|
|
299
|
+
const pathPart = q === -1 ? rest : rest.slice(0, q);
|
|
300
|
+
const queryPart = q === -1 ? "" : rest.slice(q + 1);
|
|
301
|
+
const segments = pathPart.split("/").map((s) => {
|
|
302
|
+
if (s === "") return "";
|
|
303
|
+
const bare = s.endsWith(":") ? s.slice(0, -1) : s;
|
|
304
|
+
return KNOWN_PATH_SEGMENTS.has(bare) ? s : "{\u2026}";
|
|
305
|
+
});
|
|
306
|
+
let out = `${/^https?:\/\/[A-Za-z0-9.-]+(:\d+)?$/.test(origin) ? origin : origin ? "{origin}" : ""}${segments.join("/")}`;
|
|
307
|
+
if (queryPart) {
|
|
308
|
+
const names = [];
|
|
309
|
+
let other = 0;
|
|
310
|
+
for (const part of queryPart.split("&")) {
|
|
311
|
+
const name = part.split("=")[0];
|
|
312
|
+
if (!name) continue;
|
|
313
|
+
if (KNOWN_QUERY_NAMES.has(name)) {
|
|
314
|
+
if (!names.includes(name)) names.push(name);
|
|
315
|
+
} else other += 1;
|
|
316
|
+
}
|
|
317
|
+
const list = names.join(", ") + (other ? `${names.length ? ", " : ""}+${other} other` : "");
|
|
318
|
+
out += ` [query: ${list}]`;
|
|
319
|
+
}
|
|
320
|
+
return out;
|
|
321
|
+
}
|
|
322
|
+
const KNOWN_QUERY_NAMES = /* @__PURE__ */ new Set([
|
|
323
|
+
"$select",
|
|
324
|
+
"$filter",
|
|
325
|
+
"$search",
|
|
326
|
+
"$top",
|
|
327
|
+
"$skip",
|
|
328
|
+
"$skiptoken",
|
|
329
|
+
"$orderby",
|
|
330
|
+
"$count",
|
|
331
|
+
"$expand",
|
|
332
|
+
"$format",
|
|
333
|
+
"$deltatoken",
|
|
334
|
+
"$ref",
|
|
335
|
+
"$value",
|
|
336
|
+
"$batch",
|
|
337
|
+
"$metadata"
|
|
338
|
+
]);
|
|
339
|
+
const KNOWN_ERROR_NAMES = /* @__PURE__ */ new Set([
|
|
340
|
+
"Error",
|
|
341
|
+
"TypeError",
|
|
342
|
+
"RangeError",
|
|
343
|
+
"SyntaxError",
|
|
344
|
+
"AbortError",
|
|
345
|
+
"TimeoutError",
|
|
346
|
+
"GraphApiError",
|
|
347
|
+
"OAuthUpstreamError",
|
|
348
|
+
"FetchError",
|
|
349
|
+
"AggregateError",
|
|
350
|
+
"DOMException",
|
|
351
|
+
"TicketStoreFullError",
|
|
352
|
+
"ClientAuthError",
|
|
353
|
+
"ServerError",
|
|
354
|
+
"InteractionRequiredAuthError",
|
|
355
|
+
"AuthError",
|
|
356
|
+
"BrowserAuthError"
|
|
357
|
+
]);
|
|
358
|
+
function describeError(error) {
|
|
359
|
+
return errorText(error, !redactionEnabled());
|
|
360
|
+
}
|
|
361
|
+
function summarizeError(error) {
|
|
362
|
+
return errorText(error, false);
|
|
363
|
+
}
|
|
364
|
+
function errorText(error, full) {
|
|
365
|
+
if (!(error instanceof Error)) return full ? stringify(error) : `non-error(${typeof error})`;
|
|
366
|
+
const e = error;
|
|
367
|
+
const parts = [full || KNOWN_ERROR_NAMES.has(e.name) ? e.name || "Error" : "Error"];
|
|
368
|
+
const status = [e.httpStatus, e.status].find(
|
|
369
|
+
(s) => Number.isInteger(s) && s >= 100 && s <= 599
|
|
370
|
+
);
|
|
371
|
+
if (status !== void 0) parts.push(`status=${status}`);
|
|
372
|
+
const code = [e.graphErrorCode, e.code, e.errorCode].find((c) => c !== void 0 && c !== null);
|
|
373
|
+
if (typeof code === "number" && Number.isInteger(code)) parts.push(`code=${code}`);
|
|
374
|
+
else if (typeof code === "string") {
|
|
375
|
+
parts.push(
|
|
376
|
+
full || KNOWN_ERROR_CODES.has(code) ? `code=${code}` : `code=unlisted(${code.length})`
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
const summary = parts.join(" ");
|
|
380
|
+
return full && e.message ? `${summary}: ${e.message}` : summary;
|
|
381
|
+
}
|
|
382
|
+
const FRAME = /^at (?:[\w$.<>[\] ]+ \()?(?:node:[\w/]+|file:\/\/\S+|[A-Za-z]:\\\S+|\/\S+):\d+:\d+\)?$/;
|
|
383
|
+
function describeStack(error) {
|
|
384
|
+
if (!(error instanceof Error) || typeof error.stack !== "string") return [];
|
|
385
|
+
let tail = error.stack;
|
|
386
|
+
const message = typeof error.message === "string" ? error.message : "";
|
|
387
|
+
if (message.length > 0) {
|
|
388
|
+
const at = tail.indexOf(message);
|
|
389
|
+
if (at === -1) return [];
|
|
390
|
+
tail = tail.slice(at + message.length);
|
|
391
|
+
} else {
|
|
392
|
+
const nl = tail.indexOf("\n");
|
|
393
|
+
tail = nl === -1 ? "" : tail.slice(nl);
|
|
394
|
+
}
|
|
395
|
+
return tail.split("\n").map((l) => l.trim()).filter((l) => FRAME.test(l)).slice(0, 20);
|
|
396
|
+
}
|
|
397
|
+
export {
|
|
398
|
+
describeError,
|
|
399
|
+
describeShape,
|
|
400
|
+
describeStack,
|
|
401
|
+
describeText,
|
|
402
|
+
describeUrl,
|
|
403
|
+
serializedSize,
|
|
404
|
+
summarizeError
|
|
405
|
+
};
|