@dxv-systems/mail-graph 0.4.0 → 0.5.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/README.md CHANGED
@@ -114,6 +114,8 @@ await support.forward(id, { to: ["a@b.example"], comment: "" });
114
114
  await support.sendMail({ to, subject, body: { contentType: "html", content }, attachments }); // saveToSentItems: true
115
115
  ```
116
116
 
117
+ `listConversation(conversationId)` returns every message of a conversation in any folder (Inbox, Sent Items, Archive, the mailbox's own folders), oldest first. Each has `uniqueBody`: only the text that message adds, without the quoted history, as plain text by default (`{ bodyType: "html" }` for HTML). Graph refuses `$orderby` with this filter, so the package sorts. Drafts and Deleted Items are included; filter on `isDraft` and `parentFolderId` as needed.
118
+
117
119
  Message summaries (delta, folder pages, `getMessage`) carry `bodyPreview`: Graph's first 255 characters of the body as plain text.
118
120
 
119
121
  "Delete" for customer mail is `moveMessage(id, "deleteditems")`, the same as Delete in Outlook. `listFolderMessages` is for folders a caller reads live (Archive, Deleted Items, custom folders); the Inbox and Sent Items go through `delta`.
package/dist/index.d.ts CHANGED
@@ -6,4 +6,4 @@ export { LARGE_ATTACHMENT_THRESHOLD } from "./mailbox";
6
6
  export type { MailboxClient } from "./mailbox";
7
7
  export { GraphAuthError, GraphDeltaExpiredError, GraphError, GraphUsageError } from "./errors";
8
8
  export type { GraphErrorInit, UsageErrorCode } from "./errors";
9
- export type { AccessCheckResult, AccessStatus, AttachmentInfo, AttachmentKind, BodyType, CreateReplyOptions, DeltaItem, DeltaOptions, DeltaPage, FolderMessagesOptions, FolderMessagesPage, ForwardInput, GetMessageOptions, InternetMessageHeader, MailAddress, MailFolder, Message, MessageBody, MessageSummary, OutgoingAttachment, Recipient, SendMailInput, CreateDraftInput, WellKnownFolder, WellKnownFolderIds, } from "./types";
9
+ export type { AccessCheckResult, AccessStatus, AttachmentInfo, AttachmentKind, BodyType, CreateReplyOptions, DeltaItem, DeltaOptions, DeltaPage, FolderMessagesOptions, FolderMessagesPage, ForwardInput, GetMessageOptions, InternetMessageHeader, MailAddress, MailFolder, Message, MessageBody, MessageSummary, OutgoingAttachment, Recipient, SendMailInput, CreateDraftInput, ConversationMessage, ListConversationOptions, WellKnownFolder, WellKnownFolderIds, } from "./types";
package/dist/mailbox.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Http } from "./http";
2
- import type { AccessCheckResult, AttachmentInfo, CreateReplyOptions, DeltaOptions, DeltaPage, FolderMessagesOptions, FolderMessagesPage, ForwardInput, GetMessageOptions, MailFolder, Message, MessageBody, OutgoingAttachment, SendMailInput, CreateDraftInput, WellKnownFolderIds } from "./types";
2
+ import type { AccessCheckResult, AttachmentInfo, CreateReplyOptions, DeltaOptions, DeltaPage, FolderMessagesOptions, FolderMessagesPage, ForwardInput, GetMessageOptions, MailFolder, Message, MessageBody, OutgoingAttachment, SendMailInput, CreateDraftInput, ConversationMessage, ListConversationOptions, WellKnownFolderIds } from "./types";
3
3
  export declare const LARGE_ATTACHMENT_THRESHOLD: number;
4
4
  export interface MailboxClient {
5
5
  readonly address: string;
@@ -18,6 +18,7 @@ export interface MailboxClient {
18
18
  sendDraft(draftId: string): Promise<void>;
19
19
  markRead(messageId: string, isRead?: boolean): Promise<void>;
20
20
  setCategories(messageId: string, categories: string[]): Promise<void>;
21
+ listConversation(conversationId: string, options?: ListConversationOptions): Promise<ConversationMessage[]>;
21
22
  listFolders(parent: "inbox" | "root"): Promise<MailFolder[]>;
22
23
  listChildFolders(folderId: string): Promise<MailFolder[]>;
23
24
  getWellKnownFolderIds(): Promise<WellKnownFolderIds>;
package/dist/mailbox.js CHANGED
@@ -120,9 +120,9 @@ function createMailboxClient(http, address) {
120
120
  const result = await http.request({ mailbox: address, method: "GET", path, prefer });
121
121
  return (result.data ?? {});
122
122
  }
123
- async function collect(firstPath) {
123
+ async function collect(firstPath, prefer) {
124
124
  const items = [];
125
- let page = await getJson(firstPath);
125
+ let page = await getJson(firstPath, prefer);
126
126
  for (let i = 0;; i++) {
127
127
  items.push(...(page.value ?? []));
128
128
  const next = page["@odata.nextLink"];
@@ -130,7 +130,7 @@ function createMailboxClient(http, address) {
130
130
  return items;
131
131
  if (i >= MAX_PAGES)
132
132
  throw new errors_1.GraphError({ message: "Graph returned too many pages.", status: 0, code: "TooManyPages" });
133
- const result = await http.request({ mailbox: address, method: "GET", link: next });
133
+ const result = await http.request({ mailbox: address, method: "GET", link: next, prefer });
134
134
  page = (result.data ?? {});
135
135
  }
136
136
  }
@@ -375,6 +375,31 @@ function createMailboxClient(http, address) {
375
375
  }
376
376
  return ids;
377
377
  },
378
+ async listConversation(conversationId, options = {}) {
379
+ if (!conversationId)
380
+ throw new errors_1.GraphUsageError("InvalidArgument", "conversation id is required.");
381
+ const id = conversationId;
382
+ const bodyType = options.bodyType ?? "text";
383
+ const raw = await collect(`${user}/messages${query({
384
+ $filter: `conversationId eq '${id.replace(/'/g, "''")}'`,
385
+ $select: `${SUMMARY_SELECT},uniqueBody,sentDateTime,toRecipients`,
386
+ $top: 50,
387
+ })}`, [`outlook.body-content-type="${bodyType}"`]);
388
+ const time = (m) => Date.parse(m.receivedDateTime ?? m.sentDateTime ?? "") || 0;
389
+ return raw
390
+ .sort((a, b) => time(a) - time(b))
391
+ .map((m) => {
392
+ const type = m.uniqueBody?.contentType?.toLowerCase() === "html" ? "html" : "text";
393
+ const message = {
394
+ ...toSummary(m),
395
+ uniqueBody: { contentType: type, content: m.uniqueBody?.content ?? "" },
396
+ toRecipients: toAddresses(m.toRecipients),
397
+ };
398
+ if (m.sentDateTime !== undefined)
399
+ message.sentDateTime = m.sentDateTime;
400
+ return message;
401
+ });
402
+ },
378
403
  async listFolderMessages(folderId, options = {}) {
379
404
  const result = options.link
380
405
  ? await http.request({ mailbox: address, method: "GET", link: options.link })
package/dist/types.d.ts CHANGED
@@ -51,6 +51,14 @@ export interface Message extends MessageSummary {
51
51
  inReplyTo?: string;
52
52
  references?: string[];
53
53
  }
54
+ export interface ConversationMessage extends MessageSummary {
55
+ uniqueBody: MessageBody;
56
+ sentDateTime?: string;
57
+ toRecipients: MailAddress[];
58
+ }
59
+ export interface ListConversationOptions {
60
+ bodyType?: BodyType;
61
+ }
54
62
  export interface GetMessageOptions {
55
63
  bodyType?: BodyType;
56
64
  includeHeaders?: boolean;
@@ -17,7 +17,7 @@ The code below was compiled, linted, knip-checked, built and tested against a fr
17
17
  ## 1. Install
18
18
 
19
19
  ```bash
20
- npm install --save-exact @dxv-systems/mail-graph@0.4.0 @dxv-systems/helpdesk@0.13.0 @vercel/oidc@4.0.1
20
+ npm install --save-exact @dxv-systems/mail-graph@0.5.0 @dxv-systems/helpdesk@0.13.0 @vercel/oidc@4.0.1
21
21
  ```
22
22
 
23
23
  Use the published versions (exact, never a range; upgrading is a deliberate change). **Vendored variant** (before publication, e.g. the rehearsal): `npm pack` each package into `vendor/` and install `file:vendor/dxv-systems-mail-graph-<version>.tgz file:vendor/dxv-systems-helpdesk-<version>.tgz` instead; commit the tarballs with `package.json` and the lockfile.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxv-systems/mail-graph",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Microsoft Graph mail for DXV apps — app-only auth via a caller-supplied client assertion (federated or certificate), per-mailbox delta sync, messages, attachments, threaded replies, folders, forward and send. Never deletes. Guided Microsoft 365 setup (route handlers and a React page) under ./setup. Zero runtime dependencies.",
5
5
  "keywords": [
6
6
  "dxv",