@scalio-cloud/ui 0.40.0 → 0.42.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.
package/README.md CHANGED
@@ -156,6 +156,13 @@ The settings card `<BeaconConnection client={peersApi(api)} lang={lang} />` pair
156
156
  (address and one-time code from Beacon, Einstellungen -> Verbundene Apps); findings then go to Beacon. Backend:
157
157
  scalio-connect 0.8.0 `peers.web.admin_router`.
158
158
 
159
+ `<TenantConnectStep client={...} app="Citadel" lang={lang} />` is the shared step «Microsoft-Tenant» for the setup
160
+ wizards and the settings (ADR 0092 setup/S2): exactly one tenant, «Mit Microsoft verbinden» through «Scalio Setup»,
161
+ the setup script as the way out, and the code that comes back as `#scalio_connect=<code>` is redeemed by itself. The
162
+ app passes its own routes as `client`: `status()` (`{connected, organization, azure_tenant_id, missing, last_error}`),
163
+ `link()` (`{url}`), `script()` (`{script}`), `redeem(code)` and optionally `check()`. An app with a tenant list
164
+ creates its default tenant itself in these calls. `onChange(status)` runs after every action.
165
+
159
166
  `link` is the router's `NavLink` (it gets `to`, `end`, a `className` function and `onClick`); without it the
160
167
  sidebar renders plain links and marks the item for `activePath`. Item test ids default to `nav-<path>`
161
168
  (`nav-overview` for `/`), or set `testId`. Page blocks: `KpiTile` (tone `error` = red number),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalio-cloud/ui",
