@dxv-systems/mail-graph 0.1.4 → 0.2.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 +8 -1
- package/dist/index.d.ts +1 -1
- package/dist/mailbox.d.ts +4 -1
- package/dist/mailbox.js +39 -1
- package/dist/types.d.ts +11 -0
- package/docs/app-integration.md +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,13 +92,20 @@ await support.sendDraft(draft.id); // threads nativ
|
|
|
92
92
|
await support.markRead(id); // markRead(id, false) to unread
|
|
93
93
|
await support.setCategories(id, ["Handled"]); // replaces all categories
|
|
94
94
|
await support.listFolders("inbox"); // children of the inbox; "root" for top level
|
|
95
|
+
await support.listChildFolders(folderId); // children of any folder (id or well-known name)
|
|
96
|
+
await support.getWellKnownFolderIds(); // { inbox, archive, deleteditems, sentitems, drafts, junkemail }: id or null
|
|
97
|
+
await support.listFolderMessages(folderId); // one page, newest first: { items, nextLink }; pass { link: nextLink } for older mail
|
|
95
98
|
await support.getInboxFolderId();
|
|
96
99
|
await support.createInboxFolder("Handled");
|
|
97
|
-
await support.moveMessage(id, folderId);
|
|
100
|
+
await support.moveMessage(id, folderId); // or a well-known name: "archive", "deleteditems", "inbox"; the id stays the same
|
|
98
101
|
await support.forward(id, { to: ["a@b.example"], comment: "" });
|
|
99
102
|
await support.sendMail({ to, subject, body: { contentType: "html", content }, attachments }); // saveToSentItems: true
|
|
100
103
|
```
|
|
101
104
|
|
|
105
|
+
Message summaries (delta, folder pages, `getMessage`) carry `bodyPreview`: Graph's first 255 characters of the body as plain text.
|
|
106
|
+
|
|
107
|
+
"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
|
+
|
|
102
109
|
`sendMail` attachments must total under 3 MB (a Graph request limit); for larger files create a draft by replying, or forward.
|
|
103
110
|
|
|
104
111
|
### Access check
|
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, ForwardInput, GetMessageOptions, InternetMessageHeader, MailAddress, MailFolder, Message, MessageBody, MessageSummary, OutgoingAttachment, Recipient, SendMailInput, } 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, 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, ForwardInput, GetMessageOptions, MailFolder, Message, MessageBody, OutgoingAttachment, SendMailInput } from "./types";
|
|
2
|
+
import type { AccessCheckResult, AttachmentInfo, CreateReplyOptions, DeltaOptions, DeltaPage, FolderMessagesOptions, FolderMessagesPage, ForwardInput, GetMessageOptions, MailFolder, Message, MessageBody, OutgoingAttachment, SendMailInput, WellKnownFolderIds } from "./types";
|
|
3
3
|
export declare const LARGE_ATTACHMENT_THRESHOLD: number;
|
|
4
4
|
export interface MailboxClient {
|
|
5
5
|
readonly address: string;
|
|
@@ -19,6 +19,9 @@ export interface MailboxClient {
|
|
|
19
19
|
markRead(messageId: string, isRead?: boolean): Promise<void>;
|
|
20
20
|
setCategories(messageId: string, categories: string[]): Promise<void>;
|
|
21
21
|
listFolders(parent: "inbox" | "root"): Promise<MailFolder[]>;
|
|
22
|
+
listChildFolders(folderId: string): Promise<MailFolder[]>;
|
|
23
|
+
getWellKnownFolderIds(): Promise<WellKnownFolderIds>;
|
|
24
|
+
listFolderMessages(folderId: string, options?: FolderMessagesOptions): Promise<FolderMessagesPage>;
|
|
22
25
|
getInboxFolderId(): Promise<string>;
|
|
23
26
|
createInboxFolder(displayName: string): Promise<MailFolder>;
|
|
24
27
|
moveMessage(messageId: string, destinationFolderId: string): Promise<{
|
package/dist/mailbox.js
CHANGED
|
@@ -7,7 +7,8 @@ exports.LARGE_ATTACHMENT_THRESHOLD = 3 * 1024 * 1024;
|
|
|
7
7
|
const MAX_ATTACHMENT_BYTES = 150 * 1024 * 1024;
|
|
8
8
|
const UPLOAD_CHUNK_BYTES = 12 * 320 * 1024;
|
|
9
9
|
const MAX_PAGES = 100;
|
|
10
|
-
const SUMMARY_SELECT = "id,subject,from,receivedDateTime,internetMessageId,conversationId,hasAttachments,isRead,isDraft,parentFolderId,categories";
|
|
10
|
+
const SUMMARY_SELECT = "id,subject,from,receivedDateTime,internetMessageId,conversationId,hasAttachments,isRead,isDraft,parentFolderId,categories,bodyPreview";
|
|
11
|
+
const WELL_KNOWN_FOLDERS = ["inbox", "archive", "deleteditems", "sentitems", "drafts", "junkemail"];
|
|
11
12
|
const FOLDER_SELECT = "id,displayName,parentFolderId,childFolderCount";
|
|
12
13
|
function toAddress(raw) {
|
|
13
14
|
const address = raw?.emailAddress?.address;
|
|
@@ -41,6 +42,8 @@ function toSummary(raw) {
|
|
|
41
42
|
summary.parentFolderId = raw.parentFolderId;
|
|
42
43
|
if (raw.categories !== undefined)
|
|
43
44
|
summary.categories = raw.categories;
|
|
45
|
+
if (raw.bodyPreview !== undefined)
|
|
46
|
+
summary.bodyPreview = raw.bodyPreview;
|
|
44
47
|
return summary;
|
|
45
48
|
}
|
|
46
49
|
function toMessage(raw, includeHeaders) {
|
|
@@ -349,6 +352,41 @@ function createMailboxClient(http, address) {
|
|
|
349
352
|
const base = parent === "inbox" ? `${user}/mailFolders/inbox/childFolders` : `${user}/mailFolders`;
|
|
350
353
|
return collect(`${base}${query({ $top: 200, $select: FOLDER_SELECT })}`);
|
|
351
354
|
},
|
|
355
|
+
async listChildFolders(folderId) {
|
|
356
|
+
return collect(`${user}/mailFolders/${requireId(folderId, "folder id")}/childFolders${query({ $top: 200, $select: FOLDER_SELECT })}`);
|
|
357
|
+
},
|
|
358
|
+
async getWellKnownFolderIds() {
|
|
359
|
+
const ids = {};
|
|
360
|
+
for (const name of WELL_KNOWN_FOLDERS) {
|
|
361
|
+
try {
|
|
362
|
+
const folder = await getJson(`${user}/mailFolders/${name}${query({ $select: "id" })}`);
|
|
363
|
+
ids[name] = folder.id ?? null;
|
|
364
|
+
}
|
|
365
|
+
catch (error) {
|
|
366
|
+
if (error instanceof errors_1.GraphError && error.status === 404) {
|
|
367
|
+
ids[name] = null;
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
throw error;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return ids;
|
|
374
|
+
},
|
|
375
|
+
async listFolderMessages(folderId, options = {}) {
|
|
376
|
+
const result = options.link
|
|
377
|
+
? await http.request({ mailbox: address, method: "GET", link: options.link })
|
|
378
|
+
: await http.request({
|
|
379
|
+
mailbox: address,
|
|
380
|
+
method: "GET",
|
|
381
|
+
path: `${user}/mailFolders/${requireId(folderId, "folder id")}/messages${query({
|
|
382
|
+
$select: SUMMARY_SELECT,
|
|
383
|
+
$orderby: "receivedDateTime desc",
|
|
384
|
+
$top: Math.min(100, Math.max(1, Math.floor(options.pageSize ?? 50))),
|
|
385
|
+
})}`,
|
|
386
|
+
});
|
|
387
|
+
const page = (result.data ?? {});
|
|
388
|
+
return { items: (page.value ?? []).map(toSummary), nextLink: page["@odata.nextLink"] ?? null };
|
|
389
|
+
},
|
|
352
390
|
async getInboxFolderId() {
|
|
353
391
|
const folder = await getJson(`${user}/mailFolders/inbox${query({ $select: "id" })}`);
|
|
354
392
|
if (!folder.id)
|
package/dist/types.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export interface MessageSummary {
|
|
|
20
20
|
isDraft?: boolean;
|
|
21
21
|
parentFolderId?: string;
|
|
22
22
|
categories?: string[];
|
|
23
|
+
bodyPreview?: string;
|
|
23
24
|
}
|
|
24
25
|
export interface DeltaItem extends MessageSummary {
|
|
25
26
|
removed: boolean;
|
|
@@ -80,6 +81,16 @@ export interface MailFolder {
|
|
|
80
81
|
parentFolderId?: string;
|
|
81
82
|
childFolderCount?: number;
|
|
82
83
|
}
|
|
84
|
+
export type WellKnownFolder = "inbox" | "archive" | "deleteditems" | "sentitems" | "drafts" | "junkemail";
|
|
85
|
+
export type WellKnownFolderIds = Record<WellKnownFolder, string | null>;
|
|
86
|
+
export interface FolderMessagesOptions {
|
|
87
|
+
link?: string;
|
|
88
|
+
pageSize?: number;
|
|
89
|
+
}
|
|
90
|
+
export interface FolderMessagesPage {
|
|
91
|
+
items: MessageSummary[];
|
|
92
|
+
nextLink: string | null;
|
|
93
|
+
}
|
|
83
94
|
export interface ForwardInput {
|
|
84
95
|
to: Recipient[];
|
|
85
96
|
comment?: string;
|
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.2.0 @dxv-systems/helpdesk@0.5.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.2.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",
|