@dxv-systems/mail-graph 0.0.0-stage → 0.1.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.
Files changed (52) hide show
  1. package/README.md +200 -2
  2. package/dist/auth.d.ts +41 -0
  3. package/dist/auth.js +184 -0
  4. package/dist/client.d.ts +18 -0
  5. package/dist/client.js +34 -0
  6. package/dist/errors.d.ts +25 -0
  7. package/dist/errors.js +35 -0
  8. package/dist/http.d.ts +44 -0
  9. package/dist/http.js +182 -0
  10. package/dist/index.d.ts +9 -0
  11. package/dist/index.js +14 -0
  12. package/dist/limiter.d.ts +7 -0
  13. package/dist/limiter.js +29 -0
  14. package/dist/links.d.ts +2 -0
  15. package/dist/links.js +25 -0
  16. package/dist/mailbox.d.ts +41 -0
  17. package/dist/mailbox.js +429 -0
  18. package/dist/setup/access.d.ts +20 -0
  19. package/dist/setup/access.js +71 -0
  20. package/dist/setup/address.d.ts +32 -0
  21. package/dist/setup/address.js +69 -0
  22. package/dist/setup/consent.d.ts +40 -0
  23. package/dist/setup/consent.js +78 -0
  24. package/dist/setup/constants.d.ts +2 -0
  25. package/dist/setup/constants.js +5 -0
  26. package/dist/setup/exchange-graph.d.ts +23 -0
  27. package/dist/setup/exchange-graph.js +119 -0
  28. package/dist/setup/exchange-script.d.ts +1 -0
  29. package/dist/setup/exchange-script.js +190 -0
  30. package/dist/setup/handlers.d.ts +30 -0
  31. package/dist/setup/handlers.js +571 -0
  32. package/dist/setup/index.d.ts +18 -0
  33. package/dist/setup/index.js +38 -0
  34. package/dist/setup/it-link.d.ts +17 -0
  35. package/dist/setup/it-link.js +17 -0
  36. package/dist/setup/messages.d.ts +22 -0
  37. package/dist/setup/messages.js +36 -0
  38. package/dist/setup/react.d.ts +8 -0
  39. package/dist/setup/react.js +451 -0
  40. package/dist/setup/script.d.ts +27 -0
  41. package/dist/setup/script.js +74 -0
  42. package/dist/setup/signing.d.ts +18 -0
  43. package/dist/setup/signing.js +56 -0
  44. package/dist/setup/tenant.d.ts +38 -0
  45. package/dist/setup/tenant.js +45 -0
  46. package/dist/setup/types.d.ts +76 -0
  47. package/dist/setup/types.js +2 -0
  48. package/dist/types.d.ts +98 -0
  49. package/dist/types.js +2 -0
  50. package/dist/util.d.ts +4 -0
  51. package/dist/util.js +17 -0
  52. package/package.json +68 -4
