@octarq/plugin-mail 0.1.1 → 0.1.2

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/api.ts CHANGED
@@ -1,5 +1,3 @@
1
- // Mail feature API surface — the slice of the JSON API owned by the mail plugin.
2
- // Fully self-contained without relative host leaks.
3
1
 
4
2
  import { req } from "@octarq/plugin-sdk";
5
3
 
@@ -91,10 +89,10 @@ export interface Email {
91
89
  unsubscribeUrl?: string;
92
90
  read: boolean;
93
91
  note: string;
94
- attachments: string; // JSON string of Attachment[]
95
- authSpf: string; // pass|fail|softfail|neutral|none|""
96
- authDkim: string; // pass|fail|none|""
97
- authDmarc: string; // pass|fail|none|""
92
+ attachments: string;
93
+ authSpf: string;
94
+ authDkim: string;
95
+ authDmarc: string;
98
96
  receivedAt: string;
99
97
  category?: "bill" | "otp" | "marketing" | "important" | "general" | string;
100
98
  summary?: string;
@@ -122,14 +120,20 @@ export interface MailSuppression {
122
120
  updatedAt: string;
123
121
  }
124
122
 
123
+ export const mailAiStatus = () => req<{ configured: boolean; provider: string }>("GET", "/api/mail/ai/status");
124
+
125
+ export const summarizeEmail = (id: number) =>
126
+ req<{ summary: string; category?: string; importance?: number; otp?: string }>(
127
+ "POST",
128
+ `/api/mail/assist/summarize-email/${id}`,
129
+ );
130
+
125
131
  export const mailApi = {
126
- // Mailbox CRUD
127
132
  mailboxes: () => req<Mailbox[]>("GET", "/api/mailboxes"),
128
133
  createMailbox: (m: Partial<Mailbox>) => req<Mailbox>("POST", "/api/mailboxes", m),
129
134
  updateMailbox: (id: number, m: Partial<Mailbox>) => req<Mailbox>("PUT", `/api/mailboxes/${id}`, m),
130
135
  deleteMailbox: (id: number) => req("DELETE", `/api/mailboxes/${id}`),
131
136
 
132
- // Email read & mutation
133
137
  emails: (mailboxId?: number, params?: { q?: string; folder?: string; limit?: number; offset?: number }) => {
134
138
  const sp = new URLSearchParams();
135
139
  if (mailboxId) sp.set("mailbox", mailboxId.toString());
@@ -163,7 +167,6 @@ export const mailApi = {
163
167
  trackLinks?: boolean;
164
168
  }) => req("POST", "/api/emails/send", m),
165
169
 
166
- // Contacts
167
170
  contacts: (params?: { query?: string; q?: string; limit?: number; offset?: number }) => {
168
171
  const sp = new URLSearchParams();
169
172
  const q = params?.query ?? params?.q;
@@ -174,17 +177,14 @@ export const mailApi = {
174
177
  return req<MailContact[]>("GET", `/api/mail/contacts${qs ? "?" + qs : ""}`);
175
178
  },
176
179
 
177
- // Drafts
178
180
  saveDraft: (d: { id?: number; mailboxId?: number; to: string; subject: string; text: string; html?: string }) =>
179
181
  req<Email>("POST", "/api/mail/drafts", d),
180
182
  deleteDraft: (id: number) => req<{ ok: boolean }>("DELETE", `/api/mail/drafts/${id}`),
181
183
 
182
- // Suppressions
183
184
  suppressions: () => req<MailSuppression[]>("GET", "/api/mail/suppressions"),
184
185
  createSuppression: (address: string) => req<MailSuppression>("POST", "/api/mail/suppressions", { address }),
185
186
  deleteSuppression: (id: number) => req("DELETE", `/api/mail/suppressions/${id}`),
186
187
 
187
- // Domains (used for mailbox creation host selection)
188
188
  domains: (params?: { q?: string; limit?: number; offset?: number }) => {
189
189
  const sp = new URLSearchParams();
190
190
  if (params?.q) sp.set("q", params.q);
@@ -194,7 +194,6 @@ export const mailApi = {
194
194
  return req<Domain[]>("GET", `/api/domains${qs ? "?" + qs : ""}`);
195
195
  },
196
196
 
197
- // SMTP Senders
198
197
  smtpSenders: () => req<SMTPSender[]>("GET", "/api/smtp-senders"),
199
198
  createSMTPSender: (s: SMTPSenderInput) => req<SMTPSender>("POST", "/api/smtp-senders", s),
200
199
  updateSMTPSender: (id: number, s: Partial<SMTPSenderInput>) =>
@@ -202,22 +201,15 @@ export const mailApi = {
202
201
  deleteSMTPSender: (id: number) => req<void>("DELETE", `/api/smtp-senders/${id}`),
203
202
  testSMTPSender: (id: number) => req<{ ok: boolean }>("POST", `/api/smtp-senders/${id}/test`),
204
203
 
205
- // Settings & Inbound Token
206
- settings: () => req<MailSettingsData>("GET", "/api/settings"),
204
+ settings: () => req<MailSettingsData>("GET", "/api/mail/settings"),
207
205
  updateSettings: (s: Partial<MailSettingsData> & { inboundToken?: string }) =>
208
- req<any>("PUT", "/api/settings", s),
206
+ req<any>("PUT", "/api/mail/settings", s),
209
207
  inboundToken: () => req<{ inboundToken: string }>("GET", "/api/settings/inbound-token"),
210
208
 
211
- // AI Assist
212
- aiAssistStatus: () => req<{ configured: boolean; provider: string }>("GET", "/api/ai/assist/status"),
213
- aiSummarizeEmail: (id: number) =>
214
- req<{ summary: string; category?: string; importance?: number; otp?: string }>(
215
- "POST",
216
- `/api/ai/assist/summarize-email/${id}`,
217
- ),
209
+ mailAiStatus,
210
+ summarizeEmail,
218
211
 
219
- // Overview
220
- overview: (includeBot = false) => req<any>("GET", `/api/overview?include_bot=${includeBot}`),
212
+ overview: () => req<any>("GET", "/api/overview"),
221
213
  };
222
214
 
223
215
  export { mailApi as api };
package/i18n.ts CHANGED
@@ -34,7 +34,6 @@ export const mailI18n = {
34
34
  guideStep4: "To send replies, configure an SMTP relay via Settings.",
35
35
  allMailboxes: "All mailboxes",
36
36
  searchPlaceholder: "Search emails…",
37
- // Empty inbox states: the address / query render beside these in mono.
38
37
  emptyFilteredReason: "No messages match",
39
38
  clearSearch: "Clear search",
40
39
  emptyNoBoxesReason: "No mailbox configured yet.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octarq/plugin-mail",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Mailboxes, SMTP relay, and inbound webhook processing plugin for Octarq",
5
5
  "type": "module",
6
6
  "main": "./index.ts",
@@ -15,7 +15,7 @@ export function AuthBadges({
15
15
  if (!result || result === "none" || result === "") return null;
16
16
  const pass = result === "pass";
17
17
  const warn = result === "softfail" || result === "neutral";
18
- if (compact && pass) return null; // only show problems in list view
18
+ if (compact && pass) return null;
19
19
 
20
20
  let tone: "success" | "warning" | "danger" = "danger";
21
21
  if (pass) tone = "success";
package/pages/Compose.tsx CHANGED
@@ -20,8 +20,6 @@ export function Compose({
20
20
  const [subject, setSubject] = useState(draft?.subject ?? "");
21
21
  const [text, setText] = useState(draft?.text ?? "");
22
22
  const [smtpSenderId, setSmtpSenderId] = useState<number>(0);
23
- // Which registry owns smtpSenderId. The two registries number their rows
24
- // independently, so the ID alone cannot identify a sender.
25
23
  const [senderSource, setSenderSource] = useState<"local" | "integration" | null>(null);
26
24
  const [senders, setSenders] = useState<any[]>([]);
27
25
  const [loadingSenders, setLoadingSenders] = useState(true);
@@ -30,7 +28,6 @@ export function Compose({
30
28
  const [autoWrapLinksEnabled, setAutoWrapLinksEnabled] = useState(false);
31
29
  const [trackLinks, setTrackLinks] = useState(false);
32
30
 
33
- // Contacts autocomplete
34
31
  const [contacts, setContacts] = useState<MailContact[]>([]);
35
32
  const [showSuggestions, setShowSuggestions] = useState(false);
36
33
  const toContainerRef = useRef<HTMLDivElement>(null);
@@ -52,8 +49,6 @@ export function Compose({
52
49
  credentials: "same-origin",
53
50
  });
54
51
  if (res.status === 404) {
55
- // Core Vault is unavailable on this instance: the local SMTP sender
56
- // registry is the only source, so offer it instead of an empty list.
57
52
  const list = await mailApi.smtpSenders();
58
53
  if (cancelled) return;
59
54
  setSenderSource("local");
@@ -74,8 +69,6 @@ export function Compose({
74
69
  setSmtpSenderId(preferred ? preferred.id : 0);
75
70
  } catch {
76
71
  if (cancelled) return;
77
- // Do not guess at a sender when the lookup fails: sending through the
78
- // wrong registry is worse than asking the user to retry.
79
72
  setSenderSource(null);
80
73
  setSenders([]);
81
74
  setSmtpSenderId(0);
@@ -61,14 +61,14 @@ export function EmailViewForm({
61
61
  const [summary, setSummary] = useState("");
62
62
 
63
63
  useEffect(() => {
64
- mailApi.aiAssistStatus().then((s) => setAiEnabled(s.configured)).catch(() => {});
64
+ mailApi.mailAiStatus().then((s) => setAiEnabled(s.configured)).catch(() => {});
65
65
  }, []);
66
66
  useEffect(() => setSummary(""), [email.id]);
67
67
 
68
68
  async function summarize() {
69
69
  setAiBusy(true);
70
70
  try {
71
- const r = await mailApi.aiSummarizeEmail(email.id);
71
+ const r = await mailApi.summarizeEmail(email.id);
72
72
  setSummary(r.summary);
73
73
  } catch {
74
74
  setSummary(t("mail.aiSummaryFailed"));
@@ -20,7 +20,6 @@ export function FolderNav({ currentFolder, onSelectFolder }: FolderNavProps) {
20
20
 
21
21
  return (
22
22
  <TabBar
23
- className="flex-wrap"
24
23
  size="sm"
25
24
  value={currentFolder}
26
25
  onValueChange={(v) => onSelectFolder(v as MailFolder)}
@@ -23,9 +23,6 @@ export function MailSettings() {
23
23
 
24
24
  const adminView = s?.inboundTokenSet !== undefined;
25
25
 
26
- // The raw token is never part of the settings dump — it is fetched explicitly
27
- // from the admin-only /api/settings/inbound-token endpoint and masked until
28
- // the admin asks to see it.
29
26
  const loadToken = useCallback(async () => {
30
27
  if (tokenLoaded) return;
31
28
  try {
@@ -33,7 +30,6 @@ export function MailSettings() {
33
30
  setInboundToken(r.inboundToken);
34
31
  setTokenLoaded(true);
35
32
  } catch {
36
- // First-run org or a transient failure — keep the mask.
37
33
  }
38
34
  }, [tokenLoaded]);
39
35
 
@@ -52,8 +48,6 @@ export function MailSettings() {
52
48
  });
53
49
  toast.success(t("settings.saved"));
54
50
  if (tokenLoaded) {
55
- // A save may have rotated the token (clearing it mints a fresh one);
56
- // refresh so the displayed value and URL stay accurate.
57
51
  const r = await mailApi.inboundToken();
58
52
  setInboundToken(r.inboundToken);
59
53
  }
@@ -129,7 +123,7 @@ export function MailSettings() {
129
123
  <Input
130
124
  readOnly
131
125
  className="font-mono text-xs"
132
- value={`${location.origin}/api/v1/webhook/${s?.orgSlug || ""}/email/inbound/${displayed}`}
126
+ value={`${location.origin}/api/webhook/${s?.orgSlug || ""}/email/inbound/${displayed}`}
133
127
  onFocus={(e) => e.currentTarget.select()}
134
128
  />
135
129
  </Field>
@@ -12,7 +12,7 @@ export function MailTabs({ tab, onTabChange }: MailTabsProps) {
12
12
 
13
13
  return (
14
14
  <TabBar
15
- className="mb-6 flex-wrap"
15
+ className="mb-6"
16
16
  value={tab}
17
17
  onValueChange={(v) => onTabChange(v as MailTab)}
18
18
  items={[
@@ -41,7 +41,6 @@ export function MailboxBar({
41
41
  <div className="flex flex-wrap items-center justify-between gap-3">
42
42
  <div className="min-w-0 flex-1">
43
43
  <TabBar
44
- className="flex-wrap"
45
44
  size="sm"
46
45
  value={active === undefined ? "all" : String(active)}
47
46
  onValueChange={(v) => onSelect(v === "all" ? undefined : Number(v))}
@@ -4,10 +4,6 @@ import { NavLink } from "react-router-dom";
4
4
  import { mailApi, SMTPSender } from "../api";
5
5
  import { KeyRound, Send, Blocks } from "lucide-react";
6
6
 
7
- // Which registry owns the sender rows. An instance with Core Vault
8
- // mounted uses vault items; a standalone instance without vault uses
9
- // the local mail_smtp_senders table. The two registries number rows
10
- // independently, so a page must read exactly one of them.
11
7
  type SenderMode = "integration" | "local" | null;
12
8
 
13
9
  function formatIntegrationSenderSummary(s: any): string {
@@ -161,8 +157,6 @@ export function SMTPSenders() {
161
157
  </PageRows>
162
158
  </div>
163
159
  ) : senders.length === 0 ? (
164
- // The heading carries the add/open control, so the empty state states
165
- // the fact and adds no second button.
166
160
  <Empty reason={t("settings.noSmtpSenders")} className="mt-3">
167
161
  <Send />
168
162
  </Empty>
@@ -4,9 +4,6 @@ import { render, screen, waitFor } from "@testing-library/react";
4
4
  import { MemoryRouter } from "react-router-dom";
5
5
  import { I18nProvider } from "@octarq/plugin-sdk";
6
6
 
7
- // See links/pages/emptyState.test.tsx — same contract: the page's empty state
8
- // must render through the shared Empty primitive (tagged with a testid here),
9
- // never a handwritten copy.
10
7
  vi.mock("@octarq/plugin-sdk", async (importOriginal) => {
11
8
  const ui = await importOriginal<typeof import("@octarq/plugin-sdk")>();
12
9
  return {
@@ -195,7 +195,7 @@ describe("Mail Forms", () => {
195
195
  return jsonResponse({ ok: true });
196
196
  }
197
197
 
198
- if (method === "GET" && path === "/api/settings") {
198
+ if (method === "GET" && path === "/api/mail/settings") {
199
199
  return jsonResponse({ autoWrapLinks: true });
200
200
  }
201
201
 
@@ -253,18 +253,15 @@ describe("Mail Forms", () => {
253
253
 
254
254
  renderWithProviders(<Compose onClose={onClose} />);
255
255
 
256
- // Verify fields
257
256
  expect(screen.getByText("Compose mail")).toBeDefined();
258
257
  expect((screen.getByRole("button", { name: "Send mail" }) as HTMLButtonElement).disabled).toBe(true);
259
258
 
260
- // Wait for settings & senders to load and checkbox to appear
261
259
  await waitFor(() => {
262
260
  expect(screen.getByRole("checkbox")).toBeDefined();
263
261
  expect(screen.getAllByText("Corporate Mailgun (noreply@acme.com)").length).toBeGreaterThan(0);
264
262
  });
265
263
  expect(document.body.textContent).not.toContain("undefined");
266
264
 
267
- // Fill in recipients, subject, body
268
265
  const toInput = screen.getByPlaceholderText("hello@world.com");
269
266
  fireEvent.change(toInput, {
270
267
  target: { value: "alice@example.com, bob@example.com" },
@@ -280,7 +277,6 @@ describe("Mail Forms", () => {
280
277
  target: { value: "team@acme.com" },
281
278
  });
282
279
 
283
- // Submit email
284
280
  const sendBtn = screen.getByRole("button", { name: "Send mail" });
285
281
  expect((sendBtn as HTMLButtonElement).disabled).toBe(false);
286
282
  fireEvent.click(sendBtn);
@@ -289,7 +285,6 @@ describe("Mail Forms", () => {
289
285
  expect(screen.getByText("Message sent.")).toBeDefined();
290
286
  });
291
287
 
292
- // Verify the POST payload sent to /api/emails/send
293
288
  const sendCall = fetchMock.mock.calls.find(c => {
294
289
  const url = typeof c[0] === "string" ? c[0] : (c[0] as Request).url;
295
290
  return url.includes("/api/emails/send");
@@ -306,7 +301,6 @@ describe("Mail Forms", () => {
306
301
  trackLinks: true,
307
302
  });
308
303
 
309
- // Click Done
310
304
  fireEvent.click(screen.getByRole("button", { name: "Done" }));
311
305
  expect(onClose).toHaveBeenCalledTimes(1);
312
306
  });
@@ -342,7 +336,7 @@ describe("Mail Forms", () => {
342
336
  const path = urlObj.pathname;
343
337
 
344
338
  if (method === "GET" && (path === "/api/vault/items" || path === "/api/smtp-senders")) return jsonResponse(mockIntegrations);
345
- if (method === "GET" && path === "/api/settings") return jsonResponse({});
339
+ if (method === "GET" && path === "/api/mail/settings") return jsonResponse({});
346
340
  if (method === "POST" && path === "/api/emails/send") {
347
341
  return jsonResponse({ message: "SMTP relay authentication failed" }, 400);
348
342
  }
@@ -374,7 +368,7 @@ describe("Mail Forms", () => {
374
368
  const urlObj = new URL(rawUrl, "http://localhost");
375
369
  const path = urlObj.pathname;
376
370
  if (method === "GET" && (path === "/api/vault/items" || path === "/api/smtp-senders")) return jsonResponse([]);
377
- if (method === "GET" && path === "/api/settings") return jsonResponse({});
371
+ if (method === "GET" && path === "/api/mail/settings") return jsonResponse({});
378
372
  throw new Error(`Unhandled fetch: ${method} ${rawUrl}`);
379
373
  });
380
374
 
@@ -386,7 +380,6 @@ describe("Mail Forms", () => {
386
380
  });
387
381
  });
388
382
 
389
- // Standalone instances without Core Vault still serve the local sender registry.
390
383
  it("falls back to local SMTP senders when Core Vault is absent", async () => {
391
384
  fetchMock.mockImplementation(async (input: RequestInfo | URL, init?: RequestInit) => {
392
385
  const method = (init?.method ?? "GET").toUpperCase();
@@ -396,7 +389,7 @@ describe("Mail Forms", () => {
396
389
 
397
390
  if (method === "GET" && path === "/api/vault/items") return jsonResponse({ detail: "Not Found" }, 404);
398
391
  if (method === "GET" && path === "/api/smtp-senders") return jsonResponse(mockSenders);
399
- if (method === "GET" && path === "/api/settings") return jsonResponse({});
392
+ if (method === "GET" && path === "/api/mail/settings") return jsonResponse({});
400
393
  if (method === "POST" && path === "/api/emails/send") return jsonResponse({ ok: true });
401
394
  throw new Error(`Unhandled fetch: ${method} ${rawUrl}`);
402
395
  });
@@ -497,7 +490,6 @@ describe("Mail Forms", () => {
497
490
  expect(onSaved).toHaveBeenCalledTimes(1);
498
491
  });
499
492
 
500
- // Delete mailbox with confirmation
501
493
  const delBtn = screen.getByRole("button", { name: "Delete mailbox completely" });
502
494
  fireEvent.click(delBtn);
503
495
 
@@ -530,7 +522,6 @@ describe("Mail Forms", () => {
530
522
 
531
523
  expect(document.body.textContent).not.toContain("undefined");
532
524
 
533
- // Test connection goes through Core Vault, not the local table.
534
525
  fireEvent.click(screen.getAllByRole("button", { name: "Test" })[0]);
535
526
 
536
527
  await waitFor(() => {
@@ -541,7 +532,6 @@ describe("Mail Forms", () => {
541
532
  expect(tested).toBe(true);
542
533
  });
543
534
 
544
- // The local CRUD surfaces stay absent while Core Vault is authoritative.
545
535
  expect(screen.queryByRole("button", { name: "Add SMTP" })).toBeNull();
546
536
  expect(screen.queryByRole("button", { name: "Edit SMTP" })).toBeNull();
547
537
  expect(screen.queryByRole("button", { name: "Remove" })).toBeNull();
@@ -583,7 +573,6 @@ describe("Mail Forms", () => {
583
573
  });
584
574
  });
585
575
 
586
- // Standalone instances without Core Vault serve the local registry and keep its CRUD controls.
587
576
  it("serves the local sender registry when Core Vault is absent", async () => {
588
577
  fetchMock.mockImplementation(async (input: RequestInfo | URL, init?: RequestInit) => {
589
578
  const method = (init?.method ?? "GET").toUpperCase();
@@ -619,8 +608,6 @@ describe("Mail Forms", () => {
619
608
  expect(tested).toBe(true);
620
609
  });
621
610
 
622
- // The local form is reachable and posts the password under the wire
623
- // field the server reads.
624
611
  fireEvent.click(screen.getByRole("button", { name: "Add SMTP" }));
625
612
  await waitFor(() => {
626
613
  expect(screen.getByText("Add SMTP Sender")).toBeDefined();
@@ -659,7 +646,6 @@ describe("Mail Forms", () => {
659
646
  expect(screen.getByText("Manual")).toBeDefined();
660
647
  });
661
648
 
662
- // Add address
663
649
  const addBtn = screen.getByRole("button", { name: "Add address" });
664
650
  fireEvent.click(addBtn);
665
651
 
@@ -675,7 +661,6 @@ describe("Mail Forms", () => {
675
661
  expect(screen.queryByText("Add to suppression list")).toBeNull();
676
662
  });
677
663
 
678
- // Remove suppression item with confirmation
679
664
  const delButtons = screen.getAllByTitle("Remove");
680
665
  fireEvent.click(delButtons[0]);
681
666
 
@@ -67,8 +67,8 @@ describe("Mail Enhancements", () => {
67
67
  receivedAt: new Date().toISOString(),
68
68
  });
69
69
  }
70
- if (method === "GET" && path === "/api/ai-assist/status") {
71
- return jsonResponse({ configured: false });
70
+ if (method === "GET" && path === "/api/mail/ai/status") {
71
+ return jsonResponse({ configured: false, provider: "" });
72
72
  }
73
73
 
74
74
  throw new Error(`Unhandled fetch in test: ${method} ${rawUrl}`);
@@ -127,7 +127,6 @@ describe("Mail Enhancements", () => {
127
127
  />
128
128
  );
129
129
 
130
- // Typing in To should load contact suggestions
131
130
  const toInput = screen.getByPlaceholderText("hello@world.com");
132
131
  fireEvent.focus(toInput);
133
132
 
@@ -138,7 +137,6 @@ describe("Mail Enhancements", () => {
138
137
  fireEvent.mouseDown(screen.getByText("Key Contact <contact@example.com>"));
139
138
  expect((toInput as HTMLInputElement).value).toBe("contact@example.com");
140
139
 
141
- // Click Save Draft
142
140
  const saveDraftBtn = screen.getByRole("button", { name: "Save draft" });
143
141
  fireEvent.click(saveDraftBtn);
144
142
 
@@ -251,4 +249,53 @@ describe("Mail Enhancements", () => {
251
249
  expect(screen.getByTestId("importance-dots")).toBeDefined();
252
250
  expect(screen.getByTestId("importance-dots").textContent).toBe("●●●●○");
253
251
  });
252
+
253
+ it("checks AI status and summarizes email via plugin endpoints", async () => {
254
+ fetchMock.mockImplementation(async (input: RequestInfo | URL, init?: RequestInit) => {
255
+ const method = (init?.method ?? "GET").toUpperCase();
256
+ const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
257
+ const urlObj = new URL(rawUrl, "http://localhost");
258
+ const path = urlObj.pathname;
259
+
260
+ if (method === "GET" && path === "/api/mail/ai/status") {
261
+ return jsonResponse({ configured: true, provider: "claude" });
262
+ }
263
+ if (method === "POST" && path === "/api/mail/assist/summarize-email/77") {
264
+ return jsonResponse({ summary: "Invoice due Friday for $49." });
265
+ }
266
+ throw new Error(`Unhandled fetch in test: ${method} ${rawUrl}`);
267
+ });
268
+
269
+ const mockEmail: Email = {
270
+ id: 77,
271
+ mailboxId: 1,
272
+ from: "billing@acme.com",
273
+ to: "user@example.com",
274
+ subject: "Invoice Due",
275
+ text: "Your invoice for $49 is due Friday.",
276
+ html: "",
277
+ read: true,
278
+ note: "",
279
+ attachments: "[]",
280
+ authSpf: "pass",
281
+ authDkim: "pass",
282
+ authDmarc: "pass",
283
+ receivedAt: "2026-10-24T10:00:00Z",
284
+ };
285
+
286
+ renderWithProviders(
287
+ <EmailViewForm
288
+ email={mockEmail}
289
+ onClose={vi.fn()}
290
+ onReply={vi.fn()}
291
+ onChanged={vi.fn()}
292
+ />
293
+ );
294
+
295
+ const btn = await screen.findByRole("button", { name: "AI summary" });
296
+ fireEvent.click(btn);
297
+
298
+ const box = await screen.findByTestId("email-summary-box");
299
+ expect(box.textContent).toContain("Invoice due Friday for $49.");
300
+ });
254
301
  });
@@ -0,0 +1,105 @@
1
+ // @vitest-environment happy-dom
2
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
3
+ import { cleanup, render, screen, waitFor } from "@testing-library/react";
4
+ import { I18nProvider, registerUIPlugin, resetRegistry } from "@octarq/plugin-sdk";
5
+ import mailPlugin from "../index";
6
+ import { MailSettings } from "./MailSettings";
7
+
8
+ function jsonResponse(body: unknown, status = 200) {
9
+ return {
10
+ ok: status >= 200 && status < 300,
11
+ status,
12
+ json: async () => body,
13
+ headers: { get: (name: string) => (name === "content-type" ? "application/json" : null) },
14
+ };
15
+ }
16
+
17
+ describe("MailSettings inbound webhook URL", () => {
18
+ beforeEach(() => {
19
+ cleanup();
20
+ resetRegistry();
21
+ registerUIPlugin(mailPlugin);
22
+ });
23
+
24
+ afterEach(() => {
25
+ cleanup();
26
+ vi.restoreAllMocks();
27
+ });
28
+
29
+ it("displays /api/webhook/{orgSlug}/email/inbound/... instead of /api/v1/webhook/...", async () => {
30
+ const fetchMock = vi.fn(async (input: RequestInfo | URL) => {
31
+ const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
32
+ const path = new URL(rawUrl, "http://localhost").pathname;
33
+ if (path === "/api/mail/settings") {
34
+ return jsonResponse({
35
+ orgSlug: "acme-corp",
36
+ inboundTokenSet: true,
37
+ reservedMailboxes: "admin",
38
+ catchAll: true,
39
+ autoWrapLinks: false,
40
+ });
41
+ }
42
+ if (path === "/api/settings/inbound-token") {
43
+ return jsonResponse({ inboundToken: "secret-tok-123" });
44
+ }
45
+ throw new Error(`Unexpected fetch: ${rawUrl}`);
46
+ });
47
+ vi.stubGlobal("fetch", fetchMock);
48
+
49
+ render(
50
+ <I18nProvider>
51
+ <MailSettings />
52
+ </I18nProvider>
53
+ );
54
+
55
+ const input = (await screen.findByDisplayValue(/\/api\/webhook\/acme-corp\/email\/inbound\//)) as HTMLInputElement;
56
+ expect(input.value).toContain("/api/webhook/acme-corp/email/inbound/");
57
+ expect(input.value).not.toContain("/api/v1/webhook/");
58
+ });
59
+
60
+ it("calls PUT /api/mail/settings when saving settings", async () => {
61
+ let putBody: any = null;
62
+ const fetchMock = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
63
+ const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
64
+ const path = new URL(rawUrl, "http://localhost").pathname;
65
+ const method = init?.method || "GET";
66
+ if (path === "/api/mail/settings" && method === "GET") {
67
+ return jsonResponse({
68
+ orgSlug: "acme-corp",
69
+ inboundTokenSet: false,
70
+ reservedMailboxes: "admin",
71
+ catchAll: false,
72
+ autoWrapLinks: false,
73
+ });
74
+ }
75
+ if (path === "/api/mail/settings" && method === "PUT") {
76
+ putBody = JSON.parse(init?.body as string);
77
+ return jsonResponse({
78
+ orgSlug: "acme-corp",
79
+ reservedMailboxes: putBody.reservedMailboxes,
80
+ catchAll: putBody.catchAll,
81
+ autoWrapLinks: putBody.autoWrapLinks,
82
+ });
83
+ }
84
+ throw new Error(`Unexpected fetch: ${method} ${rawUrl}`);
85
+ });
86
+ vi.stubGlobal("fetch", fetchMock);
87
+
88
+ render(
89
+ <I18nProvider>
90
+ <MailSettings />
91
+ </I18nProvider>
92
+ );
93
+
94
+ await screen.findByDisplayValue("admin");
95
+ const saveBtn = screen.getByRole("button", { name: /saveSettings/i });
96
+ saveBtn.click();
97
+
98
+ await waitFor(() => {
99
+ expect(putBody).toBeDefined();
100
+ expect(putBody.reservedMailboxes).toBe("admin");
101
+ expect(putBody.catchAll).toBe(false);
102
+ expect(putBody.autoWrapLinks).toBe(false);
103
+ });
104
+ });
105
+ });
@@ -14,8 +14,6 @@ export default function MailSetupStepWidget() {
14
14
  let cancelled = false;
15
15
  (async () => {
16
16
  try {
17
- // Core Vault owns mail senders when it is mounted. Count the
18
- // same registry the mail pages offer, not just the local table.
19
17
  const res = await fetch("/api/vault/items?provider_type=communication", {
20
18
  credentials: "same-origin",
21
19
  });
@@ -32,7 +30,6 @@ export default function MailSetupStepWidget() {
32
30
  );
33
31
  if (!cancelled) setSmtpCount(list.length);
34
32
  } catch {
35
- // Leave the step in the unknown state instead of reporting zero.
36
33
  }
37
34
  })();
38
35
  return () => {