@scalio-cloud/ui 0.88.0 → 0.89.0

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 (3) hide show
  1. package/README.md +5 -0
  2. package/package.json +1 -1
  3. package/react/mail.js +55 -13
package/README.md CHANGED
@@ -767,6 +767,11 @@ Citadel, Foundry and Pulse), the provider `tenant` also asks «Tenant, der sende
767
767
  «RBAC for Applications», only the sending mailbox) with a copy button; `mailApi` has `sendRights()`. The default
768
768
  `graphHint` and `tenantHint` now point to that script instead of the Entra permission Mail.Send.
769
769
 
770
+ Since 0.89.0 (scalio-platform 0.48.0): when `GET /mail/send-rights/status` or `POST /mail/send-rights/grant` answers
771
+ 503 `{detail, code: "exchange_unreachable", retry_after}`, `MailTransport` says «Exchange Online ist im Moment nicht
772
+ erreichbar» with the seconds left next to the buttons and greys out «Senderecht setzen» and «Status prüfen» for
773
+ `retry_after` seconds (30 if missing); then «Status prüfen» stays to try again. No toast, no app code needed.
774
+
770
775
  ## Protokoll: Aktionen und Jobs (React)
771
776
 
772
777
  One menu item «Protokoll» with two tabs like Nexus (scalio-docs ADR 0070). The server side is scalio-platform
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalio-cloud/ui",
3
- "version": "0.88.0",
3
+ "version": "0.89.0",
4
4
  "description": "Scalio Control Room design tokens, Tailwind preset, self-hosted fonts, the shared app header, sign-in layout, sidebar and page blocks",
5
5
  "license": "SEE LICENSE IN README.md",
6
6
  "private": false,