@@ -0,0 +1,22 @@
1
+ import type { ConsentErrorCode, ExchangeSetupErrorCode } from "./types";
2
+ export declare const SETUP_ERROR_MESSAGES: Readonly<{
3
+ readonly not_production: "Microsoft 365 koppelen kan alleen in de productieomgeving van de app.";
4
+ readonly not_configured: "Microsoft 365 is nog niet beschikbaar voor deze app. Neem contact op met DXV.";
5
+ readonly setup_pending: "DXV zet Microsoft 365 nog klaar voor deze app. Probeer het later opnieuw.";
6
+ readonly unauthorized: "Je hebt geen toegang tot deze koppeling. Log in als app-beheerder.";
7
+ readonly link_invalid: "Deze link werkt niet (meer). Vraag de app-beheerder om een nieuwe link.";
8
+ readonly forbidden_origin: "Dit verzoek komt niet van de app zelf en is geweigerd.";
9
+ readonly invalid_input: "Controleer de ingevulde gegevens.";
10
+ readonly not_m365: "Dit domein gebruikt geen Microsoft 365. Kies mailboxen die in Microsoft 365 staan.";
11
+ readonly mixed_tenants: "De mailboxen staan in verschillende Microsoft 365-omgevingen. Kies mailboxen uit één omgeving.";
12
+ readonly lookup_failed: "We konden Microsoft nu niet bereiken. Probeer het over een paar minuten opnieuw.";
13
+ readonly tenant_change_needs_reset: "Deze mailboxen staan in een andere Microsoft 365-omgeving dan de huidige koppeling. Ontkoppel eerst, dan kun je opnieuw beginnen.";
14
+ readonly wrong_step: "Deze stap is nu niet beschikbaar. Vernieuw de pagina.";
15
+ readonly invalid_object_id: "Dit is geen geldig Object ID. Het ziet eruit als 00000000-0000-0000-0000-000000000000.";
16
+ readonly confirm_required: "Bevestig eerst dat je wilt ontkoppelen.";
17
+ readonly not_found: "Onbekende route.";
18
+ readonly method_not_allowed: "Deze methode is hier niet toegestaan.";
19
+ }>;
20
+ export type SetupErrorCode = keyof typeof SETUP_ERROR_MESSAGES;
21
+ export declare const CONSENT_ERROR_MESSAGES: Readonly<Record<ConsentErrorCode, string>>;
22
+ export declare const EXCHANGE_SETUP_ERROR_MESSAGES: Readonly<Record<ExchangeSetupErrorCode, string>>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EXCHANGE_SETUP_ERROR_MESSAGES = exports.CONSENT_ERROR_MESSAGES = exports.SETUP_ERROR_MESSAGES = void 0;
4
+ exports.SETUP_ERROR_MESSAGES = Object.freeze({
5
+ not_production: "Microsoft 365 koppelen kan alleen in de productieomgeving van de app.",
6
+ not_configured: "Microsoft 365 is nog niet beschikbaar voor deze app. Neem contact op met DXV.",
7
+ setup_pending: "DXV zet Microsoft 365 nog klaar voor deze app. Probeer het later opnieuw.",
8
+ unauthorized: "Je hebt geen toegang tot deze koppeling. Log in als app-beheerder.",
9
+ link_invalid: "Deze link werkt niet (meer). Vraag de app-beheerder om een nieuwe link.",
10
+ forbidden_origin: "Dit verzoek komt niet van de app zelf en is geweigerd.",
11
+ invalid_input: "Controleer de ingevulde gegevens.",
12
+ not_m365: "Dit domein gebruikt geen Microsoft 365. Kies mailboxen die in Microsoft 365 staan.",
13
+ mixed_tenants: "De mailboxen staan in verschillende Microsoft 365-omgevingen. Kies mailboxen uit één omgeving.",
14
+ lookup_failed: "We konden Microsoft nu niet bereiken. Probeer het over een paar minuten opnieuw.",
15
+ tenant_change_needs_reset: "Deze mailboxen staan in een andere Microsoft 365-omgeving dan de huidige koppeling. Ontkoppel eerst, dan kun je opnieuw beginnen.",
16
+ wrong_step: "Deze stap is nu niet beschikbaar. Vernieuw de pagina.",
17
+ invalid_object_id: "Dit is geen geldig Object ID. Het ziet eruit als 00000000-0000-0000-0000-000000000000.",
18
+ confirm_required: "Bevestig eerst dat je wilt ontkoppelen.",
19
+ not_found: "Onbekende route.",
20
+ method_not_allowed: "Deze methode is hier niet toegestaan.",
21
+ });
22
+ exports.CONSENT_ERROR_MESSAGES = Object.freeze({
23
+ state_invalid: "Deze terugkoppeling van Microsoft is ongeldig. Ga terug naar de koppelpagina en klik opnieuw op Koppelen met Microsoft.",
24
+ state_expired: "Het koppelen duurde te lang en is verlopen. Klik opnieuw op Koppelen met Microsoft.",
25
+ state_stale: "Deze toestemming hoort bij een eerdere poging. Klik op de koppelpagina opnieuw op Koppelen met Microsoft.",
26
+ consent_denied: "De toestemming is geweigerd bij Microsoft. Zonder toestemming kan de koppeling niet verder.",
27
+ consent_failed: "Microsoft heeft de toestemming niet bevestigd. Log in met een Global Administrator of Application Administrator en probeer het opnieuw.",
28
+ wrong_tenant: "De toestemming kwam uit een andere Microsoft-omgeving, dus we gebruiken die niet. Log in met een account dat toegang heeft tot deze omgeving en klik opnieuw op Koppelen met Microsoft.",
29
+ });
30
+ exports.EXCHANGE_SETUP_ERROR_MESSAGES = Object.freeze({
31
+ exchange_forbidden: "Je account mag de Exchange-rechten niet regelen. Dat kan een Global Administrator of Exchange Administrator.",
32
+ exchange_org_customization: "Exchange in jullie omgeving heeft eerst een eenmalige instelling nodig. Die kan alleen het PowerShell-script zetten.",
33
+ exchange_failed: "Microsoft weigerde de Exchange-rechten op dit moment. Probeer het opnieuw, of gebruik PowerShell.",
34
+ sign_in_failed: "Het aanmelden bij Microsoft is niet afgerond.",
35
+ no_object_id: "Microsoft had de app nog niet klaarstaan. Probeer het over een minuut opnieuw.",
36
+ });
@@ -0,0 +1,8 @@
1
+ export type { SetupStatus } from "./types";
2
+ export interface M365SetupPageProps {
3
+ linkToken?: string;
4
+ helpdeskHref?: string;
5
+ settingsHref?: string;
6
+ fetch?: typeof fetch;
7
+ }
8
+ export declare function M365SetupPage({ linkToken, helpdeskHref, settingsHref, fetch: fetchImpl }: M365SetupPageProps): import("react").JSX.Element;
@@ -0,0 +1,451 @@
1
+ "use strict";
2
+ "use client";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.M365SetupPage = M365SetupPage;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = require("react");
7
+ const address_1 = require("./address");
8
+ const constants_1 = require("./constants");
9
+ const messages_1 = require("./messages");
10
+ const script_1 = require("./script");
11
+ const POLL_INTERVAL_MS = 30000;
12
+ const PREPARING_POLL_INTERVAL_MS = 120000;
13
+ const cls = Object.freeze({
14
+ root: "mx-auto flex w-full max-w-2xl flex-col gap-7 text-foreground",
15
+ breadcrumb: "text-sm text-muted-foreground",
16
+ header: "flex flex-col gap-2",
17
+ title: "text-3xl font-bold leading-tight tracking-tight",
18
+ lead: "text-base leading-relaxed text-muted-foreground",
19
+ card: "flex flex-col gap-5 rounded-xl border border-border bg-card p-6 text-card-foreground sm:p-7",
20
+ field: "flex flex-col gap-2.5",
21
+ label: "text-sm font-semibold",
22
+ heading: "text-base font-semibold",
23
+ text: "text-sm leading-relaxed",
24
+ muted: "text-sm leading-relaxed text-muted-foreground",
25
+ center: "text-center text-sm text-muted-foreground",
26
+ input: "h-11 w-full min-w-0 rounded-lg border border-input bg-background px-3 text-base focus-visible:outline focus-visible:outline-2 focus-visible:outline-ring",
27
+ chipBox: "flex min-h-11 flex-wrap items-center gap-2 rounded-lg border border-input bg-background px-2.5 py-1.5 focus-within:outline focus-within:outline-2 focus-within:outline-ring",
28
+ chipInput: "min-w-[12rem] flex-1 bg-transparent px-1 py-1.5 text-base outline-none",
29
+ chip: "inline-flex items-center gap-2 rounded-full bg-muted py-1 pl-3 pr-1 text-sm",
30
+ chipStatic: "inline-flex self-start rounded-full bg-muted px-3 py-1 text-sm",
31
+ chipRemove: "inline-flex h-6 w-6 items-center justify-center rounded-full text-muted-foreground hover:bg-accent hover:text-foreground",
32
+ actions: "flex flex-wrap items-center gap-3",
33
+ primaryButton: "inline-flex min-h-12 w-full items-center justify-center gap-2.5 rounded-lg bg-primary px-5 text-base font-semibold text-primary-foreground hover:bg-primary/90 disabled:opacity-50",
34
+ secondaryButton: "inline-flex min-h-11 items-center justify-center rounded-lg border border-border bg-background px-4 text-sm font-medium hover:bg-accent disabled:opacity-50",
35
+ wideSecondaryButton: "inline-flex min-h-12 w-full items-center justify-center rounded-lg border border-border bg-background px-5 text-base font-medium hover:bg-accent disabled:opacity-50",
36
+ quietButton: "inline-flex min-h-11 items-center px-1 text-sm font-medium text-muted-foreground hover:text-foreground",
37
+ linkButton: "inline-flex min-h-11 items-center text-sm font-semibold underline-offset-4 hover:underline",
38
+ dangerLink: "inline-flex min-h-11 items-center self-start text-sm font-medium text-destructive hover:underline",
39
+ dangerButton: "inline-flex min-h-11 items-center justify-center rounded-lg border border-destructive bg-background px-4 text-sm font-semibold text-destructive hover:bg-destructive/10 disabled:opacity-50",
40
+ details: "border-t border-border pt-5",
41
+ detailsCard: "rounded-xl border border-border bg-card p-5 text-card-foreground sm:px-7",
42
+ summary: "cursor-pointer text-sm font-semibold",
43
+ list: "flex list-disc flex-col gap-2 pl-5 text-sm leading-relaxed",
44
+ ok: "inline-flex items-center gap-2 text-sm text-emerald-700 dark:text-emerald-400",
45
+ badgeOk: "rounded-full bg-emerald-50 px-2.5 py-0.5 text-sm font-semibold text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200",
46
+ warning: "flex flex-col gap-3 rounded-xl border border-amber-200 bg-amber-50 p-5 text-amber-950 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-100",
47
+ info: "flex items-center gap-3 rounded-xl bg-muted px-5 py-4 text-sm",
48
+ error: "rounded-lg bg-destructive/10 px-4 py-3 text-sm text-destructive",
49
+ checklist: "flex flex-col overflow-hidden rounded-xl border border-border bg-card text-card-foreground",
50
+ checkItem: "flex items-center gap-4 border-b border-border px-6 py-4 last:border-b-0",
51
+ checkDone: "inline-flex h-7 w-7 flex-none items-center justify-center rounded-full bg-emerald-50 text-emerald-700 dark:bg-emerald-950 dark:text-emerald-300",
52
+ checkBusy: "inline-block h-7 w-7 flex-none animate-spin rounded-full border-2 border-amber-500 border-r-transparent motion-reduce:animate-none",
53
+ checkTitle: "text-base font-semibold",
54
+ codeBlock: "overflow-hidden rounded-lg border border-border bg-muted",
55
+ codeToolbar: "flex flex-wrap items-center justify-between gap-2 border-b border-border px-3 py-2 text-sm",
56
+ code: "m-0 overflow-x-auto p-4 font-mono text-sm leading-relaxed",
57
+ inlineCode: "font-mono text-sm",
58
+ choice: "flex min-h-11 items-center gap-3 rounded-lg border border-border px-4 text-sm",
59
+ });
60
+ class ApiError extends Error {
61
+ constructor(code, message, body) {
62
+ super(message);
63
+ this.code = code;
64
+ this.body = body;
65
+ }
66
+ }
67
+ const dateTime = new Intl.DateTimeFormat("nl-NL", { dateStyle: "long", timeStyle: "short" });
68
+ const formatDate = (iso) => (iso ? dateTime.format(new Date(iso)) : "");
69
+ const time = new Intl.DateTimeFormat("nl-NL", { timeStyle: "short" });
70
+ const formatTime = (iso) => (iso ? time.format(new Date(iso)) : "");
71
+ function mailboxErrorText(error) {
72
+ switch (error.code) {
73
+ case "invalid_address":
74
+ return `"${error.address}" is geen geldig e-mailadres.`;
75
+ case "duplicate_mailbox":
76
+ return `${error.address} staat er twee keer in.`;
77
+ case "no_mailboxes":
78
+ return "Vul minstens één mailbox in.";
79
+ case "too_many_mailboxes":
80
+ return `Je kunt maximaal ${error.max} mailboxen koppelen.`;
81
+ case "invalid_check_mailbox":
82
+ return "Vul een geldig adres in voor de controle.";
83
+ case "check_mailbox_in_list":
84
+ return "Kies voor de controle een mailbox die je niet koppelt.";
85
+ }
86
+ }
87
+ function apiErrorText(error) {
88
+ if (!(error instanceof ApiError))
89
+ return "Er ging iets mis. Probeer het opnieuw.";
90
+ const errors = error.body.errors;
91
+ if (Array.isArray(errors) && errors.length > 0)
92
+ return errors.map(mailboxErrorText).join(" ");
93
+ const domains = error.body.domains;
94
+ if (error.code === "not_m365" && Array.isArray(domains))
95
+ return `${error.message} (${domains.join(", ")})`;
96
+ const tenants = error.body.tenants;
97
+ if (error.code === "mixed_tenants" && Array.isArray(tenants)) {
98
+ return `${error.message} (${tenants.map((t) => t.domain).join(", ")})`;
99
+ }
100
+ return error.message;
101
+ }
102
+ async function copyText(text) {
103
+ try {
104
+ await navigator.clipboard.writeText(text);
105
+ return true;
106
+ }
107
+ catch {
108
+ return false;
109
+ }
110
+ }
111
+ function useApi(linkToken, fetchImpl) {
112
+ return (0, react_1.useCallback)(async (path, init = {}) => {
113
+ const headers = { Accept: "application/json" };
114
+ if (init.body !== undefined)
115
+ headers["Content-Type"] = "application/json";
116
+ if (linkToken)
117
+ headers[constants_1.IT_LINK_HEADER] = linkToken;
118
+ const doFetch = fetchImpl ?? fetch;
119
+ const response = await doFetch(`${constants_1.SETUP_BASE_PATH}/${path}`, {
120
+ method: init.method ?? "GET",
121
+ headers,
122
+ credentials: "same-origin",
123
+ body: init.body === undefined ? undefined : JSON.stringify(init.body),
124
+ });
125
+ const body = (await response.json().catch(() => ({})));
126
+ if (!response.ok) {
127
+ const code = typeof body.error === "string" ? body.error : "error";
128
+ const message = typeof body.message === "string" ? body.message : "Er ging iets mis. Probeer het opnieuw.";
129
+ throw new ApiError(code, message, body);
130
+ }
131
+ return body;
132
+ }, [linkToken, fetchImpl]);
133
+ }
134
+ async function signIn(api, method) {
135
+ const { url } = await api("consent/start", { method: "POST", body: { method } });
136
+ window.location.assign(url);
137
+ }
138
+ function M365SetupPage({ linkToken, helpdeskHref, settingsHref, fetch: fetchImpl }) {
139
+ const api = useApi(linkToken, fetchImpl);
140
+ const [status, setStatus] = (0, react_1.useState)(null);
141
+ const [loadError, setLoadError] = (0, react_1.useState)(null);
142
+ const [view, setView] = (0, react_1.useState)("auto");
143
+ const [busy, setBusy] = (0, react_1.useState)(false);
144
+ const [actionError, setActionError] = (0, react_1.useState)(null);
145
+ const load = (0, react_1.useCallback)(async () => {
146
+ try {
147
+ setStatus(await api("status"));
148
+ setLoadError(null);
149
+ }
150
+ catch (error) {
151
+ setLoadError(apiErrorText(error));
152
+ }
153
+ }, [api]);
154
+ (0, react_1.useEffect)(() => {
155
+ void load();
156
+ }, [load]);
157
+ const waiting = status?.step === "awaiting_access";
158
+ const preparing = status !== null && !status.setupReady && (status.step === "not_started" || status.step === "awaiting_consent");
159
+ (0, react_1.useEffect)(() => {
160
+ if (!waiting && !preparing)
161
+ return;
162
+ const timer = setInterval(() => void load(), waiting ? POLL_INTERVAL_MS : PREPARING_POLL_INTERVAL_MS);
163
+ return () => clearInterval(timer);
164
+ }, [waiting, preparing, load]);
165
+ const run = (0, react_1.useCallback)(async (action, nextView = "auto") => {
166
+ setBusy(true);
167
+ setActionError(null);
168
+ try {
169
+ const next = await action();
170
+ if (next)
171
+ setStatus(next);
172
+ setView(nextView);
173
+ }
174
+ catch (error) {
175
+ setActionError(apiErrorText(error));
176
+ }
177
+ finally {
178
+ setBusy(false);
179
+ }
180
+ }, []);
181
+ if (!status) {
182
+ return ((0, jsx_runtime_1.jsxs)("div", { className: cls.root, "data-m365-setup": "", children: [(0, jsx_runtime_1.jsx)("p", { className: cls.breadcrumb, children: "Beheer / Microsoft 365" }), loadError ? ((0, jsx_runtime_1.jsx)("p", { role: "alert", className: cls.error, children: loadError })) : ((0, jsx_runtime_1.jsx)("p", { className: cls.muted, "aria-live": "polite", children: "Laden\u2026" }))] }));
183
+ }
184
+ const isIt = status.viewer === "it";
185
+ const shared = { status, busy, run, api, setView };
186
+ const start = status.step === "not_started" || status.step === "awaiting_consent";
187
+ let body;
188
+ if (preparing)
189
+ body = (0, jsx_runtime_1.jsx)(PreparingStep, { status: status });
190
+ else if (!isIt && view === "forward")
191
+ body = (0, jsx_runtime_1.jsx)(ForwardStep, { ...shared });
192
+ else if (!isIt && (view === "edit" || start))
193
+ body = (0, jsx_runtime_1.jsx)(StartStep, { ...shared });
194
+ else if (status.step === "connected")
195
+ body = (0, jsx_runtime_1.jsx)(ConnectedStep, { ...shared, helpdeskHref: helpdeskHref, settingsHref: settingsHref });
196
+ else if (isIt && start)
197
+ body = (0, jsx_runtime_1.jsx)(ItStartStep, { ...shared });
198
+ else if (status.step === "awaiting_script" && status.exchangeSetupError)
199
+ body = (0, jsx_runtime_1.jsx)(FallbackStep, { ...shared, linkToken: linkToken });
200
+ else if (status.step === "awaiting_script")
201
+ body = (0, jsx_runtime_1.jsx)(ScriptStep, { ...shared, linkToken: linkToken });
202
+ else if (status.step === "failed")
203
+ body = (0, jsx_runtime_1.jsx)(FailedStep, { ...shared });
204
+ else
205
+ body = (0, jsx_runtime_1.jsx)(WaitingStep, { ...shared });
206
+ return ((0, jsx_runtime_1.jsxs)("div", { className: cls.root, "data-m365-setup": "", "data-step": status.step, children: [(0, jsx_runtime_1.jsx)("p", { className: cls.breadcrumb, children: isIt
207
+ ? `Verzoek van ${status.companyName}${status.itLinkExpiresAt ? `, link geldig tot ${formatDate(status.itLinkExpiresAt)}` : ""}`
208
+ : "Beheer / Microsoft 365" }), status.consentError && start && ((0, jsx_runtime_1.jsx)("p", { role: "alert", className: cls.error, children: messages_1.CONSENT_ERROR_MESSAGES[status.consentError] })), actionError && ((0, jsx_runtime_1.jsx)("p", { role: "alert", className: cls.error, children: actionError })), body] }));
209
+ }
210
+ function Header({ title, lead, badge }) {
211
+ return ((0, jsx_runtime_1.jsxs)("div", { className: cls.header, children: [(0, jsx_runtime_1.jsxs)("div", { className: cls.actions, children: [(0, jsx_runtime_1.jsx)("h1", { className: cls.title, children: title }), badge && (0, jsx_runtime_1.jsx)("span", { className: cls.badgeOk, children: badge })] }), lead && (0, jsx_runtime_1.jsx)("p", { className: cls.lead, children: lead })] }));
212
+ }
213
+ function MicrosoftMark() {
214
+ return ((0, jsx_runtime_1.jsxs)("svg", { "aria-hidden": "true", width: "16", height: "16", viewBox: "0 0 16 16", fill: "currentColor", children: [(0, jsx_runtime_1.jsx)("rect", { x: "1", y: "1", width: "6.5", height: "6.5" }), (0, jsx_runtime_1.jsx)("rect", { x: "8.5", y: "1", width: "6.5", height: "6.5" }), (0, jsx_runtime_1.jsx)("rect", { x: "1", y: "8.5", width: "6.5", height: "6.5" }), (0, jsx_runtime_1.jsx)("rect", { x: "8.5", y: "8.5", width: "6.5", height: "6.5" })] }));
215
+ }
216
+ function Check() {
217
+ return ((0, jsx_runtime_1.jsx)("svg", { "aria-hidden": "true", width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: (0, jsx_runtime_1.jsx)("path", { d: "M2.5 7.5l3 3 6-7" }) }));
218
+ }
219
+ function MailboxChips({ addresses }) {
220
+ return ((0, jsx_runtime_1.jsx)("ul", { className: cls.actions, "aria-label": "Mailboxen", children: addresses.map((address) => ((0, jsx_runtime_1.jsx)("li", { className: cls.chipStatic, children: address }, address))) }));
221
+ }
222
+ function RightsDetails({ status, open }) {
223
+ const graph = status.graphSetupAvailable;
224
+ return ((0, jsx_runtime_1.jsxs)("details", { className: cls.details, open: open, children: [(0, jsx_runtime_1.jsx)("summary", { className: cls.summary, children: "Wat mag de app straks?" }), (0, jsx_runtime_1.jsxs)("ul", { className: `${cls.list} mt-3`, children: [(0, jsx_runtime_1.jsx)("li", { children: "Alleen bij de gekozen mailboxen: mail lezen, concepten klaarzetten en antwoorden versturen vanaf de mailbox zelf." }), (0, jsx_runtime_1.jsx)("li", { children: "Niet bij andere mailboxen. Dat controleren we na het koppelen." }), graph && ((0, jsx_runtime_1.jsxs)("li", { children: ["Microsoft vraagt ook om ", (0, jsx_runtime_1.jsx)("strong", { children: "Exchange-rolbeheer" }), ". Dat gebruikt de app alleen tijdens deze aanmelding, om zichzelf toegang te geven tot precies deze mailboxen. Er wordt niets bewaard."] })), (0, jsx_runtime_1.jsx)("li", { children: "De rollen in Exchange: Application Mail.ReadWrite, Mail.Send en MailboxSettings.Read. Ken in Entra g\u00E9\u00E9n API-machtigingen Mail.Read, Mail.ReadWrite of Mail.Send toe: die gelden voor alle mailboxen." }), (0, jsx_runtime_1.jsxs)("li", { children: ["Je kunt de koppeling altijd pauzeren of intrekken. De app in Microsoft heet ", status.entraAppName, "."] })] })] }));
225
+ }
226
+ function StartStep({ status, busy, run, api, setView }) {
227
+ const id = (0, react_1.useId)();
228
+ const editing = !(status.step === "not_started" || status.step === "awaiting_consent");
229
+ const graph = status.graphSetupAvailable;
230
+ const [addresses, setAddresses] = (0, react_1.useState)(status.mailboxes);
231
+ const [draft, setDraft] = (0, react_1.useState)("");
232
+ const [lookup, setLookup] = (0, react_1.useState)(null);
233
+ const lookupSeq = (0, react_1.useRef)(0);
234
+ const all = () => {
235
+ const extra = draft.trim();
236
+ return extra && !addresses.includes(extra.toLowerCase()) ? [...addresses, extra] : addresses;
237
+ };
238
+ const validate = async (list) => {
239
+ if (list.length === 0)
240
+ return setLookup(null);
241
+ const seq = ++lookupSeq.current;
242
+ try {
243
+ await api("mailboxes", { method: "POST", body: { mailboxes: list, validateOnly: true } });
244
+ if (seq === lookupSeq.current)
245
+ setLookup({ ok: true, text: `Microsoft 365 gevonden: ${(0, address_1.mailboxDomain)(list[0])}` });
246
+ }
247
+ catch (error) {
248
+ if (seq === lookupSeq.current)
249
+ setLookup({ ok: false, text: apiErrorText(error) });
250
+ }
251
+ };
252
+ const commitDraft = () => {
253
+ const value = draft.trim().replace(/[,;]$/, "");
254
+ if (!value)
255
+ return;
256
+ const address = (0, address_1.normalizeMailbox)(value) ?? value;
257
+ if (addresses.includes(address) || addresses.length >= address_1.MAX_MAILBOXES)
258
+ return setDraft("");
259
+ const next = [...addresses, address];
260
+ setAddresses(next);
261
+ setDraft("");
262
+ void validate(next);
263
+ };
264
+ const onKeyDown = (e) => {
265
+ if (e.key === "Enter" || e.key === "," || e.key === ";" || e.key === " ") {
266
+ if (draft.trim()) {
267
+ e.preventDefault();
268
+ commitDraft();
269
+ }
270
+ }
271
+ else if (e.key === "Backspace" && draft === "" && addresses.length > 0) {
272
+ setAddresses(addresses.slice(0, -1));
273
+ }
274
+ };
275
+ const remove = (address) => {
276
+ const next = addresses.filter((a) => a !== address);
277
+ setAddresses(next);
278
+ void validate(next);
279
+ };
280
+ const save = () => api("mailboxes", { method: "POST", body: { mailboxes: all() } });
281
+ const connect = (method) => run(async () => {
282
+ const saved = await save();
283
+ if (editing && (saved.setupMethod !== "graph" || saved.step === "connected" || saved.step === "awaiting_access"))
284
+ return saved;
285
+ await signIn(api, method);
286
+ });
287
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Header, { title: editing ? "Mailboxen wijzigen" : "Koppel je mailbox aan de helpdesk", lead: editing
288
+ ? graph
289
+ ? "Na het opslaan meld je je opnieuw aan bij Microsoft. Tot de controle slaagt, staat de helpdesk uit."
290
+ : "Na het opslaan voer je het script opnieuw uit. Tot de controle slaagt, staat de helpdesk uit."
291
+ : "Mail komt binnen in de helpdesk. Antwoorden gaan vanaf dezelfde mailbox en staan in Outlook bij Verzonden items." }), (0, jsx_runtime_1.jsxs)("section", { className: cls.card, "aria-label": "Mailboxen koppelen", children: [(0, jsx_runtime_1.jsxs)("div", { className: cls.field, children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: `${id}-mb`, className: cls.label, children: addresses.length > 1 ? "Welke mailboxen?" : "Welke mailbox?" }), (0, jsx_runtime_1.jsxs)("div", { className: cls.chipBox, children: [addresses.map((address) => ((0, jsx_runtime_1.jsxs)("span", { className: cls.chip, children: [address, (0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.chipRemove, "aria-label": `${address} weghalen`, onClick: () => remove(address), children: (0, jsx_runtime_1.jsx)("svg", { "aria-hidden": "true", width: "10", height: "10", viewBox: "0 0 10 10", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", children: (0, jsx_runtime_1.jsx)("path", { d: "M2 2l6 6M8 2L2 8" }) }) })] }, address))), (0, jsx_runtime_1.jsx)("input", { id: `${id}-mb`, type: "email", autoComplete: "off", placeholder: addresses.length === 0 ? "info@jouwbedrijf.nl" : "Nog een mailbox toevoegen", className: cls.chipInput, value: draft, onChange: (e) => setDraft(e.target.value), onKeyDown: onKeyDown, onBlur: commitDraft })] }), (0, jsx_runtime_1.jsx)("p", { "aria-live": "polite", className: lookup ? (lookup.ok ? cls.ok : cls.error) : cls.muted, children: lookup ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [lookup.ok && (0, jsx_runtime_1.jsx)(Check, {}), lookup.text] })) : ("Meestal een gedeelde mailbox, zoals info@. Typ het hoofdadres, geen alias.") })] }), (0, jsx_runtime_1.jsxs)("div", { className: cls.field, children: [(0, jsx_runtime_1.jsxs)("button", { type: "button", className: cls.primaryButton, disabled: busy || all().length === 0, onClick: () => void connect(graph ? "graph" : "script"), children: [(0, jsx_runtime_1.jsx)(MicrosoftMark, {}), editing ? (graph ? "Opslaan en opnieuw aanmelden" : "Opslaan") : "Koppelen met Microsoft"] }), (0, jsx_runtime_1.jsx)("p", { className: cls.center, children: graph
292
+ ? "Je meldt je één keer aan als Global Administrator. Geen script, niets installeren."
293
+ : "Je geeft als beheerder toestemming. Daarna voer je één PowerShell-script uit." })] }), (0, jsx_runtime_1.jsx)(RightsDetails, { status: status }), graph && !editing && ((0, jsx_runtime_1.jsxs)("p", { className: cls.muted, children: ["Werk je liever met PowerShell?", " ", (0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.linkButton, disabled: busy || all().length === 0, onClick: () => void connect("script"), children: "Gebruik het script" })] }))] }), editing ? ((0, jsx_runtime_1.jsxs)("div", { className: cls.actions, children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.secondaryButton, onClick: () => setView("auto"), children: "Annuleren" }), (0, jsx_runtime_1.jsx)(ResetControl, { busy: busy, run: run, api: api, label: "Ontkoppelen en opnieuw beginnen" })] })) : ((0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col items-center gap-1", children: [(0, jsx_runtime_1.jsx)("p", { className: cls.muted, children: "Geen beheerder in Microsoft 365?" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.linkButton, disabled: busy || all().length === 0, onClick: () => void run(save, "forward"), children: "Stuur een link naar je IT-beheerder" })] }))] }));
294
+ }
295
+ function ItStartStep({ status, busy, run, api }) {
296
+ const graph = status.graphSetupAvailable;
297
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Header, { title: status.mailboxes.length > 1 ? "Koppel deze mailboxen aan de helpdesk" : "Koppel deze mailbox aan de helpdesk", lead: `${status.companyName} wil mail uit ${status.mailboxes.length > 1 ? "deze mailboxen" : "deze mailbox"} afhandelen in hun app. Dat kost je één aanmelding bij Microsoft.` }), (0, jsx_runtime_1.jsxs)("section", { className: cls.card, "aria-label": "Koppelen", children: [(0, jsx_runtime_1.jsxs)("div", { className: cls.field, children: [(0, jsx_runtime_1.jsx)("span", { className: cls.label, children: status.mailboxes.length > 1 ? "Mailboxen" : "Mailbox" }), (0, jsx_runtime_1.jsx)(MailboxChips, { addresses: status.mailboxes })] }), (0, jsx_runtime_1.jsxs)("div", { className: cls.field, children: [(0, jsx_runtime_1.jsxs)("button", { type: "button", className: cls.primaryButton, disabled: busy, onClick: () => void run(() => signIn(api, graph ? "graph" : "script")), children: [(0, jsx_runtime_1.jsx)(MicrosoftMark, {}), "Koppelen met Microsoft"] }), (0, jsx_runtime_1.jsx)("p", { className: cls.center, children: graph
298
+ ? "Meld je aan als Global Administrator van deze omgeving, of met je partneraccount."
299
+ : "Je geeft als beheerder toestemming. Daarna voer je één PowerShell-script uit." })] }), (0, jsx_runtime_1.jsx)(RightsDetails, { status: status, open: true })] }), graph && ((0, jsx_runtime_1.jsxs)("p", { className: cls.center, children: ["Werk je liever met PowerShell?", " ", (0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.linkButton, disabled: busy, onClick: () => void run(() => signIn(api, "script")), children: "Gebruik het script" })] }))] }));
300
+ }
301
+ function forwardMessage(graph) {
302
+ const ask = graph
303
+ ? "Het gaat om één keer aanmelden bij Microsoft als Global Administrator. Dat duurt een paar minuten."
304
+ : "Het gaat om één keer toestemming geven en één PowerShell-script uitvoeren. Dat duurt ongeveer 10 minuten.";
305
+ return `Hoi,
306
+
307
+ We koppelen onze mailbox aan de helpdesk in onze app. Daarvoor is één keer jouw hulp nodig met beheerdersrechten in Microsoft 365. ${ask}
308
+
309
+ De link hieronder legt uit welke rechten de app krijgt:
310
+ `;
311
+ }
312
+ function ForwardStep({ status, busy, run, api, setView }) {
313
+ const id = (0, react_1.useId)();
314
+ const [link, setLink] = (0, react_1.useState)(null);
315
+ const [copied, setCopied] = (0, react_1.useState)("");
316
+ const create = () => run(async () => {
317
+ setLink(await api("it-link", { method: "POST" }));
318
+ }, "forward");
319
+ const revoke = () => run(async () => {
320
+ const next = await api("it-link", { method: "DELETE" });
321
+ setLink(null);
322
+ return next;
323
+ }, "forward");
324
+ const copy = async (text, what) => setCopied((await copyText(text)) ? `${what} gekopieerd.` : "Kopiëren lukte niet. Selecteer de tekst en kopieer die zelf.");
325
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: cls.header, children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.quietButton, onClick: () => setView("auto"), children: "\u2190 Terug" }) }), (0, jsx_runtime_1.jsx)("h1", { className: cls.title, children: "Laat je IT-beheerder koppelen" }), (0, jsx_runtime_1.jsx)("p", { className: cls.lead, children: "Stuur deze link. Je beheerder heeft geen account in de app nodig en ziet alleen deze koppeling." })] }), (0, jsx_runtime_1.jsx)("section", { className: cls.card, "aria-label": "Doorsturen", children: link ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: cls.field, children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: `${id}-link`, className: cls.label, children: "Link voor je IT-beheerder" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex gap-2", children: [(0, jsx_runtime_1.jsx)("input", { id: `${id}-link`, readOnly: true, className: cls.input, value: link.url }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.secondaryButton, onClick: () => void copy(link.url, "Link"), children: "Kopi\u00EBren" })] }), (0, jsx_runtime_1.jsxs)("p", { className: cls.muted, children: ["Geldig tot ", formatDate(link.expiresAt), ". Werkt alleen voor ", status.mailboxes.join(", "), "."] })] }), (0, jsx_runtime_1.jsxs)("div", { className: cls.actions, children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.secondaryButton, onClick: () => void copy(`${forwardMessage(status.graphSetupAvailable)}${link.url}`, "Bericht"), children: "Kopieer met uitleg erbij" }), (0, jsx_runtime_1.jsx)("a", { href: link.url, target: "_blank", rel: "noreferrer", className: cls.secondaryButton, children: "Bekijk wat je beheerder ziet" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.quietButton, disabled: busy, onClick: () => void revoke(), children: "Link intrekken" })] }), (0, jsx_runtime_1.jsx)("p", { "aria-live": "polite", className: cls.muted, children: copied })] })) : ((0, jsx_runtime_1.jsxs)("div", { className: cls.field, children: [status.itLinkExpiresAt && ((0, jsx_runtime_1.jsxs)("p", { className: cls.muted, children: ["Er is al een link, geldig tot ", formatDate(status.itLinkExpiresAt), ". Een nieuwe link maakt de vorige ongeldig."] })), (0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.primaryButton, disabled: busy, onClick: () => void create(), children: status.itLinkExpiresAt ? "Nieuwe link maken" : "Link maken" }), status.itLinkExpiresAt && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.quietButton, disabled: busy, onClick: () => void revoke(), children: "Link intrekken" }))] })) }), (0, jsx_runtime_1.jsxs)("p", { className: cls.info, children: [(0, jsx_runtime_1.jsxs)("svg", { "aria-hidden": "true", width: "18", height: "18", viewBox: "0 0 18 18", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", children: [(0, jsx_runtime_1.jsx)("circle", { cx: "9", cy: "9", r: "7.2" }), (0, jsx_runtime_1.jsx)("path", { d: "M9 5.2v4.3l2.6 1.6" })] }), "Je krijgt bericht zodra de koppeling actief is. Je hoeft deze pagina niet open te houden."] })] }));
326
+ }
327
+ function PreparingStep({ status }) {
328
+ return ((0, jsx_runtime_1.jsx)(Header, { title: "Microsoft 365 wordt klaargezet", lead: `DXV zet de koppeling voor ${status.companyName} klaar. Dat duurt meestal minder dan een werkdag. Je hoeft niets te doen: deze pagina laat het zien zodra je kunt koppelen.` }));
329
+ }
330
+ function WaitingStep({ status, busy, run, api, setView }) {
331
+ const graph = status.setupMethod === "graph";
332
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Header, { title: "Bijna klaar", lead: "Microsoft zet de toegang nu aan. Dat duurt meestal minder dan 2 uur. Je kunt dit venster sluiten: je krijgt bericht zodra de helpdesk start." }), (0, jsx_runtime_1.jsxs)("ol", { className: cls.checklist, "aria-label": "Voortgang", children: [(0, jsx_runtime_1.jsxs)("li", { className: cls.checkItem, children: [(0, jsx_runtime_1.jsx)("span", { className: cls.checkDone, children: (0, jsx_runtime_1.jsx)(Check, {}) }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col gap-0.5", children: [(0, jsx_runtime_1.jsx)("span", { className: cls.checkTitle, children: graph ? "Aangemeld bij Microsoft" : "Script uitgevoerd" }), graph && status.signedInAs && (0, jsx_runtime_1.jsxs)("span", { className: cls.muted, children: ["als ", status.signedInAs] })] })] }), (0, jsx_runtime_1.jsxs)("li", { className: cls.checkItem, children: [(0, jsx_runtime_1.jsx)("span", { className: cls.checkDone, children: (0, jsx_runtime_1.jsx)(Check, {}) }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col gap-0.5", children: [(0, jsx_runtime_1.jsxs)("span", { className: cls.checkTitle, children: ["Toegang ingesteld voor ", status.mailboxes.join(", ")] }), (0, jsx_runtime_1.jsxs)("span", { className: cls.muted, children: ["Alleen ", status.mailboxes.length > 1 ? "deze mailboxen" : "deze mailbox", ". Andere mailboxen blijven dicht."] })] })] }), (0, jsx_runtime_1.jsxs)("li", { className: cls.checkItem, children: [(0, jsx_runtime_1.jsx)("span", { className: cls.checkBusy, "aria-hidden": "true" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col gap-0.5", children: [(0, jsx_runtime_1.jsx)("span", { className: cls.checkTitle, children: "Microsoft zet de toegang aan" }), (0, jsx_runtime_1.jsxs)("span", { className: cls.muted, "aria-live": "polite", children: [status.lastCheckedAt ? `Laatst gecontroleerd om ${formatTime(status.lastCheckedAt)}. ` : "", "We kijken elke 10 minuten", status.checkDeadline ? `, tot ${formatDate(status.checkDeadline)}` : "", "."] })] })] })] }), (0, jsx_runtime_1.jsxs)("div", { className: cls.actions, children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.secondaryButton, disabled: busy, onClick: () => void run(() => api("check", { method: "POST" })), children: "Nu controleren" }), status.viewer === "admin" && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.quietButton, onClick: () => setView("edit"), children: "Mailboxen wijzigen" }))] })] }));
333
+ }
334
+ function noticeText(n) {
335
+ switch (n.kind) {
336
+ case "user_mailbox":
337
+ return `${n.address} is de mailbox van een persoon, geen gedeelde mailbox. Alle mail in Postvak IN daarvan komt in de helpdesk.`;
338
+ case "rule_moves":
339
+ return `De regel "${n.rule ?? ""}" in ${n.address} verplaatst of verwijdert mail uit Postvak IN. Die mail ziet de helpdesk niet.`;
340
+ case "rule_forwards":
341
+ return `De regel "${n.rule ?? ""}" in ${n.address} stuurt mail door. Controleer dat een ander systeem dezelfde mail niet ook afhandelt.`;
342
+ }
343
+ }
344
+ function ConnectedStep({ status, busy, run, api, setView, helpdeskHref, settingsHref, }) {
345
+ if (status.viewer === "it") {
346
+ return (0, jsx_runtime_1.jsx)(Header, { title: "De koppeling is actief", badge: "Actief", lead: "Bedankt! Je kunt dit venster sluiten." });
347
+ }
348
+ const notices = status.notices ?? [];
349
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Header, { title: "De helpdesk is gekoppeld", badge: "Actief", lead: `Nieuwe mail in ${status.mailboxes.join(", ")} verschijnt binnen 5 minuten in de helpdesk.` }), helpdeskHref && ((0, jsx_runtime_1.jsx)("a", { href: helpdeskHref, className: cls.primaryButton, children: "Naar de helpdesk" })), notices.length > 0 && ((0, jsx_runtime_1.jsxs)("div", { className: cls.warning, role: "note", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-base font-semibold", children: "Goed om te weten" }), (0, jsx_runtime_1.jsx)("ul", { className: cls.list, children: notices.map((n, i) => ((0, jsx_runtime_1.jsx)("li", { children: noticeText(n) }, `${n.address}-${n.kind}-${i}`))) })] })), (0, jsx_runtime_1.jsxs)("section", { className: cls.card, "aria-label": "Mailboxen", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [(0, jsx_runtime_1.jsx)("h2", { className: cls.heading, children: "Mailboxen" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.secondaryButton, onClick: () => setView("edit"), children: "Wijzigen" })] }), (0, jsx_runtime_1.jsx)(MailboxChips, { addresses: status.mailboxes }), (0, jsx_runtime_1.jsxs)("p", { className: cls.muted, children: ["Gekoppeld op ", formatDate(status.connectedAt), status.signedInAs ? ` door ${status.signedInAs}` : "", ".", " ", status.setupMethod === "graph" ? null : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Mailboxen wijzigen gaat via de groep ", (0, jsx_runtime_1.jsx)("strong", { children: (0, script_1.exchangeGroupName)(status.appId) }), " in Exchange.", " "] })), "Pauzeren en schrijfmodus vind je bij de", " ", settingsHref ? ((0, jsx_runtime_1.jsx)("a", { href: settingsHref, className: "font-semibold underline-offset-4 hover:underline", children: "helpdesk-instellingen" })) : ("helpdesk-instellingen"), "."] }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-wrap items-center gap-3", children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.quietButton, disabled: busy, onClick: () => void run(() => api("check", { method: "POST" })), children: busy ? "Toegang controleren…" : "Toegang nu controleren" }), (0, jsx_runtime_1.jsx)("span", { className: cls.muted, "aria-live": "polite", children: status.lastCheckedAt ? `Laatst gecontroleerd ${formatDate(status.lastCheckedAt)}: de toegang klopt.` : "" })] })] }), (0, jsx_runtime_1.jsx)(ResetControl, { busy: busy, run: run, api: api, label: "Microsoft 365 ontkoppelen" })] }));
350
+ }
351
+ function retryLabel(status) {
352
+ return status.exchangeSetupError === "exchange_forbidden" ? "Opnieuw aanmelden met een ander account" : "Opnieuw proberen zonder script";
353
+ }
354
+ function FallbackStep({ status, busy, run, api, setView, linkToken }) {
355
+ const scriptOnly = status.exchangeSetupError === "exchange_org_customization";
356
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Header, { title: "Dat lukte niet in \u00E9\u00E9n keer", lead: messages_1.EXCHANGE_SETUP_ERROR_MESSAGES[status.exchangeSetupError] }), !scriptOnly && ((0, jsx_runtime_1.jsxs)("section", { className: cls.card, "aria-label": "Verder gaan", children: [(0, jsx_runtime_1.jsx)("h2", { className: cls.heading, children: "Kies hoe je verder gaat" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.primaryButton, disabled: busy, onClick: () => void run(() => signIn(api, "graph")), children: retryLabel(status) }), status.viewer === "admin" && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.wideSecondaryButton, onClick: () => setView("forward"), children: "Stuur een link naar je IT-beheerder" }))] })), (0, jsx_runtime_1.jsxs)("details", { className: cls.detailsCard, open: scriptOnly, children: [(0, jsx_runtime_1.jsx)("summary", { className: cls.summary, children: "Liever met PowerShell" }), (0, jsx_runtime_1.jsx)("div", { className: "mt-5", children: (0, jsx_runtime_1.jsx)(PowerShellPanel, { status: status, busy: busy, run: run, api: api, setView: setView, linkToken: linkToken }) })] })] }));
357
+ }
358
+ function ScriptStep(props) {
359
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Header, { title: "Voer het PowerShell-script uit", lead: "Het script geeft de app toegang tot precies de gekozen mailboxen. De gegevens zijn al ingevuld." }), (0, jsx_runtime_1.jsx)("section", { className: cls.card, "aria-label": "PowerShell", children: (0, jsx_runtime_1.jsx)(PowerShellPanel, { ...props }) })] }));
360
+ }
361
+ function PowerShellPanel({ status, busy, run, api, linkToken }) {
362
+ const id = (0, react_1.useId)();
363
+ const [kind, setKind] = (0, react_1.useState)("tenant_admin");
364
+ const [adminAccount, setAdminAccount] = (0, react_1.useState)(status.signedInAs ?? "");
365
+ const [partnerTenant, setPartnerTenant] = (0, react_1.useState)(status.mailboxes[0] ? (0, address_1.mailboxDomain)(status.mailboxes[0]) : "");
366
+ const [disableWam, setDisableWam] = (0, react_1.useState)(false);
367
+ const [copied, setCopied] = (0, react_1.useState)("");
368
+ const invocation = (0, react_1.useMemo)(() => {
369
+ try {
370
+ const signInAs = kind === "partner" ? { kind, partnerTenant } : { kind, adminAccount };
371
+ return {
372
+ text: (0, script_1.buildScriptInvocation)({
373
+ appId: status.appId,
374
+ objectId: status.objectId ?? "",
375
+ mailboxes: status.mailboxes,
376
+ checkMailbox: status.checkMailbox ?? "",
377
+ signIn: signInAs,
378
+ disableWam,
379
+ }),
380
+ error: null,
381
+ };
382
+ }
383
+ catch (error) {
384
+ const code = error instanceof script_1.ScriptInputInvalid ? error.code : "";
385
+ const text = code === "invalid_admin_account"
386
+ ? "Vul een geldig beheerdersaccount in, of laat het veld leeg."
387
+ : code === "invalid_partner_tenant"
388
+ ? "Vul het domein van de omgeving in, bijvoorbeeld bedrijf.onmicrosoft.com."
389
+ : "De gegevens voor het script zijn niet compleet. Vernieuw de pagina.";
390
+ return { text: null, error: text };
391
+ }
392
+ }, [kind, adminAccount, partnerTenant, disableWam, status]);
393
+ if (!status.objectId)
394
+ return (0, jsx_runtime_1.jsx)(ObjectIdForm, { status: status, busy: busy, run: run, api: api });
395
+ if (!status.checkMailbox)
396
+ return (0, jsx_runtime_1.jsx)(CheckMailboxForm, { status: status, busy: busy, run: run, api: api, intro: "Het script controleert ook dat de app niet bij een andere mailbox kan." });
397
+ const scriptHref = `${constants_1.SETUP_BASE_PATH}/script${linkToken ? `?t=${encodeURIComponent(linkToken)}` : ""}`;
398
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col gap-5", children: [(0, jsx_runtime_1.jsxs)("fieldset", { className: cls.field, children: [(0, jsx_runtime_1.jsx)("legend", { className: cls.label, children: "Hoe log je in?" }), (0, jsx_runtime_1.jsxs)("label", { className: cls.choice, children: [(0, jsx_runtime_1.jsx)("input", { type: "radio", name: `${id}-signin`, checked: kind === "tenant_admin", onChange: () => setKind("tenant_admin") }), "Met een beheerdersaccount in deze omgeving"] }), (0, jsx_runtime_1.jsxs)("label", { className: cls.choice, children: [(0, jsx_runtime_1.jsx)("input", { type: "radio", name: `${id}-signin`, checked: kind === "partner", onChange: () => setKind("partner") }), "Als IT-partner, met een partnerkoppeling (GDAP)"] })] }), kind === "tenant_admin" ? ((0, jsx_runtime_1.jsxs)("div", { className: cls.field, children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: `${id}-admin`, className: cls.label, children: "Beheerdersaccount (aanbevolen)" }), (0, jsx_runtime_1.jsx)("input", { id: `${id}-admin`, type: "email", autoComplete: "off", className: cls.input, value: adminAccount, onChange: (e) => setAdminAccount(e.target.value) })] })) : ((0, jsx_runtime_1.jsxs)("div", { className: cls.field, children: [(0, jsx_runtime_1.jsxs)("label", { htmlFor: `${id}-partner`, className: cls.label, children: ["Domein van de omgeving van ", status.companyName] }), (0, jsx_runtime_1.jsx)("input", { id: `${id}-partner`, type: "text", autoComplete: "off", className: cls.input, value: partnerTenant, onChange: (e) => setPartnerTenant(e.target.value) })] })), (0, jsx_runtime_1.jsxs)("label", { className: cls.choice, children: [(0, jsx_runtime_1.jsx)("input", { type: "checkbox", checked: disableWam, onChange: (e) => setDisableWam(e.target.checked) }), "Inloggen via de browser (als het Windows-inlogvenster een fout geeft)"] }), (0, jsx_runtime_1.jsxs)("div", { className: cls.codeBlock, children: [(0, jsx_runtime_1.jsxs)("div", { className: cls.codeToolbar, children: [(0, jsx_runtime_1.jsx)("span", { children: "PowerShell" }), (0, jsx_runtime_1.jsxs)("span", { className: cls.actions, children: [(0, jsx_runtime_1.jsx)("a", { href: scriptHref, download: true, className: cls.secondaryButton, children: "Script downloaden" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.secondaryButton, disabled: !invocation.text, onClick: async () => setCopied(invocation.text && (await copyText(invocation.text)) ? "Opdracht gekopieerd." : "Kopiëren lukte niet. Selecteer de tekst en kopieer die zelf."), children: "Opdracht kopi\u00EBren" })] })] }), invocation.text ? ((0, jsx_runtime_1.jsx)("pre", { className: cls.code, "aria-label": "Opdracht voor PowerShell", children: (0, jsx_runtime_1.jsx)("code", { children: invocation.text }) })) : ((0, jsx_runtime_1.jsx)("p", { role: "alert", className: cls.error, children: invocation.error }))] }), (0, jsx_runtime_1.jsx)("p", { "aria-live": "polite", className: cls.muted, children: copied }), (0, jsx_runtime_1.jsxs)("p", { className: cls.muted, children: ["Download het script, open PowerShell in de map waar het staat en plak de opdracht als \u00E9\u00E9n blok. Scripts geblokkeerd? Voer dan eerst", " ", (0, jsx_runtime_1.jsx)("code", { className: cls.inlineCode, children: script_1.EXECUTION_POLICY_TIP }), " uit. Het script is veilig om opnieuw uit te voeren."] }), (0, jsx_runtime_1.jsxs)("details", { children: [(0, jsx_runtime_1.jsx)("summary", { className: cls.summary, children: "Wat het script doet" }), (0, jsx_runtime_1.jsxs)("ul", { className: `${cls.list} mt-3`, children: [(0, jsx_runtime_1.jsx)("li", { children: "Controleert dat je in de juiste omgeving bent ingelogd, met de benodigde Exchange-rechten. Zo niet, dan stopt het zonder iets te wijzigen." }), (0, jsx_runtime_1.jsx)("li", { children: "Vraagt om bevestiging als een adres bij de mailbox van een medewerker hoort, en stopt bij een adres dat niet bestaat of een groep is." }), (0, jsx_runtime_1.jsxs)("li", { children: ["Maakt de groep ", (0, jsx_runtime_1.jsx)("strong", { children: (0, script_1.exchangeGroupName)(status.appId) }), " met de gekozen mailboxen, beperkt de app tot die groep en kent de rollen toe."] }), (0, jsx_runtime_1.jsx)("li", { children: "Zet zo nodig eenmalig \"organisatieaanpassing\" aan in Exchange. Microsoft heeft daarna soms een uur nodig; het script zegt het dan." }), (0, jsx_runtime_1.jsx)("li", { children: "Waarschuwt als een regel mail uit Postvak IN verplaatst, of als mail wordt doorgestuurd." })] })] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.primaryButton, disabled: busy, onClick: () => void run(() => api("script-ran", { method: "POST" })), children: "Script is uitgevoerd" })] }));
399
+ }
400
+ function ObjectIdForm({ status, busy, run, api }) {
401
+ const id = (0, react_1.useId)();
402
+ const [value, setValue] = (0, react_1.useState)("");
403
+ return ((0, jsx_runtime_1.jsxs)("form", { className: cls.field, onSubmit: (e) => {
404
+ e.preventDefault();
405
+ void run(() => api("object-id", { method: "POST", body: { objectId: value } }));
406
+ }, children: [(0, jsx_runtime_1.jsxs)("p", { className: cls.text, children: ["Nog \u00E9\u00E9n gegeven voor het script: het Object ID van ", (0, jsx_runtime_1.jsx)("strong", { children: status.entraAppName }), ". Je vindt het in het Microsoft Entra-beheercentrum onder ", (0, jsx_runtime_1.jsx)("strong", { children: "Enterprise applications" }), " (niet App registrations)."] }), (0, jsx_runtime_1.jsx)("label", { htmlFor: `${id}-oid`, className: cls.label, children: "Object ID" }), (0, jsx_runtime_1.jsx)("input", { id: `${id}-oid`, type: "text", autoComplete: "off", spellCheck: false, placeholder: "00000000-0000-0000-0000-000000000000", className: cls.input, value: value, onChange: (e) => setValue(e.target.value) }), (0, jsx_runtime_1.jsx)("button", { type: "submit", className: cls.primaryButton, disabled: busy || value.trim() === "", children: "Script tonen" })] }));
407
+ }
408
+ function CheckMailboxForm({ status, busy, run, api, intro }) {
409
+ const id = (0, react_1.useId)();
410
+ const [value, setValue] = (0, react_1.useState)("");
411
+ return ((0, jsx_runtime_1.jsxs)("form", { className: cls.field, onSubmit: (e) => {
412
+ e.preventDefault();
413
+ void run(() => api("mailboxes", { method: "POST", body: { mailboxes: status.mailboxes, checkMailbox: value } }));
414
+ }, children: [(0, jsx_runtime_1.jsxs)("p", { className: cls.text, children: [intro, " Kies daarvoor een andere mailbox in dezelfde omgeving, bijvoorbeeld je eigen. We lezen er niets uit."] }), (0, jsx_runtime_1.jsx)("label", { htmlFor: `${id}-check`, className: cls.label, children: "Mailbox waar de app niet bij mag" }), (0, jsx_runtime_1.jsx)("input", { id: `${id}-check`, type: "email", autoComplete: "off", className: cls.input, value: value, onChange: (e) => setValue(e.target.value) }), (0, jsx_runtime_1.jsx)("button", { type: "submit", className: cls.primaryButton, disabled: busy || value.trim() === "", children: "Opslaan en controleren" })] }));
415
+ }
416
+ const FAILURE_COPY = Object.freeze({
417
+ scope_leak: {
418
+ title: "De app kan bij een mailbox waar hij niet bij mag",
419
+ body: (s) => `Waarschijnlijk staan er in Entra machtigingen die voor alle mailboxen gelden. Verwijder bij ${s.entraAppName} de API-machtigingen Mail.Read, Mail.ReadWrite en Mail.Send.`,
420
+ },
421
+ mailbox_unreachable: {
422
+ title: "De app kan niet bij een gekozen mailbox",
423
+ body: (s) => s.setupMethod === "graph"
424
+ ? "Controleer of je het hoofdadres van de mailbox hebt ingevuld, niet een alias. Meld je anders opnieuw aan bij Microsoft."
425
+ : `Controleer of deze mailbox direct in de groep ${(0, script_1.exchangeGroupName)(s.appId)} staat. Voer anders het script nog een keer uit.`,
426
+ },
427
+ mailbox_missing: {
428
+ title: "Een gekozen mailbox bestaat niet",
429
+ body: () => "Microsoft kent dit adres niet als mailbox. Controleer het adres en pas de lijst aan.",
430
+ },
431
+ check_mailbox_missing: {
432
+ title: "We hebben nog een mailbox nodig voor de controle",
433
+ body: () => "Met een mailbox die je niet koppelt, controleren we dat de app er juist niet bij kan.",
434
+ },
435
+ });
436
+ function FailedStep({ status, busy, run, api, setView }) {
437
+ const failure = status.failure ?? "mailbox_unreachable";
438
+ const copy = FAILURE_COPY[failure];
439
+ const graph = status.setupMethod === "graph" && status.graphSetupAvailable;
440
+ const addresses = (status.checks ?? [])
441
+ .filter((c) => failure === "scope_leak" ? c.role === "check" && c.status === "ok" : failure === "check_mailbox_missing" ? c.role === "check" : c.role === "mailbox" && c.status !== "ok")
442
+ .map((c) => c.address);
443
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Header, { title: "De koppeling is nog niet actief", lead: "De helpdesk blijft uit tot dit is opgelost. Er is geen mail opgehaald of verstuurd." }), (0, jsx_runtime_1.jsxs)("section", { className: cls.card, role: "alert", "aria-label": copy.title, children: [(0, jsx_runtime_1.jsx)("h2", { className: cls.heading, children: copy.title }), addresses.length > 0 && (0, jsx_runtime_1.jsx)(MailboxChips, { addresses: addresses }), failure === "check_mailbox_missing" ? ((0, jsx_runtime_1.jsx)(CheckMailboxForm, { status: status, busy: busy, run: run, api: api, intro: copy.body(status) })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("p", { className: cls.text, children: copy.body(status) }), (0, jsx_runtime_1.jsxs)("div", { className: cls.actions, children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.secondaryButton, disabled: busy, onClick: () => void run(() => api("check", { method: "POST" })), children: "Opnieuw controleren" }), graph && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.secondaryButton, disabled: busy, onClick: () => void run(() => signIn(api, "graph")), children: "Opnieuw aanmelden bij Microsoft" })), status.viewer === "admin" && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.quietButton, onClick: () => setView("edit"), children: "Mailboxen wijzigen" }))] })] }))] }), !graph && failure !== "check_mailbox_missing" && failure !== "mailbox_missing" && ((0, jsx_runtime_1.jsxs)("details", { className: cls.detailsCard, children: [(0, jsx_runtime_1.jsx)("summary", { className: cls.summary, children: "Script opnieuw bekijken" }), (0, jsx_runtime_1.jsx)("div", { className: "mt-5", children: (0, jsx_runtime_1.jsx)(PowerShellPanel, { status: status, busy: busy, run: run, api: api, setView: setView }) })] }))] }));
444
+ }
445
+ function ResetControl({ busy, run, api, label }) {
446
+ const [confirming, setConfirming] = (0, react_1.useState)(false);
447
+ if (!confirming) {
448
+ return ((0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.dangerLink, onClick: () => setConfirming(true), children: label }));
449
+ }
450
+ return ((0, jsx_runtime_1.jsxs)("div", { role: "group", "aria-label": "Ontkoppelen bevestigen", className: cls.actions, children: [(0, jsx_runtime_1.jsx)("span", { className: cls.text, children: "Weet je het zeker? De helpdesk stopt en de koppeling wordt gewist. Mail in Outlook blijft staan." }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.dangerButton, disabled: busy, onClick: () => void run(() => api("reset", { method: "POST", body: { confirm: true } })), children: "Ja, ontkoppelen" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: cls.secondaryButton, onClick: () => setConfirming(false), children: "Annuleren" })] }));
451
+ }
@@ -0,0 +1,27 @@
1
+ export declare const SCRIPT_FILE_NAME = "dxv-helpdesk-koppelen.ps1";
2
+ export declare const EXECUTION_POLICY_TIP = "Set-ExecutionPolicy -Scope Process Bypass";
3
+ export declare function exchangeGroupName(appId: string): string;
4
+ export declare function buildExchangeScript(): string;
5
+ export type ScriptSignIn = {
6
+ kind: "tenant_admin";
7
+ adminAccount?: string;
8
+ } | {
9
+ kind: "partner";
10
+ partnerTenant: string;
11
+ };
12
+ export interface ScriptInvocationInput {
13
+ appId: string;
14
+ objectId: string;
15
+ mailboxes: string[];
16
+ checkMailbox: string;
17
+ signIn: ScriptSignIn;
18
+ disableWam?: boolean;
19
+ }
20
+ export type ScriptInputError = "invalid_app_id" | "invalid_object_id" | "invalid_mailbox" | "no_mailboxes" | "invalid_check_mailbox" | "invalid_admin_account" | "invalid_partner_tenant" | "unsafe_value";
21
+ export declare class ScriptInputInvalid extends Error {
22
+ readonly code: ScriptInputError;
23
+ readonly value?: string | undefined;
24
+ constructor(code: ScriptInputError, value?: string | undefined);
25
+ }
26
+ export declare function psQuote(value: string): string;
27
+ export declare function buildScriptInvocation(input: ScriptInvocationInput): string;