@dxv-systems/mail-graph 0.8.0 → 0.9.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 CHANGED
@@ -10,7 +10,7 @@ npm i @dxv-systems/mail-graph
10
10
 
11
11
  ## Never deletes customer mail
12
12
 
13
- There is no delete except `deleteDraft`, which refuses anything that is not a draft. The general request layer accepts only `GET`, `POST` and `PATCH`; anything else throws `GraphUsageError` (`MethodNotAllowed`) before a request is made. The one `PUT` is a chunk of an attachment upload session, sent to the `uploadUrl` Graph returned for that session. Customer mail is moved (`moveMessage`), never removed.
13
+ There is no delete except `deleteDraft` and `removeAttachment`, which both refuse anything that is not a draft. The general request layer accepts only `GET`, `POST` and `PATCH`; anything else throws `GraphUsageError` (`MethodNotAllowed`) before a request is made. The one `PUT` is a chunk of an attachment upload session, sent to the `uploadUrl` Graph returned for that session. Customer mail is moved (`moveMessage`), never removed.
14
14
 
15
15
  `deleteDraft(draftId)` is for drafts the helpdesk created itself. It first reads `isDraft`; unless that is exactly `true` it returns `{ status: "not_draft" }` and sends no DELETE. It returns `{ status: "gone" }` on a 404 (at the read or at the DELETE) and `{ status: "deleted" }` after a successful DELETE. A 429 or 503 on the DELETE is retried (a repeat is harmless); a network error is not. Per Graph's documentation a DELETE moves the item to Deleted Items; that is unverified until the real-tenant test. There is a small window: if someone sends the draft from Outlook between the read and the DELETE, the sent copy could end up in Deleted Items. Tests prove every DELETE is preceded by an `isDraft: true` read of the same message.
16
16
 
@@ -98,6 +98,15 @@ await support.sendDraft(draft.id); // lands i
98
98
 
