@dxv-systems/mail-graph 0.3.2 → 0.3.3
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/docs/app-integration.md +161 -4
- package/package.json +1 -1
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.3.
|
|
20
|
+
npm install --save-exact @dxv-systems/mail-graph@0.3.3 @dxv-systems/helpdesk@0.13.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.
|
|
@@ -1434,6 +1434,12 @@ export async function getHelpdeskSettingsForAdmin(): Promise<HelpdeskSettingsVie
|
|
|
1434
1434
|
return readHelpdeskSettings();
|
|
1435
1435
|
}
|
|
1436
1436
|
|
|
1437
|
+
/** The mailboxes whose history import the settings page shows: the connected ones the routes serve. */
|
|
1438
|
+
export async function getHistoryMailboxesForAdmin(): Promise<string[]> {
|
|
1439
|
+
await requirePermission("m365:manage");
|
|
1440
|
+
return (await getHelpdeskDeps())?.config.connectedMailboxes ?? [];
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1437
1443
|
/** Whether the inbox can work: Microsoft 365 on and at least one mailbox whose access works (`activeScope`). */
|
|
1438
1444
|
export async function isHelpdeskConnected(): Promise<boolean> {
|
|
1439
1445
|
await requirePermission("helpdesk:use");
|
|
@@ -1724,25 +1730,176 @@ export default async function MicrosoftSetupPage() {
|
|
|
1724
1730
|
}
|
|
1725
1731
|
```
|
|
1726
1732
|
|
|
1727
|
-
|
|
1733
|
+
`src/components/helpdesk/mail-history-settings.tsx` (the history import per mailbox; the package works out the stage and how far it got, the cron does the work, and nothing starts until an admin presses Starten):
|
|
1734
|
+
|
|
1735
|
+
```tsx
|
|
1736
|
+
"use client";
|
|
1737
|
+
|
|
1738
|
+
import { useCallback, useEffect, useState } from "react";
|
|
1739
|
+
import { toast } from "sonner";
|
|
1740
|
+
import { createHelpdeskClient, HelpdeskClientError } from "@dxv-systems/helpdesk/client";
|
|
1741
|
+
import type { InboxHistory } from "@dxv-systems/helpdesk/server";
|
|
1742
|
+
import { Button } from "@/components/ui/button";
|
|
1743
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
|
1744
|
+
|
|
1745
|
+
const helpdesk = createHelpdeskClient();
|
|
1746
|
+
|
|
1747
|
+
const STAGE_LABELS: Record<InboxHistory["stage"], string> = {
|
|
1748
|
+
not_started: "Niet gestart",
|
|
1749
|
+
running: "Bezig met ophalen",
|
|
1750
|
+
waiting: "Wacht op Microsoft",
|
|
1751
|
+
paused: "Gepauzeerd",
|
|
1752
|
+
done: "Klaar",
|
|
1753
|
+
};
|
|
1754
|
+
|
|
1755
|
+
const FOLDERS = [
|
|
1756
|
+
{ key: "inbox", label: "Postvak IN" },
|
|
1757
|
+
{ key: "sentitems", label: "Verzonden" },
|
|
1758
|
+
] as const;
|
|
1759
|
+
|
|
1760
|
+
const date = (iso: string) => new Date(iso).toLocaleDateString("nl-NL", { day: "numeric", month: "long", year: "numeric" });
|
|
1761
|
+
const time = (iso: string) => new Date(iso).toLocaleTimeString("nl-NL", { hour: "2-digit", minute: "2-digit" });
|
|
1762
|
+
|
|
1763
|
+
function errorText(error: unknown): string {
|
|
1764
|
+
if (error instanceof HelpdeskClientError && error.status === 403) {
|
|
1765
|
+
return "Je hebt zelf geen toegang tot deze mailbox. Geef jezelf toegang om de historie te zien en te starten.";
|
|
1766
|
+
}
|
|
1767
|
+
return error instanceof HelpdeskClientError ? error.message : "De stand kon niet worden geladen. Probeer het opnieuw.";
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
function MailboxHistory({ mailbox }: { mailbox: string }) {
|
|
1771
|
+
const [history, setHistory] = useState<InboxHistory | null>(null);
|
|
1772
|
+
const [error, setError] = useState<string | null>(null);
|
|
1773
|
+
const [busy, setBusy] = useState(false);
|
|
1774
|
+
|
|
1775
|
+
const load = useCallback(async () => {
|
|
1776
|
+
try {
|
|
1777
|
+
setHistory(await helpdesk.history(mailbox));
|
|
1778
|
+
setError(null);
|
|
1779
|
+
} catch (e) {
|
|
1780
|
+
setError(errorText(e));
|
|
1781
|
+
}
|
|
1782
|
+
}, [mailbox]);
|
|
1783
|
+
|
|
1784
|
+
useEffect(() => {
|
|
1785
|
+
void load();
|
|
1786
|
+
// The cron imports every few minutes: refresh the counts while the page is open.
|
|
1787
|
+
const timer = window.setInterval(() => void load(), 60_000);
|
|
1788
|
+
return () => window.clearInterval(timer);
|
|
1789
|
+
}, [load]);
|
|
1790
|
+
|
|
1791
|
+
async function run(action: "start" | "pause") {
|
|
1792
|
+
setBusy(true);
|
|
1793
|
+
try {
|
|
1794
|
+
setHistory(action === "start" ? await helpdesk.startHistory(mailbox) : await helpdesk.pauseHistory(mailbox));
|
|
1795
|
+
toast.success(action === "start" ? "Het ophalen loopt. De eerste mail verschijnt binnen enkele minuten." : "Gepauzeerd.");
|
|
1796
|
+
} catch (e) {
|
|
1797
|
+
toast.error(errorText(e));
|
|
1798
|
+
} finally {
|
|
1799
|
+
setBusy(false);
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
const state = history?.state ?? null;
|
|
1804
|
+
return (
|
|
1805
|
+
<Card>
|
|
1806
|
+
<CardHeader>
|
|
1807
|
+
<CardTitle className="break-all">{mailbox}</CardTitle>
|
|
1808
|
+
<CardDescription>
|
|
1809
|
+
Haalt de mail van de laatste 6 maanden vóór de koppeling op uit Postvak IN en Verzonden. Alleen lezen: in Outlook
|
|
1810
|
+
verandert niets. Opgehaalde gesprekken komen binnen als afgesloten tickets.
|
|
1811
|
+
</CardDescription>
|
|
1812
|
+
</CardHeader>
|
|
1813
|
+
<CardContent className="space-y-4 text-sm">
|
|
1814
|
+
{error && <p className="text-muted-foreground">{error}</p>}
|
|
1815
|
+
{!error && !history && <p className="text-muted-foreground">Laden…</p>}
|
|
1816
|
+
{!error && history && !history.supported && (
|
|
1817
|
+
<p className="text-muted-foreground">Mailhistorie ophalen is voor deze mailbox niet beschikbaar.</p>
|
|
1818
|
+
)}
|
|
1819
|
+
{!error && history?.supported && (
|
|
1820
|
+
<>
|
|
1821
|
+
<div className="space-y-1">
|
|
1822
|
+
<p className="font-medium">{STAGE_LABELS[history.stage]}</p>
|
|
1823
|
+
{history.retryAfter && (
|
|
1824
|
+
<p className="text-muted-foreground">
|
|
1825
|
+
Microsoft vraagt even te wachten. Het ophalen gaat vanzelf verder na {time(history.retryAfter)}.
|
|
1826
|
+
</p>
|
|
1827
|
+
)}
|
|
1828
|
+
{history.completeUntil && <p className="text-muted-foreground">Compleet tot {date(history.completeUntil)}</p>}
|
|
1829
|
+
</div>
|
|
1830
|
+
{state && (
|
|
1831
|
+
<table className="w-full max-w-sm">
|
|
1832
|
+
<thead className="text-left text-muted-foreground">
|
|
1833
|
+
<tr>
|
|
1834
|
+
<th className="py-1 pr-3 font-normal">Map</th>
|
|
1835
|
+
<th className="py-1 text-right font-normal">Opgehaald</th>
|
|
1836
|
+
</tr>
|
|
1837
|
+
</thead>
|
|
1838
|
+
<tbody>
|
|
1839
|
+
{FOLDERS.map(({ key, label }) => (
|
|
1840
|
+
<tr key={key} className="border-t">
|
|
1841
|
+
<td className="py-1 pr-3">
|
|
1842
|
+
{label}
|
|
1843
|
+
{state.folders[key].doneAt ? " ✓" : ""}
|
|
1844
|
+
</td>
|
|
1845
|
+
<td className="py-1 text-right tabular-nums">{state.folders[key].imported.toLocaleString("nl-NL")}</td>
|
|
1846
|
+
</tr>
|
|
1847
|
+
))}
|
|
1848
|
+
</tbody>
|
|
1849
|
+
</table>
|
|
1850
|
+
)}
|
|
1851
|
+
{(history.stage === "not_started" || history.stage === "paused") && (
|
|
1852
|
+
<Button size="sm" disabled={busy} onClick={() => void run("start")}>
|
|
1853
|
+
{history.stage === "paused" ? "Hervatten" : "Starten"}
|
|
1854
|
+
</Button>
|
|
1855
|
+
)}
|
|
1856
|
+
{(history.stage === "running" || history.stage === "waiting") && (
|
|
1857
|
+
<Button size="sm" variant="outline" disabled={busy} onClick={() => void run("pause")}>
|
|
1858
|
+
Pauzeren
|
|
1859
|
+
</Button>
|
|
1860
|
+
)}
|
|
1861
|
+
</>
|
|
1862
|
+
)}
|
|
1863
|
+
</CardContent>
|
|
1864
|
+
</Card>
|
|
1865
|
+
);
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
/** One card per connected mailbox; nothing when there is none. */
|
|
1869
|
+
export function MailHistorySettings({ mailboxes }: { mailboxes: string[] }) {
|
|
1870
|
+
if (mailboxes.length === 0) return null;
|
|
1871
|
+
return (
|
|
1872
|
+
<section className="space-y-4">
|
|
1873
|
+
<h2 className="text-lg font-semibold">Mailhistorie</h2>
|
|
1874
|
+
{mailboxes.map((mailbox) => (
|
|
1875
|
+
<MailboxHistory key={mailbox} mailbox={mailbox} />
|
|
1876
|
+
))}
|
|
1877
|
+
</section>
|
|
1878
|
+
);
|
|
1879
|
+
}
|
|
1880
|
+
```
|
|
1881
|
+
|
|
1882
|
+
Helpdesk settings `src/app/(app)/dashboard/helpdesk/instellingen/page.tsx` (pause and write mode, and the history import; admins only, linked from the inbox and the setup page):
|
|
1728
1883
|
|
|
1729
1884
|
```tsx
|
|
1730
1885
|
import type { Metadata } from "next";
|
|
1731
1886
|
|
|
1732
1887
|
import { requirePermission } from "@/lib/auth/dal";
|
|
1733
|
-
import { getHelpdeskSettingsForAdmin } from "@/lib/helpdesk/queries";
|
|
1888
|
+
import { getHelpdeskSettingsForAdmin, getHistoryMailboxesForAdmin } from "@/lib/helpdesk/queries";
|
|
1734
1889
|
import { PageHeader } from "@/components/app/page-header";
|
|
1735
1890
|
import { HelpdeskSettingsForm } from "@/components/helpdesk/helpdesk-settings-form";
|
|
1891
|
+
import { MailHistorySettings } from "@/components/helpdesk/mail-history-settings";
|
|
1736
1892
|
|
|
1737
1893
|
export const metadata: Metadata = { title: "Helpdesk-instellingen" };
|
|
1738
1894
|
|
|
1739
1895
|
export default async function HelpdeskSettingsPage() {
|
|
1740
1896
|
await requirePermission("m365:manage");
|
|
1741
|
-
const settings = await getHelpdeskSettingsForAdmin();
|
|
1897
|
+
const [settings, historyMailboxes] = await Promise.all([getHelpdeskSettingsForAdmin(), getHistoryMailboxesForAdmin()]);
|
|
1742
1898
|
return (
|
|
1743
1899
|
<div className="space-y-6">
|
|
1744
1900
|
<PageHeader title="Helpdesk-instellingen" />
|
|
1745
1901
|
<HelpdeskSettingsForm paused={settings.paused} />
|
|
1902
|
+
<MailHistorySettings mailboxes={historyMailboxes} />
|
|
1746
1903
|
</div>
|
|
1747
1904
|
);
|
|
1748
1905
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxv-systems/mail-graph",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
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",
|