@dxv-systems/mail-graph 0.5.2 → 0.6.1
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 +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/mailbox.d.ts +2 -1
- package/dist/mailbox.js +34 -12
- package/dist/types.d.ts +10 -1
- package/docs/app-integration.md +8 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,6 +86,8 @@ 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
|
+
`createReply` also takes `to`, `cc`, `bcc` and `subject`; each one given replaces what Outlook set on the reply, the rest stays. An empty `to` is refused, so a reply never loses its recipients. `createForward(messageId, { to, cc, bcc, subject, comment })` makes a forward draft the same way: the original's attachments come along, `updateDraftBody` and `addAttachment` work on it, and `sendDraft` sends it. `forward` stays for a one-step forward with plain text.
|
|
90
|
+
|
|
89
91
|
## New mail with large files
|
|
90
92
|
|
|
91
93
|
```ts
|
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, ConversationMessage, ListConversationOptions, 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, CreateForwardOptions, DraftOverrides, 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, ConversationMessage, ListConversationOptions, WellKnownFolderIds } from "./types";
|
|
2
|
+
import type { AccessCheckResult, AttachmentInfo, CreateForwardOptions, 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;
|
|
@@ -11,6 +11,7 @@ export interface MailboxClient {
|
|
|
11
11
|
listAttachments(messageId: string): Promise<AttachmentInfo[]>;
|
|
12
12
|
downloadAttachment(messageId: string, attachmentId: string): Promise<Uint8Array>;
|
|
13
13
|
createReply(messageId: string, options?: CreateReplyOptions): Promise<Message>;
|
|
14
|
+
createForward(messageId: string, options?: CreateForwardOptions): Promise<Message>;
|
|
14
15
|
updateDraftBody(draftId: string, body: MessageBody): Promise<void>;
|
|
15
16
|
addAttachment(draftId: string, attachment: OutgoingAttachment): Promise<{
|
|
16
17
|
id?: string;
|
package/dist/mailbox.js
CHANGED
|
@@ -92,6 +92,18 @@ function requireId(value, what) {
|
|
|
92
92
|
throw new errors_1.GraphUsageError("InvalidArgument", `${what} is required.`);
|
|
93
93
|
return encodeURIComponent(value);
|
|
94
94
|
}
|
|
95
|
+
function draftOverrides(o) {
|
|
96
|
+
const message = {};
|
|
97
|
+
if (o.to !== undefined)
|
|
98
|
+
message.toRecipients = requireRecipients(o.to);
|
|
99
|
+
if (o.cc !== undefined)
|
|
100
|
+
message.ccRecipients = toRecipients(o.cc);
|
|
101
|
+
if (o.bcc !== undefined)
|
|
102
|
+
message.bccRecipients = toRecipients(o.bcc);
|
|
103
|
+
if (o.subject !== undefined)
|
|
104
|
+
message.subject = o.subject;
|
|
105
|
+
return Object.keys(message).length > 0 ? message : null;
|
|
106
|
+
}
|
|
95
107
|
function query(params) {
|
|
96
108
|
const parts = Object.entries(params)
|
|
97
109
|
.filter(([, value]) => value !== undefined)
|
|
@@ -120,6 +132,24 @@ function createMailboxClient(http, address) {
|
|
|
120
132
|
const result = await http.request({ mailbox: address, method: "GET", path, prefer });
|
|
121
133
|
return (result.data ?? {});
|
|
122
134
|
}
|
|
135
|
+
async function createDraftFrom(messageId, action, options) {
|
|
136
|
+
const message = draftOverrides(options);
|
|
137
|
+
const body = {
|
|
138
|
+
...(options.comment !== undefined ? { comment: options.comment } : {}),
|
|
139
|
+
...(message ? { message } : {}),
|
|
140
|
+
};
|
|
141
|
+
const result = await http.request({
|
|
142
|
+
mailbox: address,
|
|
143
|
+
method: "POST",
|
|
144
|
+
path: `${user}/messages/${requireId(messageId, "message id")}/${action}`,
|
|
145
|
+
body,
|
|
146
|
+
prefer: ['outlook.body-content-type="html"'],
|
|
147
|
+
});
|
|
148
|
+
const raw = result.data;
|
|
149
|
+
if (!raw?.id)
|
|
150
|
+
throw new errors_1.GraphError({ message: `${action} returned no draft.`, status: result.status, code: "InvalidResponse" });
|
|
151
|
+
return toMessage(raw, false);
|
|
152
|
+
}
|
|
123
153
|
async function collect(firstPath, prefer) {
|
|
124
154
|
const items = [];
|
|
125
155
|
let page = await getJson(firstPath, prefer);
|
|
@@ -301,18 +331,10 @@ function createMailboxClient(http, address) {
|
|
|
301
331
|
return result.bytes ?? new Uint8Array();
|
|
302
332
|
},
|
|
303
333
|
async createReply(messageId, options = {}) {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
path: `${user}/messages/${requireId(messageId, "message id")}/${action}`,
|
|
309
|
-
body: options.comment !== undefined ? { comment: options.comment } : {},
|
|
310
|
-
prefer: ['outlook.body-content-type="html"'],
|
|
311
|
-
});
|
|
312
|
-
const raw = result.data;
|
|
313
|
-
if (!raw?.id)
|
|
314
|
-
throw new errors_1.GraphError({ message: "createReply returned no draft.", status: result.status, code: "InvalidResponse" });
|
|
315
|
-
return toMessage(raw, false);
|
|
334
|
+
return createDraftFrom(messageId, options.replyAll ? "createReplyAll" : "createReply", options);
|
|
335
|
+
},
|
|
336
|
+
async createForward(messageId, options = {}) {
|
|
337
|
+
return createDraftFrom(messageId, "createForward", options);
|
|
316
338
|
},
|
|
317
339
|
async updateDraftBody(draftId, body) {
|
|
318
340
|
await http.request({
|
package/dist/types.d.ts
CHANGED
|
@@ -73,10 +73,19 @@ export interface AttachmentInfo {
|
|
|
73
73
|
kind: AttachmentKind;
|
|
74
74
|
contentId?: string;
|
|
75
75
|
}
|
|
76
|
-
export interface
|
|
76
|
+
export interface DraftOverrides {
|
|
77
|
+
to?: Recipient[];
|
|
78
|
+
cc?: Recipient[];
|
|
79
|
+
bcc?: Recipient[];
|
|
80
|
+
subject?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface CreateReplyOptions extends DraftOverrides {
|
|
77
83
|
replyAll?: boolean;
|
|
78
84
|
comment?: string;
|
|
79
85
|
}
|
|
86
|
+
export interface CreateForwardOptions extends DraftOverrides {
|
|
87
|
+
comment?: string;
|
|
88
|
+
}
|
|
80
89
|
export interface OutgoingAttachment {
|
|
81
90
|
name: string;
|
|
82
91
|
contentType: 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.6.1 @dxv-systems/helpdesk@0.15.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
|
+
MailAddress,
|
|
84
85
|
MessageDirection,
|
|
85
86
|
MessageLocation,
|
|
86
87
|
NoiseReason,
|
|
@@ -213,6 +214,9 @@ export const helpdeskMessages = pgTable(
|
|
|
213
214
|
hasAttachments: boolean("has_attachments"),
|
|
214
215
|
isRead: boolean("is_read"),
|
|
215
216
|
location: text("location").$type<MessageLocation>(),
|
|
217
|
+
/** To and Cc (helpdesk 0.15); null when unknown. */
|
|
218
|
+
toRecipients: jsonb("to_recipients").$type<MailAddress[]>(),
|
|
219
|
+
ccRecipients: jsonb("cc_recipients").$type<MailAddress[]>(),
|
|
216
220
|
},
|
|
217
221
|
(table) => [
|
|
218
222
|
primaryKey({ columns: [table.mailbox, table.id] }),
|
|
@@ -298,7 +302,7 @@ export const helpdeskReplyAttachments = pgTable(
|
|
|
298
302
|
);
|
|
299
303
|
```
|
|
300
304
|
|
|
301
|
-
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).
|
|
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.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.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).
|
|
302
306
|
|
|
303
307
|
## 5. `src/lib/m365/` (Graph sign-in and the guided setup)
|
|
304
308
|
|
|
@@ -540,6 +544,8 @@ export function toMessage(row: MessageRow): StoredMessage {
|
|
|
540
544
|
hasAttachments: row.hasAttachments,
|
|
541
545
|
isRead: row.isRead,
|
|
542
546
|
location: row.location,
|
|
547
|
+
toRecipients: row.toRecipients,
|
|
548
|
+
ccRecipients: row.ccRecipients,
|
|
543
549
|
};
|
|
544
550
|
}
|
|
545
551
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxv-systems/mail-graph",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
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",
|