@dxv-systems/mail-graph 0.3.4 → 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 +15 -1
- package/dist/index.d.ts +1 -1
- package/dist/mailbox.d.ts +3 -1
- package/dist/mailbox.js +48 -4
- package/dist/types.d.ts +9 -0
- package/docs/app-integration.md +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,6 +86,18 @@ await support.addAttachment(draft.id, { name, contentType, content }); // 3 MB a
|
|
|
86
86
|
await support.sendDraft(draft.id); // threads natively, lands in Sent Items
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
+
## New mail with large files
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
const draft = await support.createDraft({ to, cc, bcc, subject, body: { contentType: "html", content } }); // in Drafts
|
|
93
|
+
await support.addAttachment(draft.id, { name, contentType, content }); // 3 MB and up: upload session, up to 150 MB per file
|
|
94
|
+
await support.sendDraft(draft.id); // lands in Sent Items
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`createDraft` takes `sendMail`'s fields without attachments. It is not retried on `503`, so an unclear answer never leaves a second draft. If sending fails, `deleteDraft(draft.id)` removes the draft.
|
|
98
|
+
|
|
99
|
+
150 MB is Graph's limit per upload. The mailbox's own maximum send size still applies: 35 MB by default in Exchange Online, raised per mailbox by the tenant's admin (`Set-Mailbox -MaxSendSize`). Receiving servers may accept less.
|
|
100
|
+
|
|
89
101
|
## State, folders, sending
|
|
90
102
|
|
|
91
103
|
```ts
|
|
@@ -102,11 +114,13 @@ await support.forward(id, { to: ["a@b.example"], comment: "" });
|
|
|
102
114
|
await support.sendMail({ to, subject, body: { contentType: "html", content }, attachments }); // saveToSentItems: true
|
|
103
115
|
```
|
|
104
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
|
+
|
|
105
119
|
Message summaries (delta, folder pages, `getMessage`) carry `bodyPreview`: Graph's first 255 characters of the body as plain text.
|
|
106
120
|
|
|
107
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`.
|
|
108
122
|
|
|
109
|
-
`sendMail` attachments must total under 3 MB (a Graph request limit); for larger files
|
|
123
|
+
`sendMail` attachments must total under 3 MB (a Graph request limit); for larger files use `createDraft` (above), reply, or forward.
|
|
110
124
|
|
|
111
125
|
### Access check
|
|
112
126
|
|
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, 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, 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>;
|
|
@@ -32,6 +33,7 @@ export interface MailboxClient {
|
|
|
32
33
|
status: "deleted" | "gone" | "not_draft";
|
|
33
34
|
}>;
|
|
34
35
|
sendMail(input: SendMailInput): Promise<void>;
|
|
36
|
+
createDraft(input: CreateDraftInput): Promise<Message>;
|
|
35
37
|
getMailboxPurpose(): Promise<string | null>;
|
|
36
38
|
listInboxRules(): Promise<InboxRuleInfo[] | null>;
|
|
37
39
|
}
|
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 })
|
|
@@ -446,7 +471,7 @@ function createMailboxClient(http, address) {
|
|
|
446
471
|
const attachments = input.attachments ?? [];
|
|
447
472
|
const total = attachments.reduce((sum, a) => sum + a.content.byteLength, 0);
|
|
448
473
|
if (total >= exports.LARGE_ATTACHMENT_THRESHOLD) {
|
|
449
|
-
throw new errors_1.GraphUsageError("AttachmentTooLarge", "sendMail attachments must stay under 3 MB in total;
|
|
474
|
+
throw new errors_1.GraphUsageError("AttachmentTooLarge", "sendMail attachments must stay under 3 MB in total; use createDraft and addAttachment instead.");
|
|
450
475
|
}
|
|
451
476
|
await http.request({
|
|
452
477
|
mailbox: address,
|
|
@@ -466,5 +491,24 @@ function createMailboxClient(http, address) {
|
|
|
466
491
|
retryOn503: false,
|
|
467
492
|
});
|
|
468
493
|
},
|
|
494
|
+
async createDraft(input) {
|
|
495
|
+
const result = await http.request({
|
|
496
|
+
mailbox: address,
|
|
497
|
+
method: "POST",
|
|
498
|
+
path: `${user}/messages`,
|
|
499
|
+
body: {
|
|
500
|
+
subject: input.subject,
|
|
501
|
+
body: graphBody(input.body),
|
|
502
|
+
toRecipients: requireRecipients(input.to),
|
|
503
|
+
ccRecipients: toRecipients(input.cc),
|
|
504
|
+
bccRecipients: toRecipients(input.bcc),
|
|
505
|
+
},
|
|
506
|
+
retryOn503: false,
|
|
507
|
+
});
|
|
508
|
+
const raw = result.data;
|
|
509
|
+
if (!raw?.id)
|
|
510
|
+
throw new errors_1.GraphError({ message: "createDraft returned no draft.", status: result.status, code: "InvalidResponse" });
|
|
511
|
+
return toMessage(raw, false);
|
|
512
|
+
},
|
|
469
513
|
};
|
|
470
514
|
}
|
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;
|
|
@@ -104,6 +112,7 @@ export interface SendMailInput {
|
|
|
104
112
|
body: MessageBody;
|
|
105
113
|
attachments?: OutgoingAttachment[];
|
|
106
114
|
}
|
|
115
|
+
export type CreateDraftInput = Omit<SendMailInput, "attachments">;
|
|
107
116
|
export type AccessStatus = "ok" | "denied" | "not_found";
|
|
108
117
|
export interface AccessCheckResult {
|
|
109
118
|
status: AccessStatus;
|
package/docs/app-integration.md
CHANGED
|
@@ -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.
|
|
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.
|
|
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",
|