99
99
  `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.
100
100
 
101
+ ## Editing a draft
102
+
103
+ ```ts
104
+ await support.updateDraft(draftId, { to, cc, bcc, subject }); // only the fields given; { status: "updated" | "gone" | "not_draft" }
105
+ await support.removeAttachment(draftId, attachmentId); // { status: "removed" | "gone" | "not_draft" }
106
+ ```
107
+
108
+ For any draft in the mailbox, also one made in Outlook. Both read `isDraft` first, like `deleteDraft`, and write nothing unless it is exactly `true`; a 404 at the read or the write is `gone`. `updateDraft` refuses an empty `to` and an empty change; an empty `cc` or `bcc` clears it. `updateDraftBody` still sets the body; `listAttachments` gives the ids for `removeAttachment`.
109
+
101
110
  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.
102
111
 
103
112
  ## State, folders, sending
package/dist/http.js CHANGED
@@ -137,8 +137,8 @@ function createHttp(options) {
137
137
  });
138
138
  },
139
139
  async deleteMessage(spec) {
140
- if (!/^\/users\/[^/?#]+\/messages\/[^/?#]+$/.test(spec.path)) {
141
- throw new errors_1.GraphUsageError("InvalidArgument", "deleteMessage only accepts /users/{mailbox}/messages/{id}.");
140
+ if (!/^\/users\/[^/?#]+\/messages\/[^/?#]+(\/attachments\/[^/?#]+)?$/.test(spec.path)) {
141
+ throw new errors_1.GraphUsageError("InvalidArgument", "deleteMessage only accepts /users/{mailbox}/messages/{id}[/attachments/{id}].");
142
142
  }
143
143
  return execute({
144
144
  mailbox: spec.mailbox,
package/dist/mailbox.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Http } from "./http";
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";
2
+ import type { AccessCheckResult, AttachmentInfo, CreateForwardOptions, CreateReplyOptions, DraftOverrides, 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
4
  interface RawExtendedProperty {
5
5
  id?: string;
@@ -20,9 +20,15 @@ export interface MailboxClient {
20
20
  createReply(messageId: string, options?: CreateReplyOptions): Promise<Message>;
21
21
  createForward(messageId: string, options?: CreateForwardOptions): Promise<Message>;
22
22
  updateDraftBody(draftId: string, body: MessageBody): Promise<void>;
23
+ updateDraft(draftId: string, changes: DraftOverrides): Promise<{
24
+ status: "updated" | "gone" | "not_draft";
25
+ }>;
23
26
  addAttachment(draftId: string, attachment: OutgoingAttachment): Promise<{
24
27
  id?: string;
25
28
  }>;
29
+ removeAttachment(draftId: string, attachmentId: string): Promise<{
30
+ status: "removed" | "gone" | "not_draft";
31
+ }>;
26
32
  sendDraft(draftId: string): Promise<void>;
27
33
  markRead(messageId: string, isRead?: boolean): Promise<void>;
28
34
  setCategories(messageId: string, categories: string[]): Promise<void>;
package/dist/mailbox.js CHANGED
@@ -167,6 +167,20 @@ function createMailboxClient(http, address) {
167
167
  const result = await http.request({ mailbox: address, method: "GET", path, prefer });
168
168
  return (result.data ?? {});
169
169
  }
170
+ async function onDraft(path, done, write) {
171
+ try {
172
+ const current = await getJson(`${path}${query({ $select: "isDraft" })}`);
173
+ if (current.isDraft !== true)
174
+ return { status: "not_draft" };
175
+ await write();
176
+ return { status: done };
177
+ }
178
+ catch (error) {
179
+ if (error instanceof errors_1.GraphError && error.status === 404)
180
+ return { status: "gone" };
181
+ throw error;
182
+ }
183
+ }
170
184
  async function createDraftFrom(messageId, action, options) {
171
185
  const message = draftOverrides(options);
172
186
  const body = {
@@ -521,18 +535,19 @@ function createMailboxClient(http, address) {
521
535
  },
522
536
  async deleteDraft(draftId) {
523
537
  const path = `${user}/messages/${requireId(draftId, "draft id")}`;
524
- try {
525
- const current = await getJson(`${path}${query({ $select: "isDraft" })}`);
526
- if (current.isDraft !== true)
527
- return { status: "not_draft" };
528
- await http.deleteMessage({ mailbox: address, path });
529
- return { status: "deleted" };
530
- }
531
- catch (error) {
532
- if (error instanceof errors_1.GraphError && error.status === 404)
533
- return { status: "gone" };
534
- throw error;
535
- }
538
+ return onDraft(path, "deleted", () => http.deleteMessage({ mailbox: address, path }));
539
+ },
540
+ async updateDraft(draftId, changes) {
541
+ const path = `${user}/messages/${requireId(draftId, "draft id")}`;
542
+ const body = draftOverrides(changes);
543
+ if (!body)
544
+ throw new errors_1.GraphUsageError("InvalidArgument", "updateDraft needs at least one of to, cc, bcc and subject.");
545
+ return onDraft(path, "updated", () => http.request({ mailbox: address, method: "PATCH", path, body }));
546
+ },
547
+ async removeAttachment(draftId, attachmentId) {
548
+ const path = `${user}/messages/${requireId(draftId, "draft id")}`;
549
+ const attachmentPath = `${path}/attachments/${requireId(attachmentId, "attachment id")}`;
550
+ return onDraft(path, "removed", () => http.deleteMessage({ mailbox: address, path: attachmentPath }));
536
551
  },
537
552
  async forward(messageId, input) {
538
553
  await http.request({
@@ -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.8.0 @dxv-systems/helpdesk@0.18.0 @vercel/oidc@4.0.1
20
+ npm install --save-exact @dxv-systems/mail-graph@0.9.1 @dxv-systems/helpdesk@0.18.0 @vercel/oidc@4.0.8
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.8.0",
3
+ "version": "0.9.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",