@scalio-cloud/ui 0.44.0 → 0.45.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
@@ -83,7 +83,8 @@ server {
83
83
 
84
84
  Both lists empty: no limit (both files stay empty). An address passes if it is in the IP list or its country is
85
85
  allowed. An invalid entry closes the instance for everyone except the machine paths and names the entry in the log
86
- (fail closed). Countries set but no database: only the IP list counts, the log says so. For countries the image needs
86
+ (fail closed). Countries set but no database or the geoip2 module not loaded (`load_module` in `nginx.conf` or
87
+ `modules/*.conf`): only the IP list counts, nginx still starts and the log says why. For countries the image needs
87
88
  `ngx_http_geoip2_module` and the free DB-IP «IP to Country Lite» database (CC BY 4.0: show «IP Geolocation by DB-IP»
88
89
  on the about page). Tests (`test/access.test.js`) run with real nginx when it is installed.
89
90
 
@@ -103,6 +104,19 @@ export const { AuthProvider, useAuth } = createAuth({ api, formatError: formatAp
103
104
  passkeyCancelled, legacyTokenKey: "pulse_token" });
104
105
  ```
105
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
+
106
120
  ## App header (React)
107
121
 
108
122
  Every app shows the same header on the right, always in this order: (app actions), status, language, theme,
@@ -4,7 +4,8 @@
4
4
  # official nginx image runs it before nginx starts) and machine-paths.txt next to it.
5
5
  #
6
6
  # ALLOWED_CLIENT_IPS CIDR list, comma separated ("203.0.113.0/24, 2001:db8::/48"); empty = no limit
7
- # ALLOWED_COUNTRIES ISO country codes, comma separated ("CH,DE,AT"); needs the geoip2 module and SCALIO_GEOIP_DB
7
+ # ALLOWED_COUNTRIES ISO country codes, comma separated ("CH,DE,AT"); needs SCALIO_GEOIP_DB and the geoip2 module
8
+ # loaded in nginx.conf (load_module, or modules/*.conf as in the Alpine package)
8
9
  # TRUSTED_PROXIES CIDR list of the proxy in front (Caddy network, Azure ingress); its X-Forwarded-For counts
9
10
  # SCALIO_APP nexus, citadel, … : picks the app's machine paths (machine-paths.txt)
10
11
  # SCALIO_GEOIP_DB country database (DB-IP «IP to Country Lite», mmdb); default /etc/nginx/geoip/dbip-country.mmdb
@@ -12,7 +13,8 @@
12
13
  # Allowed is who is in the IP list OR in an allowed country; machine paths stay open. Everyone else gets 403 with a
13
14
  # short page that names the address (and the country), so the customer can add it in Scalio Compass.
14
15
  # Both variables empty: the two files are written empty and nothing changes.
15
- # A wrong entry or countries without database: fail closed (only machine paths open) and say why in the log.
16
+ # A wrong entry: fail closed (only machine paths open) and say why in the log. Countries without database or
17
+ # without the geoip2 module: only the IP list counts (nginx still starts) and the log says why.
16
18
  set -eu
17
19
 
18
20
  DIR="${SCALIO_ACCESS_DIR:-/etc/nginx}"
@@ -21,6 +23,7 @@ SERVER_CONF="${SCALIO_ACCESS_SERVER:-$DIR/snippets/scalio-access.conf}"
21
23
  PATHS_FILE="${SCALIO_MACHINE_PATHS_FILE:-$(dirname "$0")/machine-paths.txt}"
22
24
  [ -f "$PATHS_FILE" ] || PATHS_FILE="$DIR/snippets/machine-paths.txt"
23
25
  GEOIP_DB="${SCALIO_GEOIP_DB:-$DIR/geoip/dbip-country.mmdb}"
26
+ NGINX_CONF="${SCALIO_NGINX_CONF:-$DIR/nginx.conf}"
24
27
  APP="${SCALIO_APP:-}"
25
28
 
26
29
  log() { echo "scalio-access: $*" >&2; }
@@ -66,6 +69,11 @@ geo_ok=1
66
69
  if [ -n "$COUNTRIES" ] && [ ! -r "$GEOIP_DB" ]; then
67
70
  geo_ok=0
68
71
  log "ALLOWED_COUNTRIES set, but no country database at $GEOIP_DB: only the IP list counts"
72
+ elif [ -n "$COUNTRIES" ] && ! cat "$NGINX_CONF" "$DIR"/modules/*.conf "$DIR"/modules-enabled/*.conf 2>/dev/null \
73
+ | grep -v '^[[:space:]]*#' | grep -q 'ngx_http_geoip2_module'; then
74
+ # Without load_module nginx would refuse the geoip2 block and not start at all.
75
+ geo_ok=0
76
+ log "ALLOWED_COUNTRIES set, but the geoip2 module is not loaded ($NGINX_CONF): only the IP list counts"
69
77
  fi
70
78
  if [ -n "$broken" ]; then
71
79
  log "invalid entries:$broken -> access closed for everyone except the machine paths"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalio-cloud/ui",
3
- "version": "0.44.0",
3
+ "version": "0.45.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,
@@ -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"));