@dxv-systems/mail-graph 0.6.1 → 0.7.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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/mailbox.d.ts +8 -1
- package/dist/mailbox.js +39 -3
- package/dist/types.d.ts +5 -0
- package/docs/app-integration.md +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -118,7 +118,7 @@ await support.sendMail({ to, subject, body: { contentType: "html", content }, at
|
|
|
118
118
|
|
|
119
119
|
`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.
|
|
120
120
|
|
|
121
|
-
Message summaries (delta, folder pages, `getMessage`) carry `bodyPreview`: Graph's first 255 characters of the body as plain text.
|
|
121
|
+
Message summaries (delta, folder pages, `getMessage`) carry `bodyPreview`: Graph's first 255 characters of the body as plain text. `getMessage` and `listFolderMessages` also carry `lastVerb` (0.7): `{ verb: "reply" | "replyAll" | "forward", at }` when the message was replied to or forwarded, in Outlook or through `createReply`/`createForward` and `sendDraft` (Exchange records it on the original), else null. It is read with `$expand=singleValueExtendedProperties` (PidTagLastVerbExecuted and its time), which needs no permission beyond reading mail. Graph answers 400 to that expand on `messages/delta`, so delta items never carry it: a reply or forward does make the original show up in delta as changed, and `getLastVerbs(ids)` reads the verb of such messages (one GET each; an id that no longer exists is left out).
|
|
122
122
|
|
|
123
123
|
"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`.
|
|
124
124
|
|
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, CreateForwardOptions, DraftOverrides, ConversationMessage, ListConversationOptions, WellKnownFolder, WellKnownFolderIds, } from "./types";
|
|
9
|
+
export type { AccessCheckResult, AccessStatus, AttachmentInfo, AttachmentKind, BodyType, CreateReplyOptions, DeltaItem, DeltaOptions, DeltaPage, FolderMessagesOptions, FolderMessagesPage, ForwardInput, GetMessageOptions, InternetMessageHeader, LastVerb, MailAddress, MailFolder, Message, MessageBody, MessageSummary, OutgoingAttachment, Recipient, SendMailInput, CreateDraftInput, CreateForwardOptions, DraftOverrides, ConversationMessage, ListConversationOptions, WellKnownFolder, WellKnownFolderIds, } from "./types";
|
package/dist/mailbox.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { Http } from "./http";
|
|
2
|
-
import type { AccessCheckResult, AttachmentInfo, CreateForwardOptions, CreateReplyOptions, DeltaOptions, DeltaPage, FolderMessagesOptions, FolderMessagesPage, ForwardInput, GetMessageOptions, MailFolder, Message, MessageBody, OutgoingAttachment, SendMailInput, CreateDraftInput, ConversationMessage, ListConversationOptions, WellKnownFolderIds } from "./types";
|
|
2
|
+
import type { AccessCheckResult, AttachmentInfo, CreateForwardOptions, CreateReplyOptions, DeltaOptions, DeltaPage, FolderMessagesOptions, FolderMessagesPage, ForwardInput, GetMessageOptions, LastVerb, MailFolder, Message, MessageBody, OutgoingAttachment, SendMailInput, CreateDraftInput, ConversationMessage, ListConversationOptions, WellKnownFolderIds } from "./types";
|
|
3
3
|
export declare const LARGE_ATTACHMENT_THRESHOLD: number;
|
|
4
|
+
interface RawExtendedProperty {
|
|
5
|
+
id?: string;
|
|
6
|
+
value?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function parseLastVerb(props: RawExtendedProperty[] | undefined): LastVerb | null;
|
|
4
9
|
export interface MailboxClient {
|
|
5
10
|
readonly address: string;
|
|
6
11
|
checkAccess(): Promise<{
|
|
@@ -8,6 +13,7 @@ export interface MailboxClient {
|
|
|
8
13
|
}>;
|
|
9
14
|
delta(options: DeltaOptions): Promise<DeltaPage>;
|
|
10
15
|
getMessage(id: string, options?: GetMessageOptions): Promise<Message | null>;
|
|
16
|
+
getLastVerbs(ids: string[]): Promise<Map<string, LastVerb | null>>;
|
|
11
17
|
listAttachments(messageId: string): Promise<AttachmentInfo[]>;
|
|
12
18
|
downloadAttachment(messageId: string, attachmentId: string): Promise<Uint8Array>;
|
|
13
19
|
createReply(messageId: string, options?: CreateReplyOptions): Promise<Message>;
|
|
@@ -45,3 +51,4 @@ export interface InboxRuleInfo {
|
|
|
45
51
|
forwards: boolean;
|
|
46
52
|
}
|
|
47
53
|
export declare function createMailboxClient(http: Http, address: string): MailboxClient;
|
|
54
|
+
export {};
|
package/dist/mailbox.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LARGE_ATTACHMENT_THRESHOLD = void 0;
|
|
4
|
+
exports.parseLastVerb = parseLastVerb;
|
|
4
5
|
exports.createMailboxClient = createMailboxClient;
|
|
5
6
|
const errors_1 = require("./errors");
|
|
6
7
|
exports.LARGE_ATTACHMENT_THRESHOLD = 3 * 1024 * 1024;
|
|
@@ -10,6 +11,14 @@ const MAX_PAGES = 100;
|
|
|
10
11
|
const SUMMARY_SELECT = "id,subject,from,receivedDateTime,internetMessageId,conversationId,hasAttachments,isRead,isDraft,parentFolderId,categories,bodyPreview";
|
|
11
12
|
const WELL_KNOWN_FOLDERS = ["inbox", "archive", "deleteditems", "sentitems", "drafts", "junkemail"];
|
|
12
13
|
const FOLDER_SELECT = "id,displayName,parentFolderId,childFolderCount";
|
|
14
|
+
const LAST_VERB_ID = "Integer 0x1081";
|
|
15
|
+
const LAST_VERB_TIME_ID = "SystemTime 0x1082";
|
|
16
|
+
const LAST_VERB_EXPAND = `singleValueExtendedProperties($filter=id eq '${LAST_VERB_ID}' or id eq '${LAST_VERB_TIME_ID}')`;
|
|
17
|
+
const LAST_VERBS = new Map([
|
|
18
|
+
["102", "reply"],
|
|
19
|
+
["103", "replyAll"],
|
|
20
|
+
["104", "forward"],
|
|
21
|
+
]);
|
|
13
22
|
function toAddress(raw) {
|
|
14
23
|
const address = raw?.emailAddress?.address;
|
|
15
24
|
if (!address)
|
|
@@ -19,6 +28,14 @@ function toAddress(raw) {
|
|
|
19
28
|
function toAddresses(raw) {
|
|
20
29
|
return (raw ?? []).map(toAddress).filter((a) => a !== undefined);
|
|
21
30
|
}
|
|
31
|
+
function parseLastVerb(props) {
|
|
32
|
+
const value = (id) => props?.find((p) => p.id?.toLowerCase() === id.toLowerCase())?.value;
|
|
33
|
+
const verb = LAST_VERBS.get(String(value(LAST_VERB_ID) ?? "").trim());
|
|
34
|
+
if (!verb)
|
|
35
|
+
return null;
|
|
36
|
+
const time = Date.parse(value(LAST_VERB_TIME_ID) ?? "");
|
|
37
|
+
return { verb, at: Number.isNaN(time) ? null : new Date(time).toISOString() };
|
|
38
|
+
}
|
|
22
39
|
function toSummary(raw) {
|
|
23
40
|
const summary = { id: raw.id };
|
|
24
41
|
if (raw.subject !== undefined)
|
|
@@ -46,6 +63,9 @@ function toSummary(raw) {
|
|
|
46
63
|
summary.bodyPreview = raw.bodyPreview;
|
|
47
64
|
return summary;
|
|
48
65
|
}
|
|
66
|
+
function withLastVerb(summary, raw) {
|
|
67
|
+
return { ...summary, lastVerb: parseLastVerb(raw.singleValueExtendedProperties) };
|
|
68
|
+
}
|
|
49
69
|
function toMessage(raw, includeHeaders) {
|
|
50
70
|
const contentType = raw.body?.contentType?.toLowerCase() === "text" ? "text" : "html";
|
|
51
71
|
const message = {
|
|
@@ -288,10 +308,10 @@ function createMailboxClient(http, address) {
|
|
|
288
308
|
const bodyType = options.bodyType ?? "html";
|
|
289
309
|
const select = `${SUMMARY_SELECT},body,sentDateTime,toRecipients,ccRecipients,replyTo${options.includeHeaders ? ",internetMessageHeaders" : ""}`;
|
|
290
310
|
try {
|
|
291
|
-
const raw = await getJson(`${user}/messages/${requireId(id, "message id")}${query({ $select: select })}`, [
|
|
311
|
+
const raw = await getJson(`${user}/messages/${requireId(id, "message id")}${query({ $select: select, $expand: LAST_VERB_EXPAND })}`, [
|
|
292
312
|
`outlook.body-content-type="${bodyType}"`,
|
|
293
313
|
]);
|
|
294
|
-
return toMessage(raw, options.includeHeaders === true);
|
|
314
|
+
return withLastVerb(toMessage(raw, options.includeHeaders === true), raw);
|
|
295
315
|
}
|
|
296
316
|
catch (error) {
|
|
297
317
|
if (error instanceof errors_1.GraphError && error.status === 404)
|
|
@@ -299,6 +319,21 @@ function createMailboxClient(http, address) {
|
|
|
299
319
|
throw error;
|
|
300
320
|
}
|
|
301
321
|
},
|
|
322
|
+
async getLastVerbs(ids) {
|
|
323
|
+
const verbs = new Map();
|
|
324
|
+
for (const id of new Set(ids)) {
|
|
325
|
+
try {
|
|
326
|
+
const raw = await getJson(`${user}/messages/${requireId(id, "message id")}${query({ $select: "id", $expand: LAST_VERB_EXPAND })}`);
|
|
327
|
+
verbs.set(id, parseLastVerb(raw.singleValueExtendedProperties));
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
if (error instanceof errors_1.GraphError && error.status === 404)
|
|
331
|
+
continue;
|
|
332
|
+
throw error;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return verbs;
|
|
336
|
+
},
|
|
302
337
|
async listAttachments(messageId) {
|
|
303
338
|
const raw = await collect(`${user}/messages/${requireId(messageId, "message id")}/attachments${query({
|
|
304
339
|
$select: "id,name,contentType,size,isInline,microsoft.graph.fileAttachment/contentId",
|
|
@@ -431,11 +466,12 @@ function createMailboxClient(http, address) {
|
|
|
431
466
|
path: `${user}/mailFolders/${requireId(folderId, "folder id")}/messages${query({
|
|
432
467
|
$select: SUMMARY_SELECT,
|
|
433
468
|
$orderby: "receivedDateTime desc",
|
|
469
|
+
$expand: LAST_VERB_EXPAND,
|
|
434
470
|
$top: Math.min(100, Math.max(1, Math.floor(options.pageSize ?? 50))),
|
|
435
471
|
})}`,
|
|
436
472
|
});
|
|
437
473
|
const page = (result.data ?? {});
|
|
438
|
-
return { items: (page.value ?? []).map(toSummary), nextLink: page["@odata.nextLink"] ?? null };
|
|
474
|
+
return { items: (page.value ?? []).map((m) => withLastVerb(toSummary(m), m)), nextLink: page["@odata.nextLink"] ?? null };
|
|
439
475
|
},
|
|
440
476
|
async getInboxFolderId() {
|
|
441
477
|
const folder = await getJson(`${user}/mailFolders/inbox${query({ $select: "id" })}`);
|
package/dist/types.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ export interface MessageBody {
|
|
|
8
8
|
contentType: BodyType;
|
|
9
9
|
content: string;
|
|
10
10
|
}
|
|
11
|
+
export interface LastVerb {
|
|
12
|
+
verb: "reply" | "replyAll" | "forward";
|
|
13
|
+
at: string | null;
|
|
14
|
+
}
|
|
11
15
|
export interface MessageSummary {
|
|
12
16
|
id: string;
|
|
13
17
|
subject?: string;
|
|
@@ -21,6 +25,7 @@ export interface MessageSummary {
|
|
|
21
25
|
parentFolderId?: string;
|
|
22
26
|
categories?: string[];
|
|
23
27
|
bodyPreview?: string;
|
|
28
|
+
lastVerb?: LastVerb | null;
|
|
24
29
|
}
|
|
25
30
|
export interface DeltaItem extends MessageSummary {
|
|
26
31
|
removed: boolean;
|
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.7.0 @dxv-systems/helpdesk@0.16.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.
|
|
@@ -81,6 +81,7 @@ import type {
|
|
|
81
81
|
DistillState,
|
|
82
82
|
DraftRunStatus,
|
|
83
83
|
HistoryState,
|
|
84
|
+
LastVerb,
|
|
84
85
|
MailAddress,
|
|
85
86
|
MessageDirection,
|
|
86
87
|
MessageLocation,
|
|
@@ -217,6 +218,8 @@ export const helpdeskMessages = pgTable(
|
|
|
217
218
|
/** To and Cc (helpdesk 0.15); null when unknown. */
|
|
218
219
|
toRecipients: jsonb("to_recipients").$type<MailAddress[]>(),
|
|
219
220
|
ccRecipients: jsonb("cc_recipients").$type<MailAddress[]>(),
|
|
221
|
+
/** Last reply or forward, in the app or in Outlook (helpdesk 0.16); null when never or unknown. */
|
|
222
|
+
lastVerb: jsonb("last_verb").$type<LastVerb>(),
|
|
220
223
|
},
|
|
221
224
|
(table) => [
|
|
222
225
|
primaryKey({ columns: [table.mailbox, table.id] }),
|
|
@@ -302,7 +305,7 @@ export const helpdeskReplyAttachments = pgTable(
|
|
|
302
305
|
);
|
|
303
306
|
```
|
|
304
307
|
|
|
305
|
-
Every column maps one field of the package types (`M365Connection`, `SyncState`, `Thread` incl. `dismissedBy`, `StoredMessage`, `DraftRun`, `SendIntent`, `ReplyAttachment`); `assignee_id`, `assignment_note` and `assigned_by` are the inbox's assignment, `seq` orders draft runs, `sync_lease_until` guards cron overlap. Then run `npm run db:generate`, review the SQL (ten `CREATE TABLE`s, foreign keys, nine indexes, no `DROP`) and commit it with its snapshot and journal entry. An app on helpdesk 0.2 upgrades with one generated migration: `direction` on `helpdesk_messages` (default `inbound`) and `sent_link`, `sent_last_received_at` on `helpdesk_sync_states` (see the helpdesk README, Upgrading from 0.2). An app on helpdesk 0.4 upgrades with one generated migration too: `assignment_note` and `assigned_by` on `helpdesk_threads`, both nullable (see the helpdesk README, Upgrading from 0.4). An app on helpdesk 0.5 upgrades with one generated migration: `from_name`, `preview`, `has_attachments`, `is_read` and `location` on `helpdesk_messages`, all nullable, and its store's `markMessageRemoved` becomes `updateMessageState`. Add `update helpdesk_sync_states set link = null, sent_link = null;` to the end of that generated migration, so the next sync fills the new fields of mail already stored (see the helpdesk README, Upgrading from 0.5). An app on helpdesk 0.11 upgrades with one generated migration: the table `helpdesk_history_states` and `history_lease_until` on `helpdesk_settings`, nothing dropped (see the helpdesk README, Upgrading from 0.11). An app on helpdesk 0.
|
|
308
|
+
Every column maps one field of the package types (`M365Connection`, `SyncState`, `Thread` incl. `dismissedBy`, `StoredMessage`, `DraftRun`, `SendIntent`, `ReplyAttachment`); `assignee_id`, `assignment_note` and `assigned_by` are the inbox's assignment, `seq` orders draft runs, `sync_lease_until` guards cron overlap. Then run `npm run db:generate`, review the SQL (ten `CREATE TABLE`s, foreign keys, nine indexes, no `DROP`) and commit it with its snapshot and journal entry. An app on helpdesk 0.2 upgrades with one generated migration: `direction` on `helpdesk_messages` (default `inbound`) and `sent_link`, `sent_last_received_at` on `helpdesk_sync_states` (see the helpdesk README, Upgrading from 0.2). An app on helpdesk 0.4 upgrades with one generated migration too: `assignment_note` and `assigned_by` on `helpdesk_threads`, both nullable (see the helpdesk README, Upgrading from 0.4). An app on helpdesk 0.5 upgrades with one generated migration: `from_name`, `preview`, `has_attachments`, `is_read` and `location` on `helpdesk_messages`, all nullable, and its store's `markMessageRemoved` becomes `updateMessageState`. Add `update helpdesk_sync_states set link = null, sent_link = null;` to the end of that generated migration, so the next sync fills the new fields of mail already stored (see the helpdesk README, Upgrading from 0.5). An app on helpdesk 0.11 upgrades with one generated migration: the table `helpdesk_history_states` and `history_lease_until` on `helpdesk_settings`, nothing dropped (see the helpdesk README, Upgrading from 0.11). An app on helpdesk 0.13 upgrades with one generated migration: the table `helpdesk_distill_states` and `distill_lease_until` on `helpdesk_settings`, nothing dropped; then add the store methods, `claimDistillLease`, the distiller in `deps.ts`, the distill cron and the settings card below (see the helpdesk README, Upgrading from 0.13.0). An app on helpdesk 0.14 upgrades with one generated migration: `to_recipients` and `cc_recipients` (jsonb, nullable) on `helpdesk_messages`, and two lines in `toMessage` (see the helpdesk README, Upgrading from 0.14.0). An app on helpdesk 0.15 upgrades with one generated migration: `last_verb` (jsonb, nullable) on `helpdesk_messages`, and one line in `toMessage` (see the helpdesk README, Upgrading from 0.15.0).
|
|
306
309
|
|
|
307
310
|
## 5. `src/lib/m365/` (Graph sign-in and the guided setup)
|
|
308
311
|
|
|
@@ -546,6 +549,7 @@ export function toMessage(row: MessageRow): StoredMessage {
|
|
|
546
549
|
location: row.location,
|
|
547
550
|
toRecipients: row.toRecipients,
|
|
548
551
|
ccRecipients: row.ccRecipients,
|
|
552
|
+
lastVerb: row.lastVerb,
|
|
549
553
|
};
|
|
550
554
|
}
|
|
551
555
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxv-systems/mail-graph",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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",
|