@scalio-cloud/ui 0.44.1 → 0.46.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 +8 -0
- package/package.json +1 -1
- package/react/auth.js +40 -2
- package/react/clientErrors.js +61 -0
- package/react/index.js +1 -1
package/README.md
CHANGED
|
@@ -104,6 +104,19 @@ export const { AuthProvider, useAuth } = createAuth({ api, formatError: formatAp
|
|
|
104
104
|
passkeyCancelled, legacyTokenKey: "pulse_token" });
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
+
## Browser-Fehler an Scalio Monitor (React-frei, from 0.45.0)
|
|
108
|
+
|
|
109
|
+
`reportClientErrors({ post, max })` hört auf `error` und `unhandledrejection` des Fensters und schickt jeden Fehler
|
|
110
|
+
einmal (höchstens `max`, Standard 10 pro Seitenaufruf) über das eigene Backend: `POST /api/client-errors` aus
|
|
111
|
+
scalio-platform 0.23.0 (`error_report.client_errors_router(require_user)`), nie direkt an den Monitor. Gesendet
|
|
112
|
+
werden nur Typ, Meldung, Stack und der Pfad ohne Query und Hash; Fehler von Browser-Erweiterungen und der harmlose
|
|
113
|
+
ResizeObserver-Hinweis bleiben weg. Gibt eine Funktion zurück, die das Zuhören beendet.
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
import { reportClientErrors } from "@scalio-cloud/ui/react";
|
|
117
|
+
reportClientErrors({ post: (body) => api.post("/client-errors", body) }); // einmal in main.jsx
|
|
118
|
+
```
|
|
119
|
+
|
|
107
120
|
## App header (React)
|
|
108
121
|
|
|
109
122
|
Every app shows the same header on the right, always in this order: (app actions), status, language, theme,
|
|
@@ -302,6 +315,8 @@ import { AuthLayout, AuthHeader, MicrosoftButton, AuthDivider, AuthMessage, Prof
|
|
|
302
315
|
lang={lang} onLangChange={setLang} // top right
|
|
303
316
|
theme={theme} onThemeChange={setTheme} // optional
|
|
304
317
|
footer={<VersionTag version={v} />} // optional
|
|
318
|
+
// version: shown small bottom left in every app. Left out = read from /version.json (written by the
|
|
319
|
+
// frontend image), a string = that version, false = hidden.
|
|
305
320
|
>
|
|
306
321
|
<AuthHeader eyebrow="Zugang" title="Anmelden" subtitle="..." />
|
|
307
322
|
<MicrosoftButton href="/api/auth/sso/login" lang={lang} disabled={!ssoReady} hint="..." />
|
package/auth.css
CHANGED
|
@@ -53,6 +53,14 @@
|
|
|
53
53
|
font-family: 'JetBrains Mono', monospace; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/* App version bottom left: on the dark brand panel from 1024px, on the page below. */
|
|
57
|
+
.scalio-auth { position: relative; }
|
|
58
|
+
.scalio-auth-version {
|
|
59
|
+
position: absolute; left: 1rem; bottom: 0.75rem; z-index: 1; pointer-events: none;
|
|
60
|
+
color: #71717a; font-family: 'JetBrains Mono', monospace; font-size: 10px; letter-spacing: 0.08em;
|
|
61
|
+
}
|
|
62
|
+
@media (min-width: 1024px) { .scalio-auth-version { left: 3rem; bottom: 1rem; } }
|
|
63
|
+
|
|
56
64
|
.scalio-auth-main { position: relative; display: flex; flex-direction: column; min-width: 0; }
|
|
57
65
|
.scalio-auth-top { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 1rem; min-height: 4.25rem; }
|
|
58
66
|
.scalio-auth-body { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; padding: 0 1.5rem 2rem; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalio-cloud/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.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/auth.js
CHANGED
|
@@ -19,7 +19,44 @@ function BrandMark({ brand, className }) {
|
|
|
19
19
|
);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
// "1.4.0" -> "v1.4.0"; dev builds ("dev-1a2b3c4") and other names stay as they are.
|
|
23
|
+
function formatVersion(v) {
|
|
24
|
+
const s = String(v || "").trim();
|
|
25
|
+
return /^\d/.test(s) ? `v${s}` : s;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Reads the build of this frontend from /version.json ({version, commit, build_date}, written by every
|
|
29
|
+
// app's frontend image). Gives "" while loading or when the file is missing (local vite run).
|
|
30
|
+
function useAppVersion(given, url) {
|
|
31
|
+
const [v, setV] = React.useState(typeof given === "string" ? given : "");
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
if (typeof given === "string") { setV(given); return undefined; }
|
|
34
|
+
if (given === false || typeof fetch !== "function") return undefined;
|
|
35
|
+
let alive = true;
|
|
36
|
+
fetch(url || "/version.json", { cache: "no-store" })
|
|
37
|
+
.then((r) => (r.ok ? r.json() : null))
|
|
38
|
+
.then((d) => { if (alive && d && d.version) setV(String(d.version)); })
|
|
39
|
+
.catch(() => {});
|
|
40
|
+
return () => { alive = false; };
|
|
41
|
+
}, [given, url]);
|
|
42
|
+
return v;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Small version bottom left of the sign-in page. version: a string, false (hidden), or left out
|
|
46
|
+
// (read from /version.json).
|
|
47
|
+
function AppVersion({ version, url, lang, labels, className, testId }) {
|
|
48
|
+
const L = labelsFor(lang, labels);
|
|
49
|
+
const v = useAppVersion(version, url);
|
|
50
|
+
if (!v) return null;
|
|
51
|
+
return h(
|
|
52
|
+
"div",
|
|
53
|
+
{ className: cx("scalio-auth-version", className), title: `${L.version} ${v}`, "data-testid": testId || "auth-version" },
|
|
54
|
+
formatVersion(v)
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
22
58
|
// brand: { mark: "N", name: "Scalio Nexus", claim, eyebrow, features: [..], color }
|
|
59
|
+
// version: shown small bottom left; left out = read from /version.json, false = hidden.
|
|
23
60
|
function AuthLayout(props) {
|
|
24
61
|
const brand = props.brand || {};
|
|
25
62
|
const L = labelsFor(props.lang, props.labels);
|
|
@@ -73,7 +110,8 @@ function AuthLayout(props) {
|
|
|
73
110
|
)
|
|
74
111
|
),
|
|
75
112
|
props.footer ? h("div", { className: "scalio-auth-footer", "aria-label": L.version }, props.footer) : null
|
|
76
|
-
)
|
|
113
|
+
),
|
|
114
|
+
h(AppVersion, { version: props.version, url: props.versionUrl, lang: props.lang, labels: props.labels })
|
|
77
115
|
);
|
|
78
116
|
}
|
|
79
117
|
|
|
@@ -155,4 +193,4 @@ function ProfileSection({ id, title, description, lang, labels, children, testId
|
|
|
155
193
|
);
|
|
156
194
|
}
|
|
157
195
|
|
|
158
|
-
module.exports = { AuthLayout, AuthHeader, AuthDivider, AuthMessage, MicrosoftButton, MicrosoftLogo, ProfileSection, PROFILE_SECTIONS };
|
|
196
|
+
module.exports = { AuthLayout, AppVersion, formatVersion, AuthHeader, AuthDivider, AuthMessage, MicrosoftButton, MicrosoftLogo, ProfileSection, PROFILE_SECTIONS };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Browser errors to Scalio Monitor through the app's own backend (scalio-platform 0.23.0
|
|
3
|
+
// error_report.client_errors_router, POST /api/client-errors; never straight to the monitor, concept monitoring.md).
|
|
4
|
+
// reportClientErrors({ post, max }) listens to window "error" and "unhandledrejection" and returns a function that
|
|
5
|
+
// stops it. post(body) is the app's call, e.g. (b) => api.post("/client-errors", b). Sent: type, message, stack
|
|
6
|
+
// and the page path (no query, no hash). Each error once per page load, at most `max` (10) in all; errors of
|
|
7
|
+
// browser extensions and the harmless ResizeObserver notice are left out. A failing post is ignored.
|
|
8
|
+
const NOISE = [/ResizeObserver loop/i, /^Script error\.?$/i];
|
|
9
|
+
const EXTENSION = /(chrome|moz|safari(-web)?)-extension:\/\//i;
|
|
10
|
+
|
|
11
|
+
function describe(reason) {
|
|
12
|
+
if (reason && typeof reason === "object") {
|
|
13
|
+
return {
|
|
14
|
+
type: String(reason.name || (reason.constructor && reason.constructor.name) || "Error").slice(0, 120),
|
|
15
|
+
message: String(reason.message || "").slice(0, 1000),
|
|
16
|
+
stack: String(reason.stack || "").slice(0, 4000),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return { type: "Error", message: String(reason == null ? "" : reason).slice(0, 1000), stack: "" };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function clientErrorBody(reason, win) {
|
|
23
|
+
const body = describe(reason);
|
|
24
|
+
const loc = (win && win.location) || {};
|
|
25
|
+
body.path = String(loc.pathname || "").slice(0, 300);
|
|
26
|
+
return body;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function reportClientErrors(opts) {
|
|
30
|
+
const o = opts || {};
|
|
31
|
+
const win = o.window || (typeof window !== "undefined" ? window : null);
|
|
32
|
+
if (!win || typeof o.post !== "function") return () => {};
|
|
33
|
+
const max = o.max || 10;
|
|
34
|
+
const seen = new Set();
|
|
35
|
+
let sent = 0;
|
|
36
|
+
|
|
37
|
+
const send = (reason) => {
|
|
38
|
+
const body = clientErrorBody(reason, win);
|
|
39
|
+
if (!body.message && !body.stack) return;
|
|
40
|
+
if (NOISE.some((re) => re.test(body.message)) || EXTENSION.test(body.stack)) return;
|
|
41
|
+
const key = `${body.type}|${body.message}`;
|
|
42
|
+
if (seen.has(key) || sent >= max) return;
|
|
43
|
+
seen.add(key);
|
|
44
|
+
sent += 1;
|
|
45
|
+
try {
|
|
46
|
+
Promise.resolve(o.post(body)).catch(() => {});
|
|
47
|
+
} catch (e) {
|
|
48
|
+
/* reporting never breaks the page */
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const onError = (ev) => send(ev && (ev.error || ev.message));
|
|
52
|
+
const onRejection = (ev) => send(ev && ev.reason);
|
|
53
|
+
win.addEventListener("error", onError);
|
|
54
|
+
win.addEventListener("unhandledrejection", onRejection);
|
|
55
|
+
return () => {
|
|
56
|
+
win.removeEventListener("error", onError);
|
|
57
|
+
win.removeEventListener("unhandledrejection", onRejection);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = { reportClientErrors, clientErrorBody };
|
package/react/index.js
CHANGED
|
@@ -380,4 +380,4 @@ module.exports = {
|
|
|
380
380
|
};
|
|
381
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"), require("./fields"));
|
|
382
382
|
// After the exports above: auth.js uses LanguageToggle and ThemeToggle from this module.
|
|
383
|
-
Object.assign(module.exports, require("./auth"), require("./session"), require("./setup"));
|
|
383
|
+
Object.assign(module.exports, require("./auth"), require("./session"), require("./setup"), require("./clientErrors"));
|