3
- "version": "0.40.0",
3
+ "version": "0.42.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/beacon.js CHANGED
@@ -28,6 +28,8 @@ function peersApi(api) {
28
28
  return {
29
29
  list: () => data(api.get("/peers")),
30
30
  connect: (url, code) => data(api.post("/peers", { url, code })),
31
+ // ADR 0092: the customer's Beacon from Compass ({beacon: url | ""}); older backends answer 404 -> no suggestion.
32
+ suggestion: () => data(api.get("/peers/suggestion")).catch(() => ({ beacon: "" })),
31
33
  check: (id) => data(api.post(`/peers/${enc(id)}/check`)),
32
34
  remove: (id) => data(api.delete(`/peers/${enc(id)}`)),
33
35
  };
@@ -41,7 +43,11 @@ function BeaconConnection({ client, lang, labels, onChange }) {
41
43
  const [busy, setBusy] = React.useState(false);
42
44
  const [error, setError] = React.useState("");
43
45
  const [note, setNote] = React.useState("");
44
- const load = React.useCallback(() => client.list().then((d) => setSt(d)).catch((err) => (setError(errorText(err)), setSt(false))), [client]);
46
+ const [suggested, setSuggested] = React.useState("");
47
+ const load = React.useCallback(() => {
48
+ if (client.suggestion) client.suggestion().then((d) => setSuggested((d && d.beacon) || "")).catch(() => setSuggested(""));
49
+ return client.list().then((d) => setSt(d)).catch((err) => (setError(errorText(err)), setSt(false)));
50
+ }, [client]);
45
51
  React.useEffect(() => { load(); }, [load]);
46
52
  const run = async (fn, ok) => {
47
53
  setBusy(true);
@@ -93,7 +99,17 @@ function BeaconConnection({ client, lang, labels, onChange }) {
93
99
  }),
94
100
  note ? h("div", { className: "scalio-notice is-ok", "data-testid": "beacon-note" }, note) : null,
95
101
  error ? h("div", { className: "scalio-notice is-error", role: "alert", "data-testid": "beacon-error" }, error) : null,
96
- beacons.length
102
+ !beacons.length && suggested
103
+ ? h(
104
+ "div",
105
+ { className: "scalio-support-conn", "data-testid": "beacon-suggestion" },
106
+ h("p", { className: "scalio-support-meta" }, L.beaconSuggested.replace("{url}", suggested)),
107
+ h("div", { className: "scalio-support-conn-actions" },
108
+ h("button", { type: "button", className: "scalio-btn-primary", disabled: busy, "data-testid": "beacon-suggest-connect",
109
+ onClick: () => run(() => client.connect(suggested, ""), L.beaconPaired) }, L.beaconSuggestConnect))
110
+ )
111
+ : null,
112
+ beacons.length || (suggested && !error) // the code form only without a suggestion or after it failed
97
113
  ? null
98
114
  : h(
99
115
  "form",
package/react/index.js CHANGED
@@ -378,6 +378,6 @@ module.exports = {
378
378
  TEST_IDS,
379
379
  initials,
380
380
  };
381
- Object.assign(module.exports, Nav, Blocks, require("./settings"), require("./support"), require("./beacon"), require("./security"), require("./license"), require("./palette"), require("./unify"), require("./profile"), require("./actions"), require("./selftest"), require("./users"), require("./customers"), require("./roles"), require("./wizard"), require("./maintenance"), require("./backup"), require("./audit"), require("./mail"), require("./saas_updates"), require("./pages"));
381
+ Object.assign(module.exports, Nav, Blocks, require("./settings"), require("./support"), require("./beacon"), require("./security"), require("./license"), require("./palette"), require("./unify"), require("./profile"), require("./actions"), require("./selftest"), require("./users"), require("./customers"), require("./roles"), require("./wizard"), require("./maintenance"), require("./backup"), require("./audit"), require("./mail"), require("./saas_updates"), require("./pages"), require("./tenant"));
382
382
  // After the exports above: auth.js uses LanguageToggle and ThemeToggle from this module.
383
383
  Object.assign(module.exports, require("./auth"), require("./session"));
package/react/labels.js CHANGED
@@ -192,6 +192,28 @@ const LABELS = {
192
192
  beaconChecked: "Verbindung funktioniert (Beacon {version}).",
193
193
  beaconCheckFailed: "Keine Verbindung: {detail}",
194
194
  beaconRemoveConfirm: "Verbindung zu Beacon trennen? Befunde gehen dann nicht mehr an Beacon; die Tickets dort bleiben.",
195
+ beaconSuggested: "Bei Ihrer Organisation läuft Scalio Beacon unter {url}. Verbinden Sie diese Installation mit einem Klick, ohne Kopplungscode.",
196
+ beaconSuggestConnect: "Mit Beacon verbinden",
197
+ // Shared step «Microsoft-Tenant» (TenantConnectStep, ADR 0092 setup/S2)
198
+ tenantTitle: "Microsoft-Tenant",
199
+ tenantHelp: "{app} liest Ihren Microsoft-Tenant mit der eigenen App-Registrierung «Scalio Lesen». Melden Sie sich als Globaler Administrator oder Administrator für privilegierte Rollen an; die Seite «Scalio Setup» legt die Registrierung an und bringt den Code selbst zurück. Scalio speichert keine Anmeldung und kein Token.",
200
+ tenantConnected: "Verbunden",
201
+ tenantNotConnected: "Noch nicht verbunden",
202
+ tenantOrganization: "Organisation",
203
+ tenantId: "Tenant-ID",
204
+ tenantMissing: "Fehlende Berechtigungen: Skript erneut ausführen",
205
+ tenantSignIn: "Mit Microsoft verbinden",
206
+ tenantOrScript: "Oder mit dem Einrichtungsskript",
207
+ tenantScriptHelp: "In der Azure Cloud Shell (PowerShell) oder in PowerShell 7 mit dem Modul Microsoft.Graph ausführen. Es zeigt zuerst die Berechtigungen; erneutes Ausführen ist sicher.",
208
+ tenantShowScript: "Skript anzeigen",
209
+ tenantCode: "Verbindungscode",
210
+ tenantCodeHelp: "Das Skript gibt eine Zeile aus, die mit SCALIO1 beginnt. Fügen Sie die ganze Zeile ein.",
211
+ tenantConnect: "Verbinden",
212
+ tenantDone: "Verbunden: {app} liest diesen Tenant.",
213
+ tenantCheck: "Verbindung prüfen",
214
+ tenantLater: "Sie können den Tenant auch später in den Einstellungen verbinden.",
215
+ copy: "Kopieren",
216
+ download: "Herunterladen",
195
217
  // Two-factor card (SecurityFactors) and license panel (LicensePanel)
196
218
  users: {
197
219
  loading: "Wird geladen …",
@@ -707,6 +729,27 @@ const LABELS = {
707
729
  beaconChecked: "Connection works (Beacon {version}).",
708
730
  beaconCheckFailed: "No connection: {detail}",
709
731
  beaconRemoveConfirm: "Disconnect from Beacon? Findings no longer go to Beacon; the tickets there stay.",
732
+ beaconSuggested: "Scalio Beacon runs for your organisation at {url}. Connect this installation with one click, without a pairing code.",
733
+ beaconSuggestConnect: "Connect with Beacon",
734
+ tenantTitle: "Microsoft tenant",
735
+ tenantHelp: "{app} reads your Microsoft tenant with its own app registration «Scalio Lesen». Sign in as Global Administrator or Privileged Role Administrator; the page «Scalio Setup» creates the registration and brings the code back by itself. Scalio stores no sign-in and no token.",
736
+ tenantConnected: "Connected",
737
+ tenantNotConnected: "Not connected yet",
738
+ tenantOrganization: "Organisation",
739
+ tenantId: "Tenant ID",
740
+ tenantMissing: "Missing permissions: run the script again",
741
+ tenantSignIn: "Connect with Microsoft",
742
+ tenantOrScript: "Or with the setup script",
743
+ tenantScriptHelp: "Run it in the Azure Cloud Shell (PowerShell) or in PowerShell 7 with the Microsoft.Graph module. It shows the permissions first; running it again is safe.",
744
+ tenantShowScript: "Show script",
745
+ tenantCode: "Connection code",
746
+ tenantCodeHelp: "The script prints a line that starts with SCALIO1. Paste the whole line.",
747
+ tenantConnect: "Connect",
748
+ tenantDone: "Connected: {app} reads this tenant.",
749
+ tenantCheck: "Check connection",
750
+ tenantLater: "You can also connect the tenant later in the settings.",
751
+ copy: "Copy",
752
+ download: "Download",
710
753
  users: {
711
754
  loading: "Loading …",
712
755
  search: "Search users",
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ // Shared step «Microsoft-Tenant» for the setup wizards and the settings (scalio-docs ADR 0092 setup/S2,
3
+ // concepts/setup-minimal.md): exactly one tenant, «Mit Microsoft verbinden» through «Scalio Setup», the setup script
4
+ // as the way out. The routes differ per app, so the app passes a client:
5
+ // status() -> {connected, organization?, azure_tenant_id?, subject?, missing?: [], last_error?}
6
+ // link() -> {url} address of «Scalio Setup»; it comes back with #scalio_connect=<code>
7
+ // script() -> {script}
8
+ // redeem(code) -> anything (the code from «Scalio Setup» or from the script)
9
+ // check() -> optional
10
+ // The app creates its default tenant itself (in link/script/redeem) when it keeps a list of tenants.
11
+ const React = require("react");
12
+ const h = React.createElement;
13
+ const { labelsFor } = require("./labels");
14
+
15
+ function errorText(err) {
16
+ const d = err && err.response && err.response.data && err.response.data.detail;
17
+ if (typeof d === "string") return d;
18
+ if (d && typeof d.message === "string") return d.message;
19
+ return (err && err.message) || String(err);
20
+ }
21
+
22
+ // Back from «Scalio Setup»: ...#scalio_connect=<code>. Read once, then removed from the address bar.
23
+ function takeConnectCode() {
24
+ if (typeof window === "undefined") return "";
25
+ const m = /^#scalio_connect=([^&]+)$/.exec(window.location.hash || "");
26
+ if (!m) return "";
27
+ window.history.replaceState(null, "", window.location.pathname + window.location.search);
28
+ return decodeURIComponent(m[1]);
29
+ }
30
+
31
+ function TenantConnectStep({ client, app = "Scalio", lang, labels, onChange, showLater = true }) {
32
+ const L = labelsFor(lang, labels);
33
+ const [st, setSt] = React.useState(null);
34
+ const [script, setScript] = React.useState("");
35
+ const [code, setCode] = React.useState("");
36
+ const [busy, setBusy] = React.useState("");
37
+ const [error, setError] = React.useState("");
38
+ const [note, setNote] = React.useState("");
39
+ const load = React.useCallback(
40
+ () => client.status().then((d) => (setSt(d || {}), d)).catch((err) => (setError(errorText(err)), setSt({}))),
41
+ [client]
42
+ );
43
+ const run = async (kind, fn, ok) => {
44
+ setBusy(kind);
45
+ setError("");
46
+ setNote("");
47
+ try {
48
+ await fn();
49
+ if (ok) setNote(ok);
50
+ } catch (err) {
51
+ setError(errorText(err));
52
+ } finally {
53
+ setBusy("");
54
+ }
55
+ const d = await load();
56
+ if (onChange) onChange(d);
57
+ };
58
+ const redeem = (value) => run("code", async () => {
59
+ await client.redeem(value.trim());
60
+ setCode("");
61
+ setScript("");
62
+ }, L.tenantDone.replace("{app}", app));
63
+ React.useEffect(() => {
64
+ const incoming = takeConnectCode();
65
+ if (incoming) redeem(incoming);
66
+ else load();
67
+ }, []); // eslint-disable-line react-hooks/exhaustive-deps
68
+
69
+ if (st === null) return h("div", { className: "scalio-support-meta" }, L.loading);
70
+ const missing = st.missing || [];
71
+ const signIn = () => run("link", async () => {
72
+ const d = await client.link();
73
+ if (d && d.url) window.location.assign(d.url);
74
+ });
75
+ const download = () => {
76
+ const url = URL.createObjectURL(new Blob([script], { type: "text/plain" }));
77
+ Object.assign(document.createElement("a"), { href: url, download: "Scalio-Lesen.ps1" }).click();
78
+ URL.revokeObjectURL(url);
79
+ };
80
+ return h(
81
+ "div",
82
+ { className: "scalio-support-conn", "data-testid": "tenant-step" },
83
+ h("div", { className: "scalio-support-conn-head" },
84
+ h("span", { className: "scalio-badge " + (st.connected ? "is-ok" : ""), "data-testid": "tenant-state" },
85
+ st.connected ? L.tenantConnected : L.tenantNotConnected)),
86
+ st.connected
87
+ ? h("dl", { className: "scalio-support-conn-facts" },
88
+ st.organization ? h(React.Fragment, null, h("dt", null, L.tenantOrganization), h("dd", null, st.organization)) : null,
89
+ st.azure_tenant_id ? h(React.Fragment, null, h("dt", null, L.tenantId), h("dd", null, st.azure_tenant_id)) : null)
90
+ : h("p", { className: "scalio-support-meta" }, L.tenantHelp.replace("{app}", app)),
91
+ st.last_error ? h("div", { className: "scalio-notice is-error", "data-testid": "tenant-last-error" }, st.last_error) : null,
92
+ missing.length
93
+ ? h("div", { className: "scalio-notice is-error", "data-testid": "tenant-missing" }, L.tenantMissing + ": " + missing.join(", "))
94
+ : null,
95
+ note ? h("div", { className: "scalio-notice is-ok", "data-testid": "tenant-note" }, note) : null,
96
+ error ? h("div", { className: "scalio-notice is-error", role: "alert", "data-testid": "tenant-error" }, error) : null,
97
+ h("div", { className: "scalio-support-conn-actions" },
98
+ st.connected
99
+ ? (client.check
100
+ ? h("button", { type: "button", className: "scalio-btn", disabled: !!busy, "data-testid": "tenant-check",
101
+ onClick: () => run("check", () => client.check()) }, L.tenantCheck)
102
+ : null)
103
+ : h("button", { type: "button", className: "scalio-btn-primary", disabled: !!busy, "data-testid": "tenant-signin",
104
+ onClick: signIn }, L.tenantSignIn)),
105
+ st.connected && !missing.length
106
+ ? null
107
+ : h(
108
+ "div",
109
+ { className: "scalio-support-form", "data-testid": "tenant-script-box" },
110
+ h("div", { className: "scalio-field-label" }, L.tenantOrScript),
111
+ h("p", { className: "scalio-support-meta" }, L.tenantScriptHelp),
112
+ script
113
+ ? h(React.Fragment, null,
114
+ h("textarea", { readOnly: true, rows: 8, className: "scalio-input", value: script, "data-testid": "tenant-script",
115
+ onFocus: (e) => e.target.select() }),
116
+ h("div", { className: "scalio-support-conn-actions" },
117
+ h("button", { type: "button", className: "scalio-btn",
118
+ onClick: () => navigator.clipboard && navigator.clipboard.writeText(script) }, L.copy),
119
+ h("button", { type: "button", className: "scalio-btn", onClick: download }, L.download)))
120
+ : h("button", { type: "button", className: "scalio-btn", disabled: !!busy, "data-testid": "tenant-show-script",
121
+ onClick: () => run("script", async () => setScript(((await client.script()) || {}).script || "")) }, L.tenantShowScript),
122
+ h("form", { onSubmit: (e) => { e.preventDefault(); redeem(code); } },
123
+ h("label", { className: "scalio-field-label", htmlFor: "tenant-code" }, L.tenantCode),
124
+ h("p", { className: "scalio-support-meta" }, L.tenantCodeHelp),
125
+ h("input", { id: "tenant-code", className: "scalio-input", placeholder: "SCALIO1.…", value: code,
126
+ onChange: (e) => setCode(e.target.value), "data-testid": "tenant-code" }),
127
+ h("button", { type: "submit", className: "scalio-btn-primary", disabled: !!busy || code.trim().length < 10,
128
+ "data-testid": "tenant-connect" }, L.tenantConnect))
129
+ ),
130
+ showLater && !st.connected ? h("p", { className: "scalio-support-meta" }, L.tenantLater) : null
131
+ );
132
+ }
133
+
134
+ module.exports = { TenantConnectStep, takeConnectCode };