package/react/mail.js CHANGED
@@ -30,6 +30,8 @@ const LABELS = {
30
30
  rightsUnknown: "Senden Sie eine Testmail, um das Senderecht zu bestätigen.",
31
31
  rightsRefused: "Microsoft 365 hat die Testmail abgelehnt (Zugriff verweigert), obwohl das Senderecht gesetzt scheint. Exchange hat es noch nicht übernommen oder es gilt nicht für dieses Postfach: Prüfen Sie das Postfach und das Senderecht in Exchange Online und versuchen Sie es später nochmals.",
32
32
  rightsSettling: (at) => `Die App hat das Senderecht eben geändert. Exchange übernimmt es bis spätestens ${at}; bis dahin kann Microsoft die Mail noch ablehnen.`,
33
+ exchangeUnreachable: "Exchange Online ist im Moment nicht erreichbar. Bitte versuchen Sie es später erneut.",
34
+ exchangeRetry: (n) => `Erneut möglich in ${n} ${n === 1 ? "Sekunde" : "Sekunden"}.`,
33
35
  rightsScriptAlso: "Lieber selbst ausführen? Skript anzeigen",
34
36
  testFirst: "Speichern Sie zuerst Weg und Postfach.",
35
37
  transportHint: "Über welchen Server die App Mails schickt. Passwort und Client-Secret werden verschlüsselt gespeichert und nie angezeigt.",
@@ -126,6 +128,8 @@ const LABELS = {
126
128
  rightsUnknown: "Send a test mail to confirm the send right.",
127
129
  rightsRefused: "Microsoft 365 refused the test mail (access denied) although the send right seems to be set. Exchange has not applied it yet or it does not cover this mailbox: check the mailbox and the send right in Exchange Online and try again later.",
128
130
  rightsSettling: (at) => `The app has just changed the send right. Exchange applies it by ${at} at the latest; until then Microsoft may still refuse the mail.`,
131
+ exchangeUnreachable: "Exchange Online is not reachable right now. Please try again later.",
132
+ exchangeRetry: (n) => `Possible again in ${n} ${n === 1 ? "second" : "seconds"}.`,
129
133
  rightsScriptAlso: "Rather run it yourself? Show script",
130
134
  testFirst: "Save the way and the mailbox first.",
131
135
  transportHint: "Which server the app sends mail through. Password and client secret are stored encrypted and never shown.",
@@ -221,6 +225,15 @@ function errorText(err) {
221
225
  return (err && err.message) || String(err);
222
226
  }
223
227
 
228
+ // scalio-platform 0.48.0: Exchange Online does not answer -> 503 {detail, code: "exchange_unreachable", retry_after} (seconds)
229
+ function exchangeUnreachable(err) {
230
+ const r = err && err.response;
231
+ const d = r && r.data;
232
+ if (!r || r.status !== 503 || !d || d.code !== "exchange_unreachable") return null;
233
+ const n = Number(d.retry_after);
234
+ return { seconds: n > 0 ? Math.ceil(n) : 30 };
235
+ }
236
+
224
237
  function fmtTime(iso, lang) {
225
238
  try {
226
239
  return new Date(iso).toLocaleString(lang === "en" ? "en-GB" : "de-CH", { dateStyle: "short", timeStyle: "short" });
@@ -317,7 +330,26 @@ function MailTransport(props) {
317
330
  const [mbxList, setMbxList] = React.useState(null); // shared mailboxes of the chosen tenant, or null
318
331
  const [mbxOther, setMbxOther] = React.useState(false);
319
332
  const [testOk, setTestOk] = React.useState(false);
333
+ const [blockedUntil, setBlockedUntil] = React.useState(0); // Exchange Online unreachable: buttons off until then (ms)
334
+ const [wasBlocked, setWasBlocked] = React.useState(false); // keeps «Status prüfen» there after the wait, to try again
335
+ const [, setClock] = React.useState(0);
320
336
  const showOutbox = props.outbox !== false;
337
+ const blockSeconds = Math.max(0, Math.ceil((blockedUntil - Date.now()) / 1000));
338
+ const blocked = blockSeconds > 0;
339
+ // returns true when the error was «Exchange Online unreachable» (then the page shows the reason at the buttons)
340
+ const blockOnUnreachable = (err) => {
341
+ const u = exchangeUnreachable(err);
342
+ if (u) { setBlockedUntil(Date.now() + u.seconds * 1000); setWasBlocked(true); }
343
+ return !!u;
344
+ };
345
+ React.useEffect(() => {
346
+ if (!blockedUntil) return undefined;
347
+ const t = setInterval(() => {
348
+ setClock((c) => c + 1);
349
+ if (Date.now() >= blockedUntil) { setBlockedUntil(0); clearInterval(t); }
350
+ }, 250);
351
+ return () => clearInterval(t);
352
+ }, [blockedUntil]);
321
353
 
322
354
  const loadOutbox = React.useCallback(() => {
323
355
  if (!showOutbox) return Promise.resolve();
@@ -325,8 +357,9 @@ function MailTransport(props) {
325
357
  }, [client, showOutbox]);
326
358
  const loadRights = React.useCallback(() => {
327
359
  if (!client.rightsStatus) return Promise.resolve();
328
- return client.rightsStatus().then((r) => setRightsInfo(r && r.mode ? r : null)).catch(() => setRightsInfo(null));
329
- }, [client]);
360
+ return client.rightsStatus().then((r) => setRightsInfo(r && r.mode ? r : null))
361
+ .catch((err) => { if (!blockOnUnreachable(err)) setRightsInfo(null); });
362
+ }, [client]); // eslint-disable-line react-hooks/exhaustive-deps
330
363
  React.useEffect(() => {
331
364
  let alive = true;
332
365
  client.settings().then((d) => { if (alive) { setForm(d); if (d && d.send_rights) loadRights(); } }).catch((e) => alive && m.fail(e));
@@ -388,7 +421,7 @@ function MailTransport(props) {
388
421
  const denied = !delivered && viaM365 && r.state === "ok" && /403|AccessDenied/i.test(String((err && (err.message || err.code || err.status)) || err || ""));
389
422
  setRightsInfo(delivered && viaM365 && r.state === "unknown" ? Object.assign({}, r, { state: "ok", detail: "" })
390
423
  : denied ? Object.assign({}, r, { state: "missing", detail: L.rightsRefused, settling_until: null }) : r);
391
- }).catch(() => undefined);
424
+ }).catch((e) => { blockOnUnreachable(e); });
392
425
  };
393
426
  const test = async () => {
394
427
  setTesting(true);
@@ -441,9 +474,11 @@ function MailTransport(props) {
441
474
  if (props.notify) props.notify(L.autoGranted, "success");
442
475
  else setScriptMsg({ tone: "ok", text: L.autoGranted });
443
476
  } catch (err) {
444
- const text = (props.formatError || errorText)(err);
445
- if (props.notify) props.notify(text, "error");
446
- else setScriptMsg({ tone: "error", text });
477
+ if (!blockOnUnreachable(err)) {
478
+ const text = (props.formatError || errorText)(err);
479
+ if (props.notify) props.notify(text, "error");
480
+ else setScriptMsg({ tone: "error", text });
481
+ }
447
482
  }
448
483
  setGranting(false);
449
484
  };
@@ -567,11 +602,18 @@ function MailTransport(props) {
567
602
  ? h(
568
603
  SettingsSection,
569
604
  { id: "mail-rights", title: L.rightsTitle, description: auto ? L.autoHint : L.rightsHint, testId: "mail-rights" },
570
- rightsInfo && rightsInfo.mode !== "none" && rightsKnown
605
+ (rightsInfo && rightsInfo.mode !== "none" && rightsKnown) || wasBlocked
571
606
  ? h("div", { className: "scalio-mail-rights-state" },
572
- h("span", { className: `scalio-badge is-${{ ok: "ok", missing: "warn" }[rightsInfo.state]}`, "data-testid": "mail-rights-state" },
573
- L.rightsState[rightsInfo.state]),
574
- h("button", { type: "button", className: "scalio-btn is-ghost", onClick: loadRights, "data-testid": "mail-rights-check" }, L.rightsCheck))
607
+ rightsInfo && rightsKnown
608
+ ? h("span", { className: `scalio-badge is-${{ ok: "ok", missing: "warn" }[rightsInfo.state]}`, "data-testid": "mail-rights-state" },
609
+ L.rightsState[rightsInfo.state])
610
+ : null,
611
+ h("button", { type: "button", className: "scalio-btn is-ghost", onClick: loadRights, disabled: blocked, title: blocked ? L.exchangeUnreachable : undefined,
612
+ "data-testid": "mail-rights-check" }, L.rightsCheck))
613
+ : null,
614
+ blocked
615
+ ? h("p", { className: "scalio-settings-help is-error", role: "alert", "data-testid": "mail-rights-unreachable" },
616
+ `${L.exchangeUnreachable} ${L.exchangeRetry(blockSeconds)}`)
575
617
  : null,
576
618
  // «unknown»: the app can not ask Exchange; no badge, one sentence what to do (the test mail confirms it)
577
619
  rightsInfo && rightsInfo.mode !== "none" && !rightsKnown
@@ -585,14 +627,14 @@ function MailTransport(props) {
585
627
  rightsInfo && rightsInfo.detail && !rightsOk
586
628
  ? h("p", { className: "scalio-settings-help is-error", "data-testid": "mail-rights-detail" }, rightsInfo.detail)
587
629
  : null,
588
- showGrant
630
+ showGrant || (wasBlocked && client.grantRights)
589
631
  ? h("div", { className: "scalio-settings-section-footer" },
590
632
  offReason
591
633
  ? h("p", { className: "scalio-settings-help", "data-testid": "mail-rights-grant-off" },
592
634
  (props.grantOffHint && props.grantOffHint[offReason]) || L.grantOff[offReason])
593
635
  : null,
594
- h("button", { type: "button", className: "scalio-btn is-primary", onClick: grant, disabled: granting || !auto,
595
- title: offReason ? ((props.grantOffHint && props.grantOffHint[offReason]) || L.grantOff[offReason]) : undefined,
636
+ h("button", { type: "button", className: "scalio-btn is-primary", onClick: grant, disabled: granting || !auto || blocked,
637
+ title: offReason ? ((props.grantOffHint && props.grantOffHint[offReason]) || L.grantOff[offReason]) : (blocked ? L.exchangeUnreachable : undefined),
596
638
  "data-testid": "mail-rights-grant" },
597
639
  h(Icons.Check, { className: "scalio-icon" }), L.autoGrant))
598
640
  : null,