@scalio-cloud/ui 0.40.0 → 0.43.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 +15 -0
- package/auth.css +6 -0
- package/package.json +1 -1
- package/react/beacon.js +18 -2
- package/react/index.js +2 -2
- package/react/labels.js +85 -0
- package/react/setup.js +102 -0
- package/react/tenant.js +134 -0
package/README.md
CHANGED
|
@@ -156,6 +156,21 @@ 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
|
+
|
|
166
|
+
`<FirstAdminSetup microsoft={...} codeFrom="portal" onSubmit={...} onMicrosoft={...} lang={lang} />` is the first-run
|
|
167
|
+
form «Ersten Administrator anlegen» inside `AuthLayout`, with the same texts in every app (Citadel, Beacon and Pulse
|
|
168
|
+
are the reference). «Mit Microsoft anmelden» is always there: greyed with a hint while the instance has no Scalio ID
|
|
169
|
+
(`microsoft` false), else it calls `onMicrosoft(setupCode)` (the app posts `/auth/setup/microsoft` and redirects).
|
|
170
|
+
`onSubmit({setupCode, name, email, password})` may return `{ok: false, error}` or throw; `error` shows an error from
|
|
171
|
+
outside (e.g. `?sso_error`). Test ids as before: `setup-code-input`, `setup-name-input`, `login-email-input`,
|
|
172
|
+
`login-password-input`, `setup-confirm-input`, `login-submit-button`, `setup-microsoft-btn`.
|
|
173
|
+
|
|
159
174
|
`link` is the router's `NavLink` (it gets `to`, `end`, a `className` function and `onClick`); without it the
|
|
160
175
|
sidebar renders plain links and marks the item for `activePath`. Item test ids default to `nav-<path>`
|
|
161
176
|
(`nav-overview` for `/`), or set `testId`. Page blocks: `KpiTile` (tone `error` = red number),
|
package/auth.css
CHANGED
|
@@ -89,6 +89,12 @@
|
|
|
89
89
|
.scalio-auth-ms:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 1px; }
|
|
90
90
|
.scalio-auth-ms-disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
|
|
91
91
|
.scalio-auth-hint { margin-top: 0.25rem; font-size: 11px; color: hsl(var(--muted-foreground)); }
|
|
92
|
+
/* First-run setup (FirstAdminSetup) */
|
|
93
|
+
.scalio-setup { display: flex; flex-direction: column; gap: 1rem; }
|
|
94
|
+
.scalio-setup-field { display: flex; flex-direction: column; gap: 0.25rem; }
|
|
95
|
+
.scalio-setup-field .scalio-field-label { margin-top: 0; }
|
|
96
|
+
.scalio-setup-field .scalio-auth-hint { margin-top: 0; }
|
|
97
|
+
.scalio-setup-submit { margin-top: 0.25rem; width: 100%; height: 2.75rem; font-size: 0.875rem; }
|
|
92
98
|
|
|
93
99
|
.scalio-auth-msg { border: 1px solid; border-radius: 2px; padding: 0.5rem 0.75rem; font-size: 0.875rem; }
|
|
94
100
|
.scalio-auth-msg-error { color: hsl(var(--destructive)); border-color: hsl(var(--destructive) / 0.35); background: hsl(var(--destructive) / 0.08); }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalio-cloud/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.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
|
|
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
|
-
Object.assign(module.exports, require("./auth"), require("./session"));
|
|
383
|
+
Object.assign(module.exports, require("./auth"), require("./session"), require("./setup"));
|
package/react/labels.js
CHANGED
|
@@ -31,6 +31,27 @@ const LABELS = {
|
|
|
31
31
|
microsoft: "Mit Microsoft anmelden",
|
|
32
32
|
redirecting: "Weiterleitung …",
|
|
33
33
|
orEmail: "oder mit E-Mail",
|
|
34
|
+
// First-run setup «Ersten Administrator anlegen» (FirstAdminSetup), same text in every app
|
|
35
|
+
setup: {
|
|
36
|
+
eyebrow: "Ersteinrichtung",
|
|
37
|
+
title: "Ersten Administrator anlegen",
|
|
38
|
+
subtitle: "Es gibt noch kein Konto. Dieses Konto erhält volle Admin-Rechte.",
|
|
39
|
+
code: "Einrichtungscode",
|
|
40
|
+
codeFromPortal: "Den Einrichtungscode finden Sie im Kundenportal bei Ihrer Instanz.",
|
|
41
|
+
codeFromLog: "Das Backend schreibt ihn bei jedem Start in sein Log (docker logs), oder es ist der Wert von SETUP_CODE.",
|
|
42
|
+
microsoftHint: "Sie werden der erste Administrator. Danach können sich nur Personen Ihrer Microsoft-Organisation anmelden.",
|
|
43
|
+
microsoftOff: "Die Anmeldung mit Microsoft ist auf dieser Instanz noch nicht eingerichtet (Scalio ID).",
|
|
44
|
+
orLocal: "oder lokalen Administrator anlegen",
|
|
45
|
+
name: "Name",
|
|
46
|
+
email: "E-Mail",
|
|
47
|
+
password: "Passwort",
|
|
48
|
+
minLength: "Mindestens {n} Zeichen.",
|
|
49
|
+
confirm: "Passwort bestätigen",
|
|
50
|
+
submit: "Administrator anlegen",
|
|
51
|
+
creating: "Wird angelegt …",
|
|
52
|
+
mismatch: "Die Passwörter stimmen nicht überein.",
|
|
53
|
+
failed: "Das Anlegen ist fehlgeschlagen.",
|
|
54
|
+
},
|
|
34
55
|
email: "E-Mail",
|
|
35
56
|
password: "Passwort",
|
|
36
57
|
forgotPassword: "Passwort vergessen?",
|
|
@@ -192,6 +213,28 @@ const LABELS = {
|
|
|
192
213
|
beaconChecked: "Verbindung funktioniert (Beacon {version}).",
|
|
193
214
|
beaconCheckFailed: "Keine Verbindung: {detail}",
|
|
194
215
|
beaconRemoveConfirm: "Verbindung zu Beacon trennen? Befunde gehen dann nicht mehr an Beacon; die Tickets dort bleiben.",
|
|
216
|
+
beaconSuggested: "Bei Ihrer Organisation läuft Scalio Beacon unter {url}. Verbinden Sie diese Installation mit einem Klick, ohne Kopplungscode.",
|
|
217
|
+
beaconSuggestConnect: "Mit Beacon verbinden",
|
|
218
|
+
// Shared step «Microsoft-Tenant» (TenantConnectStep, ADR 0092 setup/S2)
|
|
219
|
+
tenantTitle: "Microsoft-Tenant",
|
|
220
|
+
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.",
|
|
221
|
+
tenantConnected: "Verbunden",
|
|
222
|
+
tenantNotConnected: "Noch nicht verbunden",
|
|
223
|
+
tenantOrganization: "Organisation",
|
|
224
|
+
tenantId: "Tenant-ID",
|
|
225
|
+
tenantMissing: "Fehlende Berechtigungen: Skript erneut ausführen",
|
|
226
|
+
tenantSignIn: "Mit Microsoft verbinden",
|
|
227
|
+
tenantOrScript: "Oder mit dem Einrichtungsskript",
|
|
228
|
+
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.",
|
|
229
|
+
tenantShowScript: "Skript anzeigen",
|
|
230
|
+
tenantCode: "Verbindungscode",
|
|
231
|
+
tenantCodeHelp: "Das Skript gibt eine Zeile aus, die mit SCALIO1 beginnt. Fügen Sie die ganze Zeile ein.",
|
|
232
|
+
tenantConnect: "Verbinden",
|
|
233
|
+
tenantDone: "Verbunden: {app} liest diesen Tenant.",
|
|
234
|
+
tenantCheck: "Verbindung prüfen",
|
|
235
|
+
tenantLater: "Sie können den Tenant auch später in den Einstellungen verbinden.",
|
|
236
|
+
copy: "Kopieren",
|
|
237
|
+
download: "Herunterladen",
|
|
195
238
|
// Two-factor card (SecurityFactors) and license panel (LicensePanel)
|
|
196
239
|
users: {
|
|
197
240
|
loading: "Wird geladen …",
|
|
@@ -550,6 +593,26 @@ const LABELS = {
|
|
|
550
593
|
microsoft: "Sign in with Microsoft",
|
|
551
594
|
redirecting: "Redirecting …",
|
|
552
595
|
orEmail: "or with email",
|
|
596
|
+
setup: {
|
|
597
|
+
eyebrow: "First-run setup",
|
|
598
|
+
title: "Create the first administrator",
|
|
599
|
+
subtitle: "No account exists yet. This account gets full admin rights.",
|
|
600
|
+
code: "Setup code",
|
|
601
|
+
codeFromPortal: "You find the setup code in the customer portal at your instance.",
|
|
602
|
+
codeFromLog: "The backend writes it to its log at every start (docker logs), or it is the value of SETUP_CODE.",
|
|
603
|
+
microsoftHint: "You become the first administrator. Only people of your Microsoft organisation can sign in afterwards.",
|
|
604
|
+
microsoftOff: "Sign-in with Microsoft is not set up on this instance yet (Scalio ID).",
|
|
605
|
+
orLocal: "or create a local administrator",
|
|
606
|
+
name: "Name",
|
|
607
|
+
email: "Email",
|
|
608
|
+
password: "Password",
|
|
609
|
+
minLength: "At least {n} characters.",
|
|
610
|
+
confirm: "Confirm password",
|
|
611
|
+
submit: "Create administrator",
|
|
612
|
+
creating: "Creating …",
|
|
613
|
+
mismatch: "The passwords do not match.",
|
|
614
|
+
failed: "The setup failed.",
|
|
615
|
+
},
|
|
553
616
|
email: "Email",
|
|
554
617
|
password: "Password",
|
|
555
618
|
forgotPassword: "Forgot password?",
|
|
@@ -707,6 +770,27 @@ const LABELS = {
|
|
|
707
770
|
beaconChecked: "Connection works (Beacon {version}).",
|
|
708
771
|
beaconCheckFailed: "No connection: {detail}",
|
|
709
772
|
beaconRemoveConfirm: "Disconnect from Beacon? Findings no longer go to Beacon; the tickets there stay.",
|
|
773
|
+
beaconSuggested: "Scalio Beacon runs for your organisation at {url}. Connect this installation with one click, without a pairing code.",
|
|
774
|
+
beaconSuggestConnect: "Connect with Beacon",
|
|
775
|
+
tenantTitle: "Microsoft tenant",
|
|
776
|
+
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.",
|
|
777
|
+
tenantConnected: "Connected",
|
|
778
|
+
tenantNotConnected: "Not connected yet",
|
|
779
|
+
tenantOrganization: "Organisation",
|
|
780
|
+
tenantId: "Tenant ID",
|
|
781
|
+
tenantMissing: "Missing permissions: run the script again",
|
|
782
|
+
tenantSignIn: "Connect with Microsoft",
|
|
783
|
+
tenantOrScript: "Or with the setup script",
|
|
784
|
+
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.",
|
|
785
|
+
tenantShowScript: "Show script",
|
|
786
|
+
tenantCode: "Connection code",
|
|
787
|
+
tenantCodeHelp: "The script prints a line that starts with SCALIO1. Paste the whole line.",
|
|
788
|
+
tenantConnect: "Connect",
|
|
789
|
+
tenantDone: "Connected: {app} reads this tenant.",
|
|
790
|
+
tenantCheck: "Check connection",
|
|
791
|
+
tenantLater: "You can also connect the tenant later in the settings.",
|
|
792
|
+
copy: "Copy",
|
|
793
|
+
download: "Download",
|
|
710
794
|
users: {
|
|
711
795
|
loading: "Loading …",
|
|
712
796
|
search: "Search users",
|
|
@@ -1051,6 +1135,7 @@ function labelsFor(lang, overrides) {
|
|
|
1051
1135
|
passwordPolicy: Object.assign({}, base.passwordPolicy, o.passwordPolicy),
|
|
1052
1136
|
profile_: Object.assign({}, base.profile_, o.profile_),
|
|
1053
1137
|
wizard: Object.assign({}, base.wizard, o.wizard),
|
|
1138
|
+
setup: Object.assign({}, base.setup, o.setup),
|
|
1054
1139
|
backup: Object.assign({}, base.backup, o.backup),
|
|
1055
1140
|
});
|
|
1056
1141
|
}
|
package/react/setup.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// First-run setup «Ersten Administrator anlegen», the same form in every app (texts of Citadel, Beacon and Pulse,
|
|
3
|
+
// Markus 2026-11-06). Inside AuthLayout, in place of the sign-in form while the backend reports needsSetup.
|
|
4
|
+
// Order: header, setup code, «Mit Microsoft anmelden» (always shown; greyed with a hint while the instance has no
|
|
5
|
+
// Scalio ID), divider, local administrator (name, e-mail, password, confirm), submit.
|
|
6
|
+
// The app passes:
|
|
7
|
+
// microsoft true when sign-in with Microsoft is set up (setup-status «microsoft»)
|
|
8
|
+
// codeFrom "portal" (SaaS: code in the customer portal) or "log"
|
|
9
|
+
// onSubmit(form) {setupCode, name, email, password}; may return {ok:false, error} or throw
|
|
10
|
+
// onMicrosoft(code) starts the Microsoft sign-in (the app posts /auth/setup/microsoft and redirects)
|
|
11
|
+
// error an error from outside, e.g. ?sso_error after Microsoft
|
|
12
|
+
const React = require("react");
|
|
13
|
+
const h = React.createElement;
|
|
14
|
+
const { labelsFor } = require("./labels");
|
|
15
|
+
const { AuthHeader, AuthDivider, AuthMessage, MicrosoftButton } = require("./auth");
|
|
16
|
+
|
|
17
|
+
function errorText(err) {
|
|
18
|
+
const d = err && err.response && err.response.data && err.response.data.detail;
|
|
19
|
+
if (typeof d === "string") return d;
|
|
20
|
+
if (d && typeof d.message === "string") return d.message;
|
|
21
|
+
return (err && err.message) || String(err);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function Field({ id, label, hint, testId, ...input }) {
|
|
25
|
+
return h(
|
|
26
|
+
"div",
|
|
27
|
+
{ className: "scalio-setup-field" },
|
|
28
|
+
h("label", { className: "scalio-field-label", htmlFor: id }, label),
|
|
29
|
+
h("input", { id, className: "scalio-input", "data-testid": testId, ...input }),
|
|
30
|
+
hint ? h("p", { className: "scalio-auth-hint" }, hint) : null
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function FirstAdminSetup({ microsoft, codeFrom, onSubmit, onMicrosoft, error, lang, labels, minLength = 12 }) {
|
|
35
|
+
const L = labelsFor(lang, labels).setup;
|
|
36
|
+
const [code, setCode] = React.useState("");
|
|
37
|
+
const [name, setName] = React.useState("");
|
|
38
|
+
const [email, setEmail] = React.useState("");
|
|
39
|
+
const [password, setPassword] = React.useState("");
|
|
40
|
+
const [confirm, setConfirm] = React.useState("");
|
|
41
|
+
const [busy, setBusy] = React.useState("");
|
|
42
|
+
const [own, setOwn] = React.useState("");
|
|
43
|
+
|
|
44
|
+
const submit = async (e) => {
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
setOwn("");
|
|
47
|
+
if (password !== confirm) {
|
|
48
|
+
setOwn(L.mismatch);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
setBusy("form");
|
|
52
|
+
try {
|
|
53
|
+
const res = await onSubmit({ setupCode: code.trim(), name: name.trim(), email: email.trim(), password });
|
|
54
|
+
if (res && res.ok === false) setOwn(res.error || L.failed);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
setOwn(errorText(err));
|
|
57
|
+
} finally {
|
|
58
|
+
setBusy("");
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const viaMicrosoft = async () => {
|
|
62
|
+
setOwn("");
|
|
63
|
+
setBusy("microsoft");
|
|
64
|
+
try {
|
|
65
|
+
await onMicrosoft(code.trim());
|
|
66
|
+
} catch (err) {
|
|
67
|
+
setOwn(errorText(err));
|
|
68
|
+
setBusy("");
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return h(
|
|
73
|
+
"form",
|
|
74
|
+
{ className: "scalio-setup", onSubmit: submit, "data-testid": "login-form" },
|
|
75
|
+
h(AuthHeader, { eyebrow: L.eyebrow, title: L.title, subtitle: L.subtitle, testId: "setup-header" }),
|
|
76
|
+
h(Field, { id: "setup-code", label: L.code, testId: "setup-code-input", value: code, required: true, autoComplete: "off",
|
|
77
|
+
onChange: (e) => setCode(e.target.value), style: { fontFamily: "'JetBrains Mono', monospace", letterSpacing: "0.1em" },
|
|
78
|
+
hint: codeFrom === "portal" ? L.codeFromPortal : L.codeFromLog }),
|
|
79
|
+
h(MicrosoftButton, {
|
|
80
|
+
onClick: microsoft ? viaMicrosoft : undefined,
|
|
81
|
+
busy: busy === "microsoft",
|
|
82
|
+
disabled: !microsoft || !!busy || !code.trim(),
|
|
83
|
+
hint: microsoft ? L.microsoftHint : L.microsoftOff,
|
|
84
|
+
lang, labels, testId: "setup-microsoft-btn",
|
|
85
|
+
}),
|
|
86
|
+
h(AuthDivider, { label: L.orLocal, testId: "setup-divider" }),
|
|
87
|
+
h(Field, { id: "setup-name", label: L.name, testId: "setup-name-input", value: name, required: true, autoComplete: "name",
|
|
88
|
+
onChange: (e) => setName(e.target.value) }),
|
|
89
|
+
h(Field, { id: "login-email", label: L.email, testId: "login-email-input", type: "email", value: email, required: true,
|
|
90
|
+
autoComplete: "username", onChange: (e) => setEmail(e.target.value) }),
|
|
91
|
+
h(Field, { id: "login-password", label: L.password, testId: "login-password-input", type: "password", value: password,
|
|
92
|
+
required: true, minLength, autoComplete: "new-password", onChange: (e) => setPassword(e.target.value),
|
|
93
|
+
hint: L.minLength.replace("{n}", String(minLength)) }),
|
|
94
|
+
h(Field, { id: "setup-confirm", label: L.confirm, testId: "setup-confirm-input", type: "password", value: confirm,
|
|
95
|
+
required: true, autoComplete: "new-password", onChange: (e) => setConfirm(e.target.value) }),
|
|
96
|
+
h(AuthMessage, { kind: "error", testId: "login-error" }, own || error || null),
|
|
97
|
+
h("button", { type: "submit", className: "scalio-btn-primary scalio-setup-submit", disabled: !!busy,
|
|
98
|
+
"data-testid": "login-submit-button" }, busy === "form" ? L.creating : L.submit)
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = { FirstAdminSetup };
|
package/react/tenant.js
ADDED
|
@@ -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 };
|