@octarq/plugin-mail 0.1.0 → 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.
@@ -39,8 +39,30 @@ const mockIntegrations = [
39
39
  provider: "smtp",
40
40
  providerType: "communication",
41
41
  configured: true,
42
- summary: "noreply@acme.com via smtp.mailgun.org:587",
43
42
  isDefault: true,
43
+ metadata: {
44
+ fromEmail: "noreply@acme.com",
45
+ fromName: "Acme Mail",
46
+ smtpHost: "smtp.mailgun.org",
47
+ smtpPort: 587,
48
+ },
49
+ },
50
+ {
51
+ id: 2,
52
+ name: "Transactional Resend",
53
+ provider: "resend",
54
+ providerType: "communication",
55
+ configured: true,
56
+ metadata: {
57
+ fromEmail: "alerts@acme.com",
58
+ },
59
+ },
60
+ {
61
+ id: 3,
62
+ name: "Bare SMTP",
63
+ provider: "smtp",
64
+ providerType: "communication",
65
+ configured: false,
44
66
  },
45
67
  ];
46
68
 
@@ -92,6 +114,7 @@ const testResources = {
92
114
  noSmtpConfigured: "No SMTP outgoing senders configured.",
93
115
  noSmtpSenders: "No SMTP outgoing senders configured.",
94
116
  smtpPasswordSet: "password set",
117
+ smtpNoPassword: "no password",
95
118
  integrationsHubBanner: "Manage third-party credentials and cloud provider integrations centrally.",
96
119
  openIntegrationsHub: "Integrations Hub",
97
120
  addSmtpSender: "Add SMTP Sender",
@@ -147,10 +170,10 @@ describe("Mail Forms", () => {
147
170
  const urlObj = new URL(rawUrl, "http://localhost");
148
171
  const path = urlObj.pathname;
149
172
 
150
- if (method === "GET" && path === "/api/integrations") {
173
+ if (method === "GET" && path === "/api/vault/items") {
151
174
  return jsonResponse(mockIntegrations);
152
175
  }
153
- if (method === "POST" && path.startsWith("/api/integrations/") && path.endsWith("/test")) {
176
+ if (method === "POST" && path.startsWith("/api/vault/items/") && path.endsWith("/test")) {
154
177
  return jsonResponse({ ok: true, message: "Sent test email via Corporate Mailgun." });
155
178
  }
156
179
 
@@ -172,7 +195,7 @@ describe("Mail Forms", () => {
172
195
  return jsonResponse({ ok: true });
173
196
  }
174
197
 
175
- if (method === "GET" && path === "/api/settings") {
198
+ if (method === "GET" && path === "/api/mail/settings") {
176
199
  return jsonResponse({ autoWrapLinks: true });
177
200
  }
178
201
 
@@ -230,16 +253,15 @@ describe("Mail Forms", () => {
230
253
 
231
254
  renderWithProviders(<Compose onClose={onClose} />);
232
255
 
233
- // Verify fields
234
256
  expect(screen.getByText("Compose mail")).toBeDefined();
235
257
  expect((screen.getByRole("button", { name: "Send mail" }) as HTMLButtonElement).disabled).toBe(true);
236
258
 
237
- // Wait for settings & senders to load and checkbox to appear
238
259
  await waitFor(() => {
239
260
  expect(screen.getByRole("checkbox")).toBeDefined();
261
+ expect(screen.getAllByText("Corporate Mailgun (noreply@acme.com)").length).toBeGreaterThan(0);
240
262
  });
263
+ expect(document.body.textContent).not.toContain("undefined");
241
264
 
242
- // Fill in recipients, subject, body
243
265
  const toInput = screen.getByPlaceholderText("hello@world.com");
244
266
  fireEvent.change(toInput, {
245
267
  target: { value: "alice@example.com, bob@example.com" },
@@ -255,7 +277,6 @@ describe("Mail Forms", () => {
255
277
  target: { value: "team@acme.com" },
256
278
  });
257
279
 
258
- // Submit email
259
280
  const sendBtn = screen.getByRole("button", { name: "Send mail" });
260
281
  expect((sendBtn as HTMLButtonElement).disabled).toBe(false);
261
282
  fireEvent.click(sendBtn);
@@ -264,7 +285,6 @@ describe("Mail Forms", () => {
264
285
  expect(screen.getByText("Message sent.")).toBeDefined();
265
286
  });
266
287
 
267
- // Verify the POST payload sent to /api/emails/send
268
288
  const sendCall = fetchMock.mock.calls.find(c => {
269
289
  const url = typeof c[0] === "string" ? c[0] : (c[0] as Request).url;
270
290
  return url.includes("/api/emails/send");
@@ -281,7 +301,6 @@ describe("Mail Forms", () => {
281
301
  trackLinks: true,
282
302
  });
283
303
 
284
- // Click Done
285
304
  fireEvent.click(screen.getByRole("button", { name: "Done" }));
286
305
  expect(onClose).toHaveBeenCalledTimes(1);
287
306
  });
@@ -316,8 +335,8 @@ describe("Mail Forms", () => {
316
335
  const urlObj = new URL(rawUrl, "http://localhost");
317
336
  const path = urlObj.pathname;
318
337
 
319
- if (method === "GET" && (path === "/api/integrations" || path === "/api/smtp-senders")) return jsonResponse(mockIntegrations);
320
- if (method === "GET" && path === "/api/settings") return jsonResponse({});
338
+ if (method === "GET" && (path === "/api/vault/items" || path === "/api/smtp-senders")) return jsonResponse(mockIntegrations);
339
+ if (method === "GET" && path === "/api/mail/settings") return jsonResponse({});
321
340
  if (method === "POST" && path === "/api/emails/send") {
322
341
  return jsonResponse({ message: "SMTP relay authentication failed" }, 400);
323
342
  }
@@ -348,8 +367,8 @@ describe("Mail Forms", () => {
348
367
  const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
349
368
  const urlObj = new URL(rawUrl, "http://localhost");
350
369
  const path = urlObj.pathname;
351
- if (method === "GET" && (path === "/api/integrations" || path === "/api/smtp-senders")) return jsonResponse([]);
352
- if (method === "GET" && path === "/api/settings") return jsonResponse({});
370
+ if (method === "GET" && (path === "/api/vault/items" || path === "/api/smtp-senders")) return jsonResponse([]);
371
+ if (method === "GET" && path === "/api/mail/settings") return jsonResponse({});
353
372
  throw new Error(`Unhandled fetch: ${method} ${rawUrl}`);
354
373
  });
355
374
 
@@ -361,18 +380,16 @@ describe("Mail Forms", () => {
361
380
  });
362
381
  });
363
382
 
364
- // Standalone Core has no Integrations Hub. The local sender registry must
365
- // still be usable, and the send must name that registry.
366
- it("falls back to local SMTP senders when the Integrations Hub is absent", async () => {
383
+ it("falls back to local SMTP senders when Core Vault is absent", async () => {
367
384
  fetchMock.mockImplementation(async (input: RequestInfo | URL, init?: RequestInit) => {
368
385
  const method = (init?.method ?? "GET").toUpperCase();
369
386
  const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
370
387
  const urlObj = new URL(rawUrl, "http://localhost");
371
388
  const path = urlObj.pathname;
372
389
 
373
- if (method === "GET" && path === "/api/integrations") return jsonResponse({ detail: "Not Found" }, 404);
390
+ if (method === "GET" && path === "/api/vault/items") return jsonResponse({ detail: "Not Found" }, 404);
374
391
  if (method === "GET" && path === "/api/smtp-senders") return jsonResponse(mockSenders);
375
- if (method === "GET" && path === "/api/settings") return jsonResponse({});
392
+ if (method === "GET" && path === "/api/mail/settings") return jsonResponse({});
376
393
  if (method === "POST" && path === "/api/emails/send") return jsonResponse({ ok: true });
377
394
  throw new Error(`Unhandled fetch: ${method} ${rawUrl}`);
378
395
  });
@@ -473,7 +490,6 @@ describe("Mail Forms", () => {
473
490
  expect(onSaved).toHaveBeenCalledTimes(1);
474
491
  });
475
492
 
476
- // Delete mailbox with confirmation
477
493
  const delBtn = screen.getByRole("button", { name: "Delete mailbox completely" });
478
494
  fireEvent.click(delBtn);
479
495
 
@@ -491,40 +507,61 @@ describe("Mail Forms", () => {
491
507
  });
492
508
 
493
509
  describe("SMTPSenders", () => {
494
- it("uses the Integrations Hub when it is mounted and hides the local sender form", async () => {
510
+ it("uses Core Vault when it is mounted and hides the local sender form", async () => {
495
511
  renderWithProviders(<SMTPSenders />);
496
512
 
497
513
  await waitFor(() => {
498
514
  expect(screen.getByText("Corporate Mailgun")).toBeDefined();
499
515
  expect(screen.getByText("noreply@acme.com via smtp.mailgun.org:587")).toBeDefined();
500
- expect(screen.getByText("password set")).toBeDefined();
516
+ expect(screen.getByText("alerts@acme.com")).toBeDefined();
517
+ expect(screen.getByText("Bare SMTP")).toBeDefined();
518
+ expect(screen.getAllByText("password set").length).toBeGreaterThan(0);
519
+ expect(screen.getByText("no password")).toBeDefined();
501
520
  expect(screen.getByText("Manage third-party credentials and cloud provider integrations centrally.")).toBeDefined();
502
521
  });
503
522
 
504
- // Test connection goes through the hub, not the local table.
505
- fireEvent.click(screen.getByRole("button", { name: "Test" }));
523
+ expect(document.body.textContent).not.toContain("undefined");
524
+
525
+ fireEvent.click(screen.getAllByRole("button", { name: "Test" })[0]);
506
526
 
507
527
  await waitFor(() => {
508
528
  const tested = fetchMock.mock.calls.some((c) => {
509
529
  const url = typeof c[0] === "string" ? c[0] : (c[0] as Request).url;
510
- return url.includes("/api/integrations/1/test");
530
+ return url.includes("/api/vault/items/1/test");
511
531
  });
512
532
  expect(tested).toBe(true);
513
533
  });
514
534
 
515
- // The local CRUD surfaces stay absent while the hub is authoritative.
516
535
  expect(screen.queryByRole("button", { name: "Add SMTP" })).toBeNull();
517
536
  expect(screen.queryByRole("button", { name: "Edit SMTP" })).toBeNull();
518
537
  expect(screen.queryByRole("button", { name: "Remove" })).toBeNull();
519
538
  });
520
539
 
521
- it("renders empty state with deep link when the hub has no senders", async () => {
540
+ it("unwraps { body: [...] } envelope from Core Vault API", async () => {
541
+ fetchMock.mockImplementation(async (input: RequestInfo | URL, init?: RequestInit) => {
542
+ const method = (init?.method ?? "GET").toUpperCase();
543
+ const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
544
+ const urlObj = new URL(rawUrl, "http://localhost");
545
+ if (method === "GET" && urlObj.pathname === "/api/vault/items" && urlObj.searchParams.get("provider_type") === "communication") {
546
+ return jsonResponse({ body: mockIntegrations });
547
+ }
548
+ throw new Error(`Unhandled fetch: ${method} ${rawUrl}`);
549
+ });
550
+
551
+ renderWithProviders(<SMTPSenders />);
552
+
553
+ await waitFor(() => {
554
+ expect(screen.getByText("Corporate Mailgun")).toBeDefined();
555
+ });
556
+ });
557
+
558
+ it("renders empty state with deep link when Core Vault has no senders", async () => {
522
559
  fetchMock.mockImplementation(async (input: RequestInfo | URL, init?: RequestInit) => {
523
560
  const method = (init?.method ?? "GET").toUpperCase();
524
561
  const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
525
562
  const urlObj = new URL(rawUrl, "http://localhost");
526
563
  const path = urlObj.pathname;
527
- if (method === "GET" && path === "/api/integrations") return jsonResponse([]);
564
+ if (method === "GET" && path === "/api/vault/items") return jsonResponse([]);
528
565
  throw new Error(`Unhandled fetch: ${method} ${rawUrl}`);
529
566
  });
530
567
 
@@ -536,16 +573,14 @@ describe("Mail Forms", () => {
536
573
  });
537
574
  });
538
575
 
539
- // Standalone Core mounts no Integrations Hub, so the page must serve the
540
- // local registry and keep its CRUD controls.
541
- it("serves the local sender registry when the Integrations Hub is absent", async () => {
576
+ it("serves the local sender registry when Core Vault is absent", async () => {
542
577
  fetchMock.mockImplementation(async (input: RequestInfo | URL, init?: RequestInit) => {
543
578
  const method = (init?.method ?? "GET").toUpperCase();
544
579
  const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
545
580
  const urlObj = new URL(rawUrl, "http://localhost");
546
581
  const path = urlObj.pathname;
547
582
 
548
- if (method === "GET" && path === "/api/integrations") return jsonResponse({ detail: "Not Found" }, 404);
583
+ if (method === "GET" && path === "/api/vault/items") return jsonResponse({ detail: "Not Found" }, 404);
549
584
  if (method === "GET" && path === "/api/smtp-senders") return jsonResponse(mockSenders);
550
585
  if (method === "POST" && path === "/api/smtp-senders/1/test") return jsonResponse({ ok: true });
551
586
  if (method === "POST" && path === "/api/smtp-senders") {
@@ -573,8 +608,6 @@ describe("Mail Forms", () => {
573
608
  expect(tested).toBe(true);
574
609
  });
575
610
 
576
- // The local form is reachable and posts the password under the wire
577
- // field the server reads.
578
611
  fireEvent.click(screen.getByRole("button", { name: "Add SMTP" }));
579
612
  await waitFor(() => {
580
613
  expect(screen.getByText("Add SMTP Sender")).toBeDefined();
@@ -613,7 +646,6 @@ describe("Mail Forms", () => {
613
646
  expect(screen.getByText("Manual")).toBeDefined();
614
647
  });
615
648
 
616
- // Add address
617
649
  const addBtn = screen.getByRole("button", { name: "Add address" });
618
650
  fireEvent.click(addBtn);
619
651
 
@@ -629,7 +661,6 @@ describe("Mail Forms", () => {
629
661
  expect(screen.queryByText("Add to suppression list")).toBeNull();
630
662
  });
631
663
 
632
- // Remove suppression item with confirmation
633
664
  const delButtons = screen.getAllByTitle("Remove");
634
665
  fireEvent.click(delButtons[0]);
635
666
 
package/pages/index.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { ScreenWrap, PageHeader, GlassCard, Button, useTranslation } from "@octarq/plugin-sdk";
1
+ import { PageShell, Button, useTranslation } from "@octarq/plugin-sdk";
2
2
  import { useEffect, useState, useMemo } from "react";
3
3
  import { useSearchParams } from "react-router-dom";
4
4
  import { mailApi, Domain, effectiveMailHosts, Email, Mailbox } from "../api";
@@ -121,26 +121,25 @@ export default function MailPage() {
121
121
  const totalUnread = useMemo(() => boxes.reduce((acc, b) => acc + (b.unread || 0), 0), [boxes]);
122
122
 
123
123
  return (
124
- <ScreenWrap>
125
- <PageHeader
126
- title={t("mail.pageTitle")}
127
- description={t("mail.pageDesc")}
128
- action={
129
- <div className="flex items-center gap-2">
130
- <Button variant="ghost" size="sm" onClick={markAllRead}>
131
- {t("mail.markRead")}
132
- </Button>
133
- <Button variant="outline" size="sm" onClick={() => setCompose(true)}>
134
- <Send className="h-3.5 w-3.5" />
135
- {t("mail.compose")}
136
- </Button>
137
- <Button variant="primary" size="sm" onClick={() => setNewBox(true)}>
138
- <Plus className="h-3.5 w-3.5" />
139
- {t("mail.newMailbox")}
140
- </Button>
141
- </div>
142
- }
143
- />
124
+ <PageShell
125
+ title={t("mail.pageTitle")}
126
+ description={t("mail.pageDesc")}
127
+ action={
128
+ <div className="flex items-center gap-2">
129
+ <Button variant="ghost" size="sm" onClick={markAllRead}>
130
+ {t("mail.markRead")}
131
+ </Button>
132
+ <Button variant="outline" size="sm" onClick={() => setCompose(true)}>
133
+ <Send className="h-3.5 w-3.5" />
134
+ {t("mail.compose")}
135
+ </Button>
136
+ <Button variant="primary" size="sm" onClick={() => setNewBox(true)}>
137
+ <Plus className="h-3.5 w-3.5" />
138
+ {t("mail.newMailbox")}
139
+ </Button>
140
+ </div>
141
+ }
142
+ >
144
143
 
145
144
  <MailTabs tab={tab} onTabChange={setTab} />
146
145
 
@@ -184,8 +183,8 @@ export default function MailPage() {
184
183
  onChanged={() => { loadEmails(true); loadBoxes(); }}
185
184
  />
186
185
  ) : (
187
- <div className="flex min-h-[420px] flex-col items-center justify-center gap-3 rounded-2xl border border-dashed border-border bg-well px-6 py-16 text-center">
188
- <div className="flex h-12 w-12 items-center justify-center rounded-2xl bg-card text-accent-fg shadow-[var(--shadow-card)] ring-1 ring-border">
186
+ <div className="flex min-h-[420px] flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-well px-6 py-16 text-center">
187
+ <div className="flex h-12 w-12 items-center justify-center rounded-lg border border-border bg-card text-accent-fg">
189
188
  <Inbox className="h-5 w-5" />
190
189
  </div>
191
190
  <p className="font-display text-[13px] text-foreground">{t("mail.selectEmail")}</p>
@@ -209,6 +208,6 @@ export default function MailPage() {
209
208
  onDraftSaved={() => { loadEmails(true); }}
210
209
  />
211
210
  )}
212
- </ScreenWrap>
211
+ </PageShell>
213
212
  );
214
213
  }
@@ -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,9 +14,7 @@ export default function MailSetupStepWidget() {
14
14
  let cancelled = false;
15
15
  (async () => {
16
16
  try {
17
- // The Integrations Hub owns mail senders when it is mounted. Count the
18
- // same registry the mail pages offer, not just the local table.
19
- const res = await fetch("/api/integrations?provider_type=communication", {
17
+ const res = await fetch("/api/vault/items?provider_type=communication", {
20
18
  credentials: "same-origin",
21
19
  });
22
20
  if (res.status === 404) {
@@ -26,12 +24,12 @@ export default function MailSetupStepWidget() {
26
24
  }
27
25
  if (!res.ok) return;
28
26
  const data = await res.json();
29
- const list = (Array.isArray(data) ? data : []).filter(
27
+ const raw = Array.isArray(data) ? data : (data?.body ?? []);
28
+ const list = (Array.isArray(raw) ? raw : []).filter(
30
29
  (item: any) => item.provider === "smtp" || item.provider === "resend"
31
30
  );
32
31
  if (!cancelled) setSmtpCount(list.length);
33
32
  } catch {
34
- // Leave the step in the unknown state instead of reporting zero.
35
33
  }
36
34
  })();
37
35
  return () => {