@mcp-z/mcp-outlook 2.4.2 → 2.4.3

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 (37) hide show
  1. package/dist/cjs/email/querying/next-link.d.cts +5 -0
  2. package/dist/cjs/email/querying/next-link.d.ts +5 -0
  3. package/dist/cjs/email/querying/next-link.js +30 -0
  4. package/dist/cjs/email/querying/next-link.js.map +1 -0
  5. package/dist/cjs/email/querying/pagination-token.d.cts +3 -4
  6. package/dist/cjs/email/querying/pagination-token.d.ts +3 -4
  7. package/dist/cjs/email/querying/pagination-token.js +71 -49
  8. package/dist/cjs/email/querying/pagination-token.js.map +1 -1
  9. package/dist/cjs/email/querying/paging-decisions.d.cts +14 -0
  10. package/dist/cjs/email/querying/paging-decisions.d.ts +14 -0
  11. package/dist/cjs/email/querying/paging-decisions.js +91 -0
  12. package/dist/cjs/email/querying/paging-decisions.js.map +1 -0
  13. package/dist/cjs/email/querying/search-execution.js +130 -88
  14. package/dist/cjs/email/querying/search-execution.js.map +1 -1
  15. package/dist/cjs/mcp/tools/message-search.d.cts +1 -1
  16. package/dist/cjs/mcp/tools/message-search.d.ts +1 -1
  17. package/dist/cjs/mcp/tools/message-search.js +1 -1
  18. package/dist/cjs/mcp/tools/message-search.js.map +1 -1
  19. package/dist/cjs/mcp/tools/messages-export-csv.js +10 -6
  20. package/dist/cjs/mcp/tools/messages-export-csv.js.map +1 -1
  21. package/dist/esm/email/querying/next-link.d.ts +5 -0
  22. package/dist/esm/email/querying/next-link.js +22 -0
  23. package/dist/esm/email/querying/next-link.js.map +1 -0
  24. package/dist/esm/email/querying/pagination-token.d.ts +3 -4
  25. package/dist/esm/email/querying/pagination-token.js +22 -44
  26. package/dist/esm/email/querying/pagination-token.js.map +1 -1
  27. package/dist/esm/email/querying/paging-decisions.d.ts +14 -0
  28. package/dist/esm/email/querying/paging-decisions.js +21 -0
  29. package/dist/esm/email/querying/paging-decisions.js.map +1 -0
  30. package/dist/esm/email/querying/search-execution.js +82 -77
  31. package/dist/esm/email/querying/search-execution.js.map +1 -1
  32. package/dist/esm/mcp/tools/message-search.d.ts +1 -1
  33. package/dist/esm/mcp/tools/message-search.js +1 -1
  34. package/dist/esm/mcp/tools/message-search.js.map +1 -1
  35. package/dist/esm/mcp/tools/messages-export-csv.js +10 -6
  36. package/dist/esm/mcp/tools/messages-export-csv.js.map +1 -1
  37. package/package.json +1 -1
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Check an `@odata.nextLink` and return its path and query after the version (`/me/messages?...`),
3
+ * as the URL parser writes them. Microsoft says to follow the whole link and not to rebuild it, so nothing is decoded or reordered.
4
+ */
5
+ export declare function checkNextLink(link: string): string;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Check an `@odata.nextLink` and return its path and query after the version (`/me/messages?...`),
3
+ * as the URL parser writes them. Microsoft says to follow the whole link and not to rebuild it, so nothing is decoded or reordered.
4
+ */
5
+ export declare function checkNextLink(link: string): string;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "checkNextLink", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return checkNextLink;
9
+ }
10
+ });
11
+ var _server = require("@mcp-z/server");
12
+ var GRAPH_HOST = 'graph.microsoft.com';
13
+ var GRAPH_VERSION_PATH = '/v1.0';
14
+ var MESSAGES_PATH = "".concat(GRAPH_VERSION_PATH, "/me/messages");
15
+ function refuse(reason) {
16
+ throw new _server.ProtocolError(_server.ProtocolErrorCode.InternalError, "Microsoft Graph returned a next-page link that cannot be followed (".concat(reason, "); results would be incomplete"));
17
+ }
18
+ function checkNextLink(link) {
19
+ var url;
20
+ try {
21
+ url = new URL(link);
22
+ } catch (unused) {
23
+ return refuse('not a URL');
24
+ }
25
+ if (url.protocol !== 'https:') return refuse("scheme ".concat(url.protocol.slice(0, -1)));
26
+ if (url.host !== GRAPH_HOST) return refuse("host ".concat(url.host));
27
+ if (url.pathname !== MESSAGES_PATH) return refuse("path ".concat(url.pathname));
28
+ return url.pathname.slice(GRAPH_VERSION_PATH.length) + url.search;
29
+ }
30
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-outlook/src/email/querying/next-link.ts"],"sourcesContent":["import { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\n\nconst GRAPH_HOST = 'graph.microsoft.com';\nconst GRAPH_VERSION_PATH = '/v1.0';\nconst MESSAGES_PATH = `${GRAPH_VERSION_PATH}/me/messages`;\n\nfunction refuse(reason: string): never {\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Microsoft Graph returned a next-page link that cannot be followed (${reason}); results would be incomplete`);\n}\n\n/**\n * Check an `@odata.nextLink` and return its path and query after the version (`/me/messages?...`),\n * as the URL parser writes them. Microsoft says to follow the whole link and not to rebuild it, so nothing is decoded or reordered.\n */\nexport function checkNextLink(link: string): string {\n let url: URL;\n try {\n url = new URL(link);\n } catch {\n return refuse('not a URL');\n }\n if (url.protocol !== 'https:') return refuse(`scheme ${url.protocol.slice(0, -1)}`);\n if (url.host !== GRAPH_HOST) return refuse(`host ${url.host}`);\n if (url.pathname !== MESSAGES_PATH) return refuse(`path ${url.pathname}`);\n return url.pathname.slice(GRAPH_VERSION_PATH.length) + url.search;\n}\n"],"names":["checkNextLink","GRAPH_HOST","GRAPH_VERSION_PATH","MESSAGES_PATH","refuse","reason","ProtocolError","ProtocolErrorCode","InternalError","link","url","URL","protocol","slice","host","pathname","length","search"],"mappings":";;;;+BAcgBA;;;eAAAA;;;sBAdiC;AAEjD,IAAMC,aAAa;AACnB,IAAMC,qBAAqB;AAC3B,IAAMC,gBAAgB,AAAC,GAAqB,OAAnBD,oBAAmB;AAE5C,SAASE,OAAOC,MAAc;IAC5B,MAAM,IAAIC,qBAAa,CAACC,yBAAiB,CAACC,aAAa,EAAE,AAAC,sEAA4E,OAAPH,QAAO;AACxI;AAMO,SAASL,cAAcS,IAAY;IACxC,IAAIC;IACJ,IAAI;QACFA,MAAM,IAAIC,IAAIF;IAChB,EAAE,eAAM;QACN,OAAOL,OAAO;IAChB;IACA,IAAIM,IAAIE,QAAQ,KAAK,UAAU,OAAOR,OAAO,AAAC,UAAmC,OAA1BM,IAAIE,QAAQ,CAACC,KAAK,CAAC,GAAG,CAAC;IAC9E,IAAIH,IAAII,IAAI,KAAKb,YAAY,OAAOG,OAAO,AAAC,QAAgB,OAATM,IAAII,IAAI;IAC3D,IAAIJ,IAAIK,QAAQ,KAAKZ,eAAe,OAAOC,OAAO,AAAC,QAAoB,OAAbM,IAAIK,QAAQ;IACtE,OAAOL,IAAIK,QAAQ,CAACF,KAAK,CAACX,mBAAmBc,MAAM,IAAIN,IAAIO,MAAM;AACnE"}
@@ -1,12 +1,11 @@
1
- export declare const FIRST_PAGE_SKIP_TOKEN = "__mcp_outlook_first_page__";
2
1
  export interface DecodeNextPageTokenResult {
3
- skipToken?: string;
2
+ /** Path and query of the Graph next-page link that fetches the page, absent for the first page. */
3
+ link?: string;
4
4
  offset: number;
5
5
  mode?: string;
6
- legacy: boolean;
7
6
  }
8
7
  export declare function encodeNextPageToken(params: {
9
- skipToken?: string;
8
+ link?: string;
10
9
  offset: number;
11
10
  mode?: string;
12
11
  }): string;
@@ -1,12 +1,11 @@
1
- export declare const FIRST_PAGE_SKIP_TOKEN = "__mcp_outlook_first_page__";
2
1
  export interface DecodeNextPageTokenResult {
3
- skipToken?: string;
2
+ /** Path and query of the Graph next-page link that fetches the page, absent for the first page. */
3
+ link?: string;
4
4
  offset: number;
5
5
  mode?: string;
6
- legacy: boolean;
7
6
  }
8
7
  export declare function encodeNextPageToken(params: {
9
- skipToken?: string;
8
+ link?: string;
10
9
  offset: number;
11
10
  mode?: string;
12
11
  }): string;
@@ -9,9 +9,6 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- get FIRST_PAGE_SKIP_TOKEN () {
13
- return FIRST_PAGE_SKIP_TOKEN;
14
- },
15
12
  get decodeNextPageToken () {
16
13
  return decodeNextPageToken;
17
14
  },
@@ -20,62 +17,87 @@ _export(exports, {
20
17
  }
21
18
  });
22
19
  var _server = require("@mcp-z/server");
23
- var PREFIX = 'v2:';
24
- var FIRST_PAGE_SKIP_TOKEN = '__mcp_outlook_first_page__';
20
+ function _define_property(obj, key, value) {
21
+ if (key in obj) {
22
+ Object.defineProperty(obj, key, {
23
+ value: value,
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true
27
+ });
28
+ } else obj[key] = value;
29
+ return obj;
30
+ }
31
+ function _object_spread(target) {
32
+ for(var i = 1; i < arguments.length; i++){
33
+ var source = arguments[i] != null ? arguments[i] : {};
34
+ var ownKeys = Object.keys(source);
35
+ if (typeof Object.getOwnPropertySymbols === "function") {
36
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
37
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
38
+ }));
39
+ }
40
+ ownKeys.forEach(function(key) {
41
+ _define_property(target, key, source[key]);
42
+ });
43
+ }
44
+ return target;
45
+ }
46
+ function ownKeys(object, enumerableOnly) {
47
+ var keys = Object.keys(object);
48
+ if (Object.getOwnPropertySymbols) {
49
+ var symbols = Object.getOwnPropertySymbols(object);
50
+ if (enumerableOnly) {
51
+ symbols = symbols.filter(function(sym) {
52
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
53
+ });
54
+ }
55
+ keys.push.apply(keys, symbols);
56
+ }
57
+ return keys;
58
+ }
59
+ function _object_spread_props(target, source) {
60
+ source = source != null ? source : {};
61
+ if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
62
+ else {
63
+ ownKeys(Object(source)).forEach(function(key) {
64
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
65
+ });
66
+ }
67
+ return target;
68
+ }
69
+ var PREFIX = 'v3:';
25
70
  function encodeNextPageToken(params) {
26
- var _params_skipToken;
27
- var sanitizedOffset = Math.max(0, Math.trunc(params.offset));
28
71
  var payload = {
29
- v: 2,
30
- skipToken: (_params_skipToken = params.skipToken) !== null && _params_skipToken !== void 0 ? _params_skipToken : FIRST_PAGE_SKIP_TOKEN,
31
- offset: sanitizedOffset
72
+ v: 3,
73
+ offset: Math.max(0, Math.trunc(params.offset))
32
74
  };
33
- if (typeof params.mode === 'string' && params.mode.length > 0) {
34
- payload.mode = params.mode;
35
- }
36
- var serialized = JSON.stringify(payload);
37
- return "".concat(PREFIX).concat(base64UrlEncode(serialized));
75
+ if (params.link) payload.link = params.link;
76
+ if (typeof params.mode === 'string' && params.mode.length > 0) payload.mode = params.mode;
77
+ return "".concat(PREFIX).concat(Buffer.from(JSON.stringify(payload), 'utf8').toString('base64url'));
38
78
  }
39
79
  function decodeNextPageToken(token) {
40
- if (!token) {
41
- return {
42
- offset: 0,
43
- legacy: true
44
- };
45
- }
80
+ if (!token) return {
81
+ offset: 0
82
+ };
46
83
  if (!token.startsWith(PREFIX)) {
47
- return {
48
- skipToken: token,
49
- offset: 0,
50
- legacy: true
51
- };
84
+ throw new _server.ProtocolError(_server.ProtocolErrorCode.InvalidParams, 'pageToken was issued by an earlier mcp-outlook version and cannot be used; repeat the search without pageToken');
52
85
  }
53
- var encoded = token.slice(PREFIX.length);
54
86
  try {
55
- var decodedJson = base64UrlDecode(encoded);
56
- var parsed = JSON.parse(decodedJson);
57
- if (parsed.v !== 2) throw new Error('unsupported token version');
58
- var skipTokenRaw = parsed.skipToken;
59
- var offsetRaw = parsed.offset;
60
- if (typeof skipTokenRaw !== 'string' || skipTokenRaw.trim() === '') throw new Error('missing skipToken');
61
- if (typeof offsetRaw !== 'number' || !Number.isInteger(offsetRaw) || offsetRaw < 0) throw new Error('invalid offset');
62
- return {
63
- skipToken: skipTokenRaw === FIRST_PAGE_SKIP_TOKEN ? undefined : skipTokenRaw,
64
- offset: offsetRaw,
65
- mode: typeof parsed.mode === 'string' ? parsed.mode : undefined,
66
- legacy: false
67
- };
87
+ var parsed = JSON.parse(Buffer.from(token.slice(PREFIX.length), 'base64url').toString('utf8'));
88
+ if (parsed.v !== 3) throw new Error('unsupported token version');
89
+ var link = parsed.link, offset = parsed.offset, mode = parsed.mode;
90
+ if (link !== undefined && (typeof link !== 'string' || link === '')) throw new Error('invalid link');
91
+ if (typeof offset !== 'number' || !Number.isInteger(offset) || offset < 0) throw new Error('invalid offset');
92
+ return _object_spread(_object_spread_props(_object_spread({}, typeof link === 'string' && {
93
+ link: link
94
+ }), {
95
+ offset: offset
96
+ }), typeof mode === 'string' && {
97
+ mode: mode
98
+ });
68
99
  } catch (unused) {
69
100
  throw new _server.ProtocolError(_server.ProtocolErrorCode.InvalidParams, 'Invalid pageToken');
70
101
  }
71
102
  }
72
- function base64UrlEncode(value) {
73
- return Buffer.from(value, 'utf8').toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
74
- }
75
- function base64UrlDecode(value) {
76
- var padded = value.replace(/-/g, '+').replace(/_/g, '/');
77
- var padLength = (4 - padded.length % 4) % 4;
78
- var normalized = padded + '='.repeat(padLength);
79
- return Buffer.from(normalized, 'base64').toString('utf8');
80
- }
81
103
  /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-outlook/src/email/querying/pagination-token.ts"],"sourcesContent":["import { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\n\nconst PREFIX = 'v2:';\nexport const FIRST_PAGE_SKIP_TOKEN = '__mcp_outlook_first_page__';\n\ninterface V2Payload {\n v: 2;\n skipToken: string;\n offset: number;\n mode?: string;\n}\n\nexport interface DecodeNextPageTokenResult {\n skipToken?: string;\n offset: number;\n mode?: string;\n legacy: boolean;\n}\n\nexport function encodeNextPageToken(params: { skipToken?: string; offset: number; mode?: string }): string {\n const sanitizedOffset = Math.max(0, Math.trunc(params.offset));\n const payload: V2Payload = {\n v: 2,\n skipToken: params.skipToken ?? FIRST_PAGE_SKIP_TOKEN,\n offset: sanitizedOffset,\n };\n if (typeof params.mode === 'string' && params.mode.length > 0) {\n payload.mode = params.mode;\n }\n const serialized = JSON.stringify(payload);\n return `${PREFIX}${base64UrlEncode(serialized)}`;\n}\n\nexport function decodeNextPageToken(token: string | undefined): DecodeNextPageTokenResult {\n if (!token) {\n return { offset: 0, legacy: true };\n }\n\n if (!token.startsWith(PREFIX)) {\n return { skipToken: token, offset: 0, legacy: true };\n }\n\n const encoded = token.slice(PREFIX.length);\n try {\n const decodedJson = base64UrlDecode(encoded);\n const parsed = JSON.parse(decodedJson) as Record<string, unknown>;\n if (parsed.v !== 2) throw new Error('unsupported token version');\n const skipTokenRaw = parsed.skipToken;\n const offsetRaw = parsed.offset;\n if (typeof skipTokenRaw !== 'string' || skipTokenRaw.trim() === '') throw new Error('missing skipToken');\n if (typeof offsetRaw !== 'number' || !Number.isInteger(offsetRaw) || offsetRaw < 0) throw new Error('invalid offset');\n\n return {\n skipToken: skipTokenRaw === FIRST_PAGE_SKIP_TOKEN ? undefined : skipTokenRaw,\n offset: offsetRaw,\n mode: typeof parsed.mode === 'string' ? parsed.mode : undefined,\n legacy: false,\n };\n } catch {\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, 'Invalid pageToken');\n }\n}\n\nfunction base64UrlEncode(value: string): string {\n return Buffer.from(value, 'utf8').toString('base64').replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '');\n}\n\nfunction base64UrlDecode(value: string): string {\n const padded = value.replace(/-/g, '+').replace(/_/g, '/');\n const padLength = (4 - (padded.length % 4)) % 4;\n const normalized = padded + '='.repeat(padLength);\n return Buffer.from(normalized, 'base64').toString('utf8');\n}\n"],"names":["FIRST_PAGE_SKIP_TOKEN","decodeNextPageToken","encodeNextPageToken","PREFIX","params","sanitizedOffset","Math","max","trunc","offset","payload","v","skipToken","mode","length","serialized","JSON","stringify","base64UrlEncode","token","legacy","startsWith","encoded","slice","decodedJson","base64UrlDecode","parsed","parse","Error","skipTokenRaw","offsetRaw","trim","Number","isInteger","undefined","ProtocolError","ProtocolErrorCode","InvalidParams","value","Buffer","from","toString","replace","padded","padLength","normalized","repeat"],"mappings":";;;;;;;;;;;QAGaA;eAAAA;;QA8BGC;eAAAA;;QAdAC;eAAAA;;;sBAnBiC;AAEjD,IAAMC,SAAS;AACR,IAAMH,wBAAwB;AAgB9B,SAASE,oBAAoBE,MAA6D;QAIlFA;IAHb,IAAMC,kBAAkBC,KAAKC,GAAG,CAAC,GAAGD,KAAKE,KAAK,CAACJ,OAAOK,MAAM;IAC5D,IAAMC,UAAqB;QACzBC,GAAG;QACHC,SAAS,GAAER,oBAAAA,OAAOQ,SAAS,cAAhBR,+BAAAA,oBAAoBJ;QAC/BS,QAAQJ;IACV;IACA,IAAI,OAAOD,OAAOS,IAAI,KAAK,YAAYT,OAAOS,IAAI,CAACC,MAAM,GAAG,GAAG;QAC7DJ,QAAQG,IAAI,GAAGT,OAAOS,IAAI;IAC5B;IACA,IAAME,aAAaC,KAAKC,SAAS,CAACP;IAClC,OAAO,AAAC,GAAWQ,OAATf,QAAqC,OAA5Be,gBAAgBH;AACrC;AAEO,SAASd,oBAAoBkB,KAAyB;IAC3D,IAAI,CAACA,OAAO;QACV,OAAO;YAAEV,QAAQ;YAAGW,QAAQ;QAAK;IACnC;IAEA,IAAI,CAACD,MAAME,UAAU,CAAClB,SAAS;QAC7B,OAAO;YAAES,WAAWO;YAAOV,QAAQ;YAAGW,QAAQ;QAAK;IACrD;IAEA,IAAME,UAAUH,MAAMI,KAAK,CAACpB,OAAOW,MAAM;IACzC,IAAI;QACF,IAAMU,cAAcC,gBAAgBH;QACpC,IAAMI,SAASV,KAAKW,KAAK,CAACH;QAC1B,IAAIE,OAAOf,CAAC,KAAK,GAAG,MAAM,IAAIiB,MAAM;QACpC,IAAMC,eAAeH,OAAOd,SAAS;QACrC,IAAMkB,YAAYJ,OAAOjB,MAAM;QAC/B,IAAI,OAAOoB,iBAAiB,YAAYA,aAAaE,IAAI,OAAO,IAAI,MAAM,IAAIH,MAAM;QACpF,IAAI,OAAOE,cAAc,YAAY,CAACE,OAAOC,SAAS,CAACH,cAAcA,YAAY,GAAG,MAAM,IAAIF,MAAM;QAEpG,OAAO;YACLhB,WAAWiB,iBAAiB7B,wBAAwBkC,YAAYL;YAChEpB,QAAQqB;YACRjB,MAAM,OAAOa,OAAOb,IAAI,KAAK,WAAWa,OAAOb,IAAI,GAAGqB;YACtDd,QAAQ;QACV;IACF,EAAE,eAAM;QACN,MAAM,IAAIe,qBAAa,CAACC,yBAAiB,CAACC,aAAa,EAAE;IAC3D;AACF;AAEA,SAASnB,gBAAgBoB,KAAa;IACpC,OAAOC,OAAOC,IAAI,CAACF,OAAO,QAAQG,QAAQ,CAAC,UAAUC,OAAO,CAAC,OAAO,KAAKA,OAAO,CAAC,OAAO,KAAKA,OAAO,CAAC,OAAO;AAC9G;AAEA,SAASjB,gBAAgBa,KAAa;IACpC,IAAMK,SAASL,MAAMI,OAAO,CAAC,MAAM,KAAKA,OAAO,CAAC,MAAM;IACtD,IAAME,YAAY,AAAC,CAAA,IAAKD,OAAO7B,MAAM,GAAG,CAAC,IAAK;IAC9C,IAAM+B,aAAaF,SAAS,IAAIG,MAAM,CAACF;IACvC,OAAOL,OAAOC,IAAI,CAACK,YAAY,UAAUJ,QAAQ,CAAC;AACpD"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-outlook/src/email/querying/pagination-token.ts"],"sourcesContent":["import { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\n\nconst PREFIX = 'v3:';\n\ninterface V3Payload {\n v: 3;\n link?: string;\n offset: number;\n mode?: string;\n}\n\nexport interface DecodeNextPageTokenResult {\n /** Path and query of the Graph next-page link that fetches the page, absent for the first page. */\n link?: string;\n offset: number;\n mode?: string;\n}\n\nexport function encodeNextPageToken(params: { link?: string; offset: number; mode?: string }): string {\n const payload: V3Payload = { v: 3, offset: Math.max(0, Math.trunc(params.offset)) };\n if (params.link) payload.link = params.link;\n if (typeof params.mode === 'string' && params.mode.length > 0) payload.mode = params.mode;\n return `${PREFIX}${Buffer.from(JSON.stringify(payload), 'utf8').toString('base64url')}`;\n}\n\nexport function decodeNextPageToken(token: string | undefined): DecodeNextPageTokenResult {\n if (!token) return { offset: 0 };\n\n if (!token.startsWith(PREFIX)) {\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, 'pageToken was issued by an earlier mcp-outlook version and cannot be used; repeat the search without pageToken');\n }\n\n try {\n const parsed = JSON.parse(Buffer.from(token.slice(PREFIX.length), 'base64url').toString('utf8')) as Record<string, unknown>;\n if (parsed.v !== 3) throw new Error('unsupported token version');\n const { link, offset, mode } = parsed;\n if (link !== undefined && (typeof link !== 'string' || link === '')) throw new Error('invalid link');\n if (typeof offset !== 'number' || !Number.isInteger(offset) || offset < 0) throw new Error('invalid offset');\n return {\n ...(typeof link === 'string' && { link }),\n offset,\n ...(typeof mode === 'string' && { mode }),\n };\n } catch {\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, 'Invalid pageToken');\n }\n}\n"],"names":["decodeNextPageToken","encodeNextPageToken","PREFIX","params","payload","v","offset","Math","max","trunc","link","mode","length","Buffer","from","JSON","stringify","toString","token","startsWith","ProtocolError","ProtocolErrorCode","InvalidParams","parsed","parse","slice","Error","undefined","Number","isInteger"],"mappings":";;;;;;;;;;;QAyBgBA;eAAAA;;QAPAC;eAAAA;;;sBAlBiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEjD,IAAMC,SAAS;AAgBR,SAASD,oBAAoBE,MAAwD;IAC1F,IAAMC,UAAqB;QAAEC,GAAG;QAAGC,QAAQC,KAAKC,GAAG,CAAC,GAAGD,KAAKE,KAAK,CAACN,OAAOG,MAAM;IAAG;IAClF,IAAIH,OAAOO,IAAI,EAAEN,QAAQM,IAAI,GAAGP,OAAOO,IAAI;IAC3C,IAAI,OAAOP,OAAOQ,IAAI,KAAK,YAAYR,OAAOQ,IAAI,CAACC,MAAM,GAAG,GAAGR,QAAQO,IAAI,GAAGR,OAAOQ,IAAI;IACzF,OAAO,AAAC,GAAWE,OAATX,QAA4E,OAAnEW,OAAOC,IAAI,CAACC,KAAKC,SAAS,CAACZ,UAAU,QAAQa,QAAQ,CAAC;AAC3E;AAEO,SAASjB,oBAAoBkB,KAAyB;IAC3D,IAAI,CAACA,OAAO,OAAO;QAAEZ,QAAQ;IAAE;IAE/B,IAAI,CAACY,MAAMC,UAAU,CAACjB,SAAS;QAC7B,MAAM,IAAIkB,qBAAa,CAACC,yBAAiB,CAACC,aAAa,EAAE;IAC3D;IAEA,IAAI;QACF,IAAMC,SAASR,KAAKS,KAAK,CAACX,OAAOC,IAAI,CAACI,MAAMO,KAAK,CAACvB,OAAOU,MAAM,GAAG,aAAaK,QAAQ,CAAC;QACxF,IAAIM,OAAOlB,CAAC,KAAK,GAAG,MAAM,IAAIqB,MAAM;QACpC,IAAQhB,OAAuBa,OAAvBb,MAAMJ,SAAiBiB,OAAjBjB,QAAQK,OAASY,OAATZ;QACtB,IAAID,SAASiB,aAAc,CAAA,OAAOjB,SAAS,YAAYA,SAAS,EAAC,GAAI,MAAM,IAAIgB,MAAM;QACrF,IAAI,OAAOpB,WAAW,YAAY,CAACsB,OAAOC,SAAS,CAACvB,WAAWA,SAAS,GAAG,MAAM,IAAIoB,MAAM;QAC3F,OAAO,uDACD,OAAOhB,SAAS,YAAY;YAAEA,MAAAA;QAAK;YACvCJ,QAAAA;YACI,OAAOK,SAAS,YAAY;YAAEA,MAAAA;QAAK;IAE3C,EAAE,eAAM;QACN,MAAM,IAAIS,qBAAa,CAACC,yBAAiB,CAACC,aAAa,EAAE;IAC3D;AACF"}
@@ -0,0 +1,14 @@
1
+ /** Token that resumes inside the page fetched by `link`, one message past the last one taken. */
2
+ export declare function midPageToken(params: {
3
+ link?: string;
4
+ pageStart: number;
5
+ index: number;
6
+ mode: 'search' | 'filter';
7
+ }): string;
8
+ /** Which collection a page token resumes: a fallback-filter token resumes the filter collection, anything else the search. */
9
+ export declare function resumeCollection(mode: string | undefined): 'search' | 'filter';
10
+ /** Cut a batch to what still fits under maxItems; truncated when rows were cut or a link remains at the limit. */
11
+ export declare function cutToMaxItems<T>(rows: T[], taken: number, maxItems: number, hasMore: boolean): {
12
+ rows: T[];
13
+ truncated: boolean;
14
+ };
@@ -0,0 +1,14 @@
1
+ /** Token that resumes inside the page fetched by `link`, one message past the last one taken. */
2
+ export declare function midPageToken(params: {
3
+ link?: string;
4
+ pageStart: number;
5
+ index: number;
6
+ mode: 'search' | 'filter';
7
+ }): string;
8
+ /** Which collection a page token resumes: a fallback-filter token resumes the filter collection, anything else the search. */
9
+ export declare function resumeCollection(mode: string | undefined): 'search' | 'filter';
10
+ /** Cut a batch to what still fits under maxItems; truncated when rows were cut or a link remains at the limit. */
11
+ export declare function cutToMaxItems<T>(rows: T[], taken: number, maxItems: number, hasMore: boolean): {
12
+ rows: T[];
13
+ truncated: boolean;
14
+ };
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get cutToMaxItems () {
13
+ return cutToMaxItems;
14
+ },
15
+ get midPageToken () {
16
+ return midPageToken;
17
+ },
18
+ get resumeCollection () {
19
+ return resumeCollection;
20
+ }
21
+ });
22
+ var _paginationtokents = require("./pagination-token.js");
23
+ function _define_property(obj, key, value) {
24
+ if (key in obj) {
25
+ Object.defineProperty(obj, key, {
26
+ value: value,
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true
30
+ });
31
+ } else obj[key] = value;
32
+ return obj;
33
+ }
34
+ function _object_spread(target) {
35
+ for(var i = 1; i < arguments.length; i++){
36
+ var source = arguments[i] != null ? arguments[i] : {};
37
+ var ownKeys = Object.keys(source);
38
+ if (typeof Object.getOwnPropertySymbols === "function") {
39
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
40
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
41
+ }));
42
+ }
43
+ ownKeys.forEach(function(key) {
44
+ _define_property(target, key, source[key]);
45
+ });
46
+ }
47
+ return target;
48
+ }
49
+ function ownKeys(object, enumerableOnly) {
50
+ var keys = Object.keys(object);
51
+ if (Object.getOwnPropertySymbols) {
52
+ var symbols = Object.getOwnPropertySymbols(object);
53
+ if (enumerableOnly) {
54
+ symbols = symbols.filter(function(sym) {
55
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
56
+ });
57
+ }
58
+ keys.push.apply(keys, symbols);
59
+ }
60
+ return keys;
61
+ }
62
+ function _object_spread_props(target, source) {
63
+ source = source != null ? source : {};
64
+ if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
65
+ else {
66
+ ownKeys(Object(source)).forEach(function(key) {
67
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
68
+ });
69
+ }
70
+ return target;
71
+ }
72
+ function midPageToken(params) {
73
+ return (0, _paginationtokents.encodeNextPageToken)(_object_spread_props(_object_spread({}, params.link && {
74
+ link: params.link
75
+ }), {
76
+ offset: params.pageStart + params.index + 1,
77
+ mode: params.mode
78
+ }));
79
+ }
80
+ function resumeCollection(mode) {
81
+ return mode === 'filter' ? 'filter' : 'search';
82
+ }
83
+ function cutToMaxItems(rows, taken, maxItems, hasMore) {
84
+ var kept = rows.slice(0, Math.max(0, maxItems - taken));
85
+ var truncated = kept.length < rows.length || taken + kept.length >= maxItems && hasMore;
86
+ return {
87
+ rows: kept,
88
+ truncated: truncated
89
+ };
90
+ }
91
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-outlook/src/email/querying/paging-decisions.ts"],"sourcesContent":["import { encodeNextPageToken } from './pagination-token.ts';\n\n/** Token that resumes inside the page fetched by `link`, one message past the last one taken. */\nexport function midPageToken(params: { link?: string; pageStart: number; index: number; mode: 'search' | 'filter' }): string {\n return encodeNextPageToken({ ...(params.link && { link: params.link }), offset: params.pageStart + params.index + 1, mode: params.mode });\n}\n\n/** Which collection a page token resumes: a fallback-filter token resumes the filter collection, anything else the search. */\nexport function resumeCollection(mode: string | undefined): 'search' | 'filter' {\n return mode === 'filter' ? 'filter' : 'search';\n}\n\n/** Cut a batch to what still fits under maxItems; truncated when rows were cut or a link remains at the limit. */\nexport function cutToMaxItems<T>(rows: T[], taken: number, maxItems: number, hasMore: boolean): { rows: T[]; truncated: boolean } {\n const kept = rows.slice(0, Math.max(0, maxItems - taken));\n const truncated = kept.length < rows.length || (taken + kept.length >= maxItems && hasMore);\n return { rows: kept, truncated };\n}\n"],"names":["cutToMaxItems","midPageToken","resumeCollection","params","encodeNextPageToken","link","offset","pageStart","index","mode","rows","taken","maxItems","hasMore","kept","slice","Math","max","truncated","length"],"mappings":";;;;;;;;;;;QAagBA;eAAAA;;QAVAC;eAAAA;;QAKAC;eAAAA;;;iCARoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG7B,SAASD,aAAaE,MAAsF;IACjH,OAAOC,IAAAA,sCAAmB,EAAC,wCAAMD,OAAOE,IAAI,IAAI;QAAEA,MAAMF,OAAOE,IAAI;IAAC;QAAIC,QAAQH,OAAOI,SAAS,GAAGJ,OAAOK,KAAK,GAAG;QAAGC,MAAMN,OAAOM,IAAI;;AACxI;AAGO,SAASP,iBAAiBO,IAAwB;IACvD,OAAOA,SAAS,WAAW,WAAW;AACxC;AAGO,SAAST,cAAiBU,IAAS,EAAEC,KAAa,EAAEC,QAAgB,EAAEC,OAAgB;IAC3F,IAAMC,OAAOJ,KAAKK,KAAK,CAAC,GAAGC,KAAKC,GAAG,CAAC,GAAGL,WAAWD;IAClD,IAAMO,YAAYJ,KAAKK,MAAM,GAAGT,KAAKS,MAAM,IAAKR,QAAQG,KAAKK,MAAM,IAAIP,YAAYC;IACnF,OAAO;QAAEH,MAAMI;QAAMI,WAAAA;IAAU;AACjC"}