@scalio-cloud/ui 0.42.0 → 0.44.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 +64 -0
- package/auth.css +6 -0
- package/nginx/access-limit.sh +128 -0
- package/nginx/machine-paths.txt +10 -0
- package/package.json +1 -1
- package/react/fields.js +486 -0
- package/react/index.js +2 -2
- package/react/labels.js +42 -0
- package/react/setup.js +102 -0
package/README.md
CHANGED
|
@@ -54,6 +54,39 @@ COPY --from=build /app/node_modules/@scalio-cloud/ui/nginx/security-headers.conf
|
|
|
54
54
|
include /etc/nginx/snippets/security-headers.conf;
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
## Access limit by IP and country for nginx (from 0.44.0)
|
|
58
|
+
|
|
59
|
+
`nginx/access-limit.sh` limits who may open an instance (ADR 0085, zugang/Z1). The official nginx image runs it at
|
|
60
|
+
start (`/docker-entrypoint.d/`); it reads the environment and writes two nginx files. Machine paths
|
|
61
|
+
(`nginx/machine-paths.txt`: health, version, provisioning, agent, webhooks) stay open, so Compass, Scalio Monitor and
|
|
62
|
+
the agent keep working. A blocked person sees a page in German and English with their address.
|
|
63
|
+
|
|
64
|
+
```dockerfile
|
|
65
|
+
COPY --from=build /app/node_modules/@scalio-cloud/ui/nginx/access-limit.sh /docker-entrypoint.d/30-scalio-access.sh
|
|
66
|
+
COPY --from=build /app/node_modules/@scalio-cloud/ui/nginx/machine-paths.txt /etc/nginx/snippets/
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
```nginx
|
|
70
|
+
server {
|
|
71
|
+
include /etc/nginx/snippets/scalio-access.conf;
|
|
72
|
+
...
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
| Variable | Meaning |
|
|
77
|
+
|---|---|
|
|
78
|
+
| `ALLOWED_CLIENT_IPS` | Addresses and networks, comma separated (`198.51.100.7, 203.0.113.0/24, 2001:db8::/32`) |
|
|
79
|
+
| `ALLOWED_COUNTRIES` | ISO country codes (`CH, LI, DE`); needs the geoip2 module and a country database |
|
|
80
|
+
| `TRUSTED_PROXIES` | Proxies whose `X-Forwarded-For` counts (Caddy, Azure front end); the last entry is used |
|
|
81
|
+
| `SCALIO_APP` | App name (`nexus`, …) for the app-specific machine paths |
|
|
82
|
+
| `SCALIO_GEOIP_DB` | Country database, default `/etc/nginx/geoip/dbip-country.mmdb` |
|
|
83
|
+
|
|
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
|
+
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
|
|
87
|
+
`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
|
+
on the about page). Tests (`test/access.test.js`) run with real nginx when it is installed.
|
|
89
|
+
|
|
57
90
|
## Sign-in state (React, from 0.37.0)
|
|
58
91
|
|
|
59
92
|
`createAuth({ api, formatError, signInWithPasskey, passkeyCancelled, legacyTokenKey })` gives `{ AuthProvider,
|
|
@@ -163,6 +196,14 @@ app passes its own routes as `client`: `status()` (`{connected, organization, az
|
|
|
163
196
|
`link()` (`{url}`), `script()` (`{script}`), `redeem(code)` and optionally `check()`. An app with a tenant list
|
|
164
197
|
creates its default tenant itself in these calls. `onChange(status)` runs after every action.
|
|
165
198
|
|
|
199
|
+
`<FirstAdminSetup microsoft={...} codeFrom="portal" onSubmit={...} onMicrosoft={...} lang={lang} />` is the first-run
|
|
200
|
+
form «Ersten Administrator anlegen» inside `AuthLayout`, with the same texts in every app (Citadel, Beacon and Pulse
|
|
201
|
+
are the reference). «Mit Microsoft anmelden» is always there: greyed with a hint while the instance has no Scalio ID
|
|
202
|
+
(`microsoft` false), else it calls `onMicrosoft(setupCode)` (the app posts `/auth/setup/microsoft` and redirects).
|
|
203
|
+
`onSubmit({setupCode, name, email, password})` may return `{ok: false, error}` or throw; `error` shows an error from
|
|
204
|
+
outside (e.g. `?sso_error`). Test ids as before: `setup-code-input`, `setup-name-input`, `login-email-input`,
|
|
205
|
+
`login-password-input`, `setup-confirm-input`, `login-submit-button`, `setup-microsoft-btn`.
|
|
206
|
+
|
|
166
207
|
`link` is the router's `NavLink` (it gets `to`, `end`, a `className` function and `onClick`); without it the
|
|
167
208
|
sidebar renders plain links and marks the item for `activePath`. Item test ids default to `nav-<path>`
|
|
168
209
|
(`nav-overview` for `/`), or set `testId`. Page blocks: `KpiTile` (tone `error` = red number),
|
|
@@ -555,6 +596,29 @@ The package holds only design values and fonts under the SIL OFL, nothing confid
|
|
|
555
596
|
Design tokens and preset: (c) Scalio Cloud LLC, free to use in Scalio apps. Fonts: SIL Open Font License 1.1,
|
|
556
597
|
see `fonts/licenses/`. Icons in `react/icons.js`: Lucide, ISC license, see `licenses/lucide-LICENSE.txt`.
|
|
557
598
|
|
|
599
|
+
## Eingabefelder prüfen: `Input` (React, from 0.44.0)
|
|
600
|
+
|
|
601
|
+
Taken over from Scalio Kontor, so every app checks fields the same way. `<Input check="…">` is the native
|
|
602
|
+
`<input>` with checks: only allowed characters are taken, the value is tidied up when the field is left
|
|
603
|
+
(`1'250,50` → `1250.50`, IBAN in groups of four, UID `CHE-123.456.788`), a clear German or English message shows
|
|
604
|
+
under the field after leaving it, and the form cannot be sent (`setCustomValidity`) until the value is right.
|
|
605
|
+
|
|
606
|
+
Checks: `text`, `amount`, `signedAmount`, `quantity`, `percent`, `rate`, `integer`, `date`, `email`, `emails`,
|
|
607
|
+
`phone`, `url`, `iban`, `qrIban`, `zip`, `uid`, `vat`, `country`, `account`, `reference` (QR reference or RF…), `bic`.
|
|
608
|
+
`country` (e.g. `"CH"`) makes zip, UID and MWST number strict; `lang` defaults to `<html lang>`.
|
|
609
|
+
|
|
610
|
+
```jsx
|
|
611
|
+
import { Input, validNear, fieldProblem, fieldProblemText } from "@scalio-cloud/ui/react";
|
|
612
|
+
|
|
613
|
+
<Input check="iban" value={iban} onChange={(e) => setIban(e.target.value)} required testId="iban" />
|
|
614
|
+
<Input check="zip" country={address.country} value={zip} onChange={...} />
|
|
615
|
+
<button onClick={(e) => validNear(e.currentTarget) && save()}>Speichern</button> // outside a <form>
|
|
616
|
+
fieldProblemText(fieldProblem("uid", value, { country: "CH" }), lang) // same rule without a field
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
The backend checks the same rules again; the pure functions (`fieldProblem`, `normalizeField`, `validIban`,
|
|
620
|
+
`formatUid`, …) work without React.
|
|
621
|
+
|
|
558
622
|
## Release
|
|
559
623
|
|
|
560
624
|
1. Change the files and bump `version` in `package.json` (semver; tag without `v`).
|
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); }
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Scalio access limit for the frontend nginx of every app (scalio-docs ADR 0085, zugang/Z1, Z6, Z7).
|
|
3
|
+
# Shipped in @scalio-cloud/ui. The app's Dockerfile copies it to /docker-entrypoint.d/30-scalio-access.sh (the
|
|
4
|
+
# official nginx image runs it before nginx starts) and machine-paths.txt next to it.
|
|
5
|
+
#
|
|
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
|
|
8
|
+
# TRUSTED_PROXIES CIDR list of the proxy in front (Caddy network, Azure ingress); its X-Forwarded-For counts
|
|
9
|
+
# SCALIO_APP nexus, citadel, … : picks the app's machine paths (machine-paths.txt)
|
|
10
|
+
# SCALIO_GEOIP_DB country database (DB-IP «IP to Country Lite», mmdb); default /etc/nginx/geoip/dbip-country.mmdb
|
|
11
|
+
#
|
|
12
|
+
# Allowed is who is in the IP list OR in an allowed country; machine paths stay open. Everyone else gets 403 with a
|
|
13
|
+
# short page that names the address (and the country), so the customer can add it in Scalio Compass.
|
|
14
|
+
# 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
|
+
set -eu
|
|
17
|
+
|
|
18
|
+
DIR="${SCALIO_ACCESS_DIR:-/etc/nginx}"
|
|
19
|
+
HTTP_CONF="${SCALIO_ACCESS_HTTP:-$DIR/conf.d/00-scalio-access.conf}"
|
|
20
|
+
SERVER_CONF="${SCALIO_ACCESS_SERVER:-$DIR/snippets/scalio-access.conf}"
|
|
21
|
+
PATHS_FILE="${SCALIO_MACHINE_PATHS_FILE:-$(dirname "$0")/machine-paths.txt}"
|
|
22
|
+
[ -f "$PATHS_FILE" ] || PATHS_FILE="$DIR/snippets/machine-paths.txt"
|
|
23
|
+
GEOIP_DB="${SCALIO_GEOIP_DB:-$DIR/geoip/dbip-country.mmdb}"
|
|
24
|
+
APP="${SCALIO_APP:-}"
|
|
25
|
+
|
|
26
|
+
log() { echo "scalio-access: $*" >&2; }
|
|
27
|
+
|
|
28
|
+
# "a, b ,c" -> "a b c"
|
|
29
|
+
words() { echo "${1:-}" | tr ',;' ' ' | tr -s ' \t\n' ' ' | sed 's/^ //; s/ $//'; }
|
|
30
|
+
|
|
31
|
+
valid_cidr() {
|
|
32
|
+
case "$1" in
|
|
33
|
+
*[!0-9a-fA-F:./]*|"") return 1 ;;
|
|
34
|
+
esac
|
|
35
|
+
ip="${1%/*}"; bits=""
|
|
36
|
+
[ "$ip" != "$1" ] && bits="${1#*/}"
|
|
37
|
+
case "$ip" in
|
|
38
|
+
*:*) max=128; echo "$ip" | grep -Eq '^[0-9a-fA-F:]+(\.[0-9.]+)?$' || return 1 ;;
|
|
39
|
+
*) max=32
|
|
40
|
+
echo "$ip" | grep -Eq '^([0-9]{1,3}\.){3}[0-9]{1,3}$' || return 1
|
|
41
|
+
for o in $(echo "$ip" | tr '.' ' '); do [ "$o" -le 255 ] || return 1; done ;;
|
|
42
|
+
esac
|
|
43
|
+
if [ -n "$bits" ]; then
|
|
44
|
+
echo "$bits" | grep -Eq '^[0-9]{1,3}$' || return 1
|
|
45
|
+
[ "$bits" -le "$max" ] || return 1
|
|
46
|
+
fi
|
|
47
|
+
return 0
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
IPS=$(words "${ALLOWED_CLIENT_IPS:-}")
|
|
51
|
+
COUNTRIES=$(words "${ALLOWED_COUNTRIES:-}" | tr 'a-z' 'A-Z')
|
|
52
|
+
PROXIES=$(words "${TRUSTED_PROXIES:-}")
|
|
53
|
+
mkdir -p "$(dirname "$HTTP_CONF")" "$(dirname "$SERVER_CONF")"
|
|
54
|
+
|
|
55
|
+
if [ -z "$IPS" ] && [ -z "$COUNTRIES" ]; then
|
|
56
|
+
: > "$HTTP_CONF"
|
|
57
|
+
: > "$SERVER_CONF"
|
|
58
|
+
log "no access limit (ALLOWED_CLIENT_IPS and ALLOWED_COUNTRIES empty)"
|
|
59
|
+
exit 0
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
broken=""
|
|
63
|
+
for c in $IPS $PROXIES; do valid_cidr "$c" || broken="$broken $c"; done
|
|
64
|
+
for c in $COUNTRIES; do echo "$c" | grep -Eq '^[A-Z]{2}$' || broken="$broken $c"; done
|
|
65
|
+
geo_ok=1
|
|
66
|
+
if [ -n "$COUNTRIES" ] && [ ! -r "$GEOIP_DB" ]; then
|
|
67
|
+
geo_ok=0
|
|
68
|
+
log "ALLOWED_COUNTRIES set, but no country database at $GEOIP_DB: only the IP list counts"
|
|
69
|
+
fi
|
|
70
|
+
if [ -n "$broken" ]; then
|
|
71
|
+
log "invalid entries:$broken -> access closed for everyone except the machine paths"
|
|
72
|
+
IPS=""; COUNTRIES=""
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
{
|
|
76
|
+
echo "# Written by scalio-access (@scalio-cloud/ui nginx/access-limit.sh) at container start. Do not edit."
|
|
77
|
+
if [ -n "$PROXIES" ]; then
|
|
78
|
+
for p in $PROXIES; do echo "set_real_ip_from $p;"; done
|
|
79
|
+
echo "real_ip_header X-Forwarded-For;"
|
|
80
|
+
echo "real_ip_recursive off;"
|
|
81
|
+
fi
|
|
82
|
+
echo "geo \$scalio_ip_allowed {"
|
|
83
|
+
echo " default 0;"
|
|
84
|
+
for c in $IPS; do echo " $c 1;"; done
|
|
85
|
+
echo "}"
|
|
86
|
+
if [ -n "$COUNTRIES" ] && [ "$geo_ok" = 1 ]; then
|
|
87
|
+
echo "geoip2 $GEOIP_DB {"
|
|
88
|
+
echo " \$scalio_country country iso_code;"
|
|
89
|
+
echo "}"
|
|
90
|
+
echo "map \$scalio_country \$scalio_country_allowed {"
|
|
91
|
+
echo " default 0;"
|
|
92
|
+
for c in $COUNTRIES; do echo " $c 1;"; done
|
|
93
|
+
echo "}"
|
|
94
|
+
else
|
|
95
|
+
echo "map \$remote_addr \$scalio_country { default \"\"; }"
|
|
96
|
+
echo "map \$remote_addr \$scalio_country_allowed { default 0; }"
|
|
97
|
+
fi
|
|
98
|
+
echo "map \$uri \$scalio_machine_path {"
|
|
99
|
+
echo " default 0;"
|
|
100
|
+
grep -v '^[[:space:]]*#' "$PATHS_FILE" | while read -r app path; do
|
|
101
|
+
[ -n "${path:-}" ] || continue
|
|
102
|
+
if [ "$app" = "*" ] || [ "$app" = "$APP" ]; then
|
|
103
|
+
case "$path" in
|
|
104
|
+
*/) echo " ~^$(echo "$path" | sed 's/[.]/\\./g') 1;" ;;
|
|
105
|
+
*) echo " $path 1;"; echo " ~^$(echo "$path" | sed 's/[.]/\\./g')/ 1;" ;;
|
|
106
|
+
esac
|
|
107
|
+
fi
|
|
108
|
+
done
|
|
109
|
+
echo "}"
|
|
110
|
+
echo "map \"\$scalio_ip_allowed\$scalio_country_allowed\$scalio_machine_path\" \$scalio_access_denied {"
|
|
111
|
+
echo " default 0;"
|
|
112
|
+
echo " 000 1;"
|
|
113
|
+
echo "}"
|
|
114
|
+
} > "$HTTP_CONF"
|
|
115
|
+
|
|
116
|
+
cat > "$SERVER_CONF" <<'CONF'
|
|
117
|
+
# Written by scalio-access (@scalio-cloud/ui nginx/access-limit.sh). Include it in the app's server block.
|
|
118
|
+
error_page 403 @scalio_access_denied;
|
|
119
|
+
if ($scalio_access_denied) {
|
|
120
|
+
return 403;
|
|
121
|
+
}
|
|
122
|
+
location @scalio_access_denied {
|
|
123
|
+
default_type "text/html; charset=utf-8";
|
|
124
|
+
add_header Cache-Control "no-store" always;
|
|
125
|
+
return 200 '<!doctype html><html lang="de"><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Zugriff nicht freigegeben</title><body style="font-family:system-ui,sans-serif;max-width:36rem;margin:4rem auto;padding:0 1rem;line-height:1.5"><h1 style="font-size:1.4rem">Zugriff nicht freigegeben</h1><p>Der Zugriff von Ihrer Adresse <b>$remote_addr</b> $scalio_country ist für diese Instanz nicht freigegeben. Bitten Sie Ihre Administration, die Adresse in Scalio Compass unter «Zugriff eingrenzen» einzutragen.</p><p lang="en" style="color:#666">Access from your address <b>$remote_addr</b> $scalio_country is not allowed for this instance. Ask your administrator to add it in Scalio Compass under «Restrict access».</p></body></html>';
|
|
126
|
+
}
|
|
127
|
+
CONF
|
|
128
|
+
log "access limited: $(echo "$IPS" | wc -w | tr -d ' ') IP range(s), countries: ${COUNTRIES:-none}, trusted proxies: ${PROXIES:-none}"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Paths that stay open when a Scalio instance limits access by IP or country (scalio-docs ADR 0085, zugang/Z6).
|
|
2
|
+
# They carry no customer data or have their own protection (token, HMAC, signature). One line: <app> <path prefix>;
|
|
3
|
+
# app "*" = every app. Same list as MACHINE_PATHS in scalio-infra tests/test_internal_only.py (Dev/Test wall).
|
|
4
|
+
* /api/health
|
|
5
|
+
* /api/version
|
|
6
|
+
* /version.json
|
|
7
|
+
* /api/provision/
|
|
8
|
+
* /api/e2e/status
|
|
9
|
+
nexus /api/agent
|
|
10
|
+
nexus /api/webhook/hris/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalio-cloud/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.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/fields.js
ADDED
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Input checks for form fields, shared by all apps (taken over from Scalio Kontor, lib/validate.ts and lib/Input.tsx;
|
|
3
|
+
// Backlog «Prüf-Baustein für Eingabefelder»). What may be typed, how a value is tidied up when the field is left,
|
|
4
|
+
// and which message a wrong value gets, in German ("Sie") and English. Pure functions plus the component <Input>.
|
|
5
|
+
// The backend of an app checks the same rules again.
|
|
6
|
+
//
|
|
7
|
+
// h(ui.Input, { check: "iban", value, onChange, required: true })
|
|
8
|
+
// ui.validNear(button) // a button outside a form: checks the fields of its card, dialog or form
|
|
9
|
+
const React = require("react");
|
|
10
|
+
const h = React.createElement;
|
|
11
|
+
|
|
12
|
+
const CHECKS = ["text", "amount", "signedAmount", "quantity", "percent", "rate", "integer", "date", "email", "emails",
|
|
13
|
+
"phone", "url", "iban", "qrIban", "zip", "uid", "vat", "country", "account", "reference", "bic"];
|
|
14
|
+
|
|
15
|
+
const FIELD_TEXTS = {
|
|
16
|
+
de: {
|
|
17
|
+
fixFields: "Bitte die markierten Felder korrigieren.",
|
|
18
|
+
required: "Bitte ausfüllen.",
|
|
19
|
+
tooLong: "Höchstens {n} Zeichen.",
|
|
20
|
+
tooShort: "Mindestens {n} Zeichen.",
|
|
21
|
+
number: "Bitte eine Zahl eingeben, z. B. 12.5.",
|
|
22
|
+
amount: "Bitte einen Betrag eingeben, z. B. 1250.50 oder 1'250.50.",
|
|
23
|
+
negative: "Bitte keinen negativen Wert eingeben.",
|
|
24
|
+
positive: "Bitte einen Wert grösser als 0 eingeben.",
|
|
25
|
+
decimals: "Höchstens {n} Stellen nach dem Punkt.",
|
|
26
|
+
tooBig: "Diese Zahl ist zu gross.",
|
|
27
|
+
integer: "Bitte eine ganze Zahl ohne Komma eingeben.",
|
|
28
|
+
min: "Mindestens {n}.",
|
|
29
|
+
max: "Höchstens {n}.",
|
|
30
|
+
percent: "Bitte einen Prozentsatz von 0 bis 100 eingeben (höchstens 2 Stellen nach dem Punkt).",
|
|
31
|
+
date: "Bitte ein gültiges Datum eingeben (TT.MM.JJJJ).",
|
|
32
|
+
dateMin: "Das Datum darf nicht vor dem {d} liegen.",
|
|
33
|
+
dateMax: "Das Datum darf nicht nach dem {d} liegen.",
|
|
34
|
+
email: "Bitte eine gültige E-Mail-Adresse eingeben, z. B. name@firma.ch.",
|
|
35
|
+
emails: "Bitte gültige E-Mail-Adressen eingeben, mehrere mit Komma getrennt.",
|
|
36
|
+
phone: "Bitte eine gültige Telefonnummer eingeben, z. B. +41 44 123 45 67.",
|
|
37
|
+
url: "Bitte eine gültige Webadresse eingeben, z. B. www.firma.ch.",
|
|
38
|
+
iban: "Diese IBAN ist ungültig. Bitte prüfen, z. B. CH93 0076 2011 6238 5295 7.",
|
|
39
|
+
qrIban: "Das ist keine QR-IBAN. Eine QR-IBAN hat an Stelle 5 bis 9 eine Zahl von 30000 bis 31999.",
|
|
40
|
+
zipCH: "PLZ mit 4 Ziffern, z. B. 8001.",
|
|
41
|
+
zip4: "PLZ mit 4 Ziffern.",
|
|
42
|
+
zip5: "PLZ mit 5 Ziffern.",
|
|
43
|
+
zip: "Bitte eine gültige PLZ eingeben.",
|
|
44
|
+
uid: "Bitte eine gültige UID eingeben, z. B. CHE-123.456.788 (die letzte Ziffer ist eine Prüfziffer).",
|
|
45
|
+
vat: "Bitte eine gültige MWST-Nummer eingeben, z. B. CHE-123.456.788 MWST.",
|
|
46
|
+
vatForeign: "Bitte eine gültige MWST-Nummer mit Ländercode eingeben, z. B. DE123456789.",
|
|
47
|
+
country: "2 Buchstaben, z. B. CH.",
|
|
48
|
+
account: "Bitte eine Kontonummer mit 4 bis 6 Ziffern eingeben, z. B. 1020.",
|
|
49
|
+
reference: "Bitte eine gültige QR-Referenz (27 Ziffern) oder Creditor Reference (RF…) eingeben.",
|
|
50
|
+
bic: "Bitte einen gültigen BIC mit 8 oder 11 Zeichen eingeben.",
|
|
51
|
+
pattern: "Bitte das richtige Format verwenden.",
|
|
52
|
+
},
|
|
53
|
+
en: {
|
|
54
|
+
fixFields: "Please correct the marked fields.",
|
|
55
|
+
required: "Please fill in this field.",
|
|
56
|
+
tooLong: "At most {n} characters.",
|
|
57
|
+
tooShort: "At least {n} characters.",
|
|
58
|
+
number: "Please enter a number, e.g. 12.5.",
|
|
59
|
+
amount: "Please enter an amount, e.g. 1250.50 or 1'250.50.",
|
|
60
|
+
negative: "Please do not enter a negative value.",
|
|
61
|
+
positive: "Please enter a value greater than 0.",
|
|
62
|
+
decimals: "At most {n} digits after the point.",
|
|
63
|
+
tooBig: "This number is too large.",
|
|
64
|
+
integer: "Please enter a whole number.",
|
|
65
|
+
min: "At least {n}.",
|
|
66
|
+
max: "At most {n}.",
|
|
67
|
+
percent: "Please enter a percentage from 0 to 100 (at most 2 digits after the point).",
|
|
68
|
+
date: "Please enter a valid date.",
|
|
69
|
+
dateMin: "The date must not be before {d}.",
|
|
70
|
+
dateMax: "The date must not be after {d}.",
|
|
71
|
+
email: "Please enter a valid email address, e.g. name@company.ch.",
|
|
72
|
+
emails: "Please enter valid email addresses, several separated by commas.",
|
|
73
|
+
phone: "Please enter a valid phone number, e.g. +41 44 123 45 67.",
|
|
74
|
+
url: "Please enter a valid web address, e.g. www.company.ch.",
|
|
75
|
+
iban: "This IBAN is not valid. Please check it, e.g. CH93 0076 2011 6238 5295 7.",
|
|
76
|
+
qrIban: "This is not a QR-IBAN. A QR-IBAN has a number from 30000 to 31999 at positions 5 to 9.",
|
|
77
|
+
zipCH: "Postcode with 4 digits, e.g. 8001.",
|
|
78
|
+
zip4: "Postcode with 4 digits.",
|
|
79
|
+
zip5: "Postcode with 5 digits.",
|
|
80
|
+
zip: "Please enter a valid postcode.",
|
|
81
|
+
uid: "Please enter a valid UID, e.g. CHE-123.456.788 (the last digit is a check digit).",
|
|
82
|
+
vat: "Please enter a valid VAT number, e.g. CHE-123.456.788 MWST.",
|
|
83
|
+
vatForeign: "Please enter a valid VAT number with country code, e.g. DE123456789.",
|
|
84
|
+
country: "2 letters, e.g. CH.",
|
|
85
|
+
account: "Please enter an account number with 4 to 6 digits, e.g. 1020.",
|
|
86
|
+
reference: "Please enter a valid QR reference (27 digits) or Creditor Reference (RF…).",
|
|
87
|
+
bic: "Please enter a valid BIC with 8 or 11 characters.",
|
|
88
|
+
pattern: "Please use the expected format.",
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const SWISS = new Set(["CH", "LI"]);
|
|
93
|
+
|
|
94
|
+
// Characters allowed while typing; anything else is not taken into the field.
|
|
95
|
+
const ALLOWED = {
|
|
96
|
+
amount: /^[0-9.,'’ ]*$/,
|
|
97
|
+
signedAmount: /^-?[0-9.,'’ ]*$/,
|
|
98
|
+
quantity: /^[0-9.,'’ ]*$/,
|
|
99
|
+
percent: /^[0-9.,]*$/,
|
|
100
|
+
rate: /^[0-9.,]*$/,
|
|
101
|
+
integer: /^[0-9]*$/,
|
|
102
|
+
phone: /^[+0-9 ()/.-]*$/,
|
|
103
|
+
iban: /^[A-Za-z0-9 ]*$/,
|
|
104
|
+
qrIban: /^[A-Za-z0-9 ]*$/,
|
|
105
|
+
country: /^[A-Za-z]{0,2}$/,
|
|
106
|
+
account: /^[0-9]*$/,
|
|
107
|
+
reference: /^[A-Za-z0-9 ]*$/,
|
|
108
|
+
bic: /^[A-Za-z0-9]*$/,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
function allowed(check, value) {
|
|
112
|
+
const re = ALLOWED[check];
|
|
113
|
+
return !re || re.test(value);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Letters that are always written in capitals.
|
|
117
|
+
function upper(check) {
|
|
118
|
+
return ["iban", "qrIban", "country", "reference", "bic", "uid", "vat"].includes(check);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// "1'250,50 " -> "1250.50": Swiss thousands separators and the decimal comma are accepted.
|
|
122
|
+
function normalizeNumber(value) {
|
|
123
|
+
return String(value).replace(/[\s'’]/g, "").replace(",", ".");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function groupIban(value) {
|
|
127
|
+
return value.replace(/\s+/g, "").toUpperCase().replace(/(.{4})/g, "$1 ").trim();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Swiss UID "CHE-123.456.788" (mod 11 check digit); null if it is not a valid UID.
|
|
131
|
+
function formatUid(value) {
|
|
132
|
+
const m = String(value).toUpperCase().replace(/[\s.-]/g, "").match(/^CHE([0-9]{9})$/);
|
|
133
|
+
if (!m) return null;
|
|
134
|
+
const d = m[1].split("").map(Number);
|
|
135
|
+
const weights = [5, 4, 3, 2, 7, 6, 5, 4];
|
|
136
|
+
const sum = weights.reduce((s, w, i) => s + w * d[i], 0);
|
|
137
|
+
const check = (11 - (sum % 11)) % 11;
|
|
138
|
+
if (check === 10 || check !== d[8]) return null;
|
|
139
|
+
return `CHE-${m[1].slice(0, 3)}.${m[1].slice(3, 6)}.${m[1].slice(6)}`;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// The value as it is kept once the field is left; empty stays empty.
|
|
143
|
+
function normalize(check, value) {
|
|
144
|
+
const v = String(value).trim();
|
|
145
|
+
if (!v) return "";
|
|
146
|
+
switch (check) {
|
|
147
|
+
case "amount": case "signedAmount": case "quantity": case "percent": case "rate":
|
|
148
|
+
return normalizeNumber(v);
|
|
149
|
+
case "iban": case "qrIban":
|
|
150
|
+
return groupIban(v);
|
|
151
|
+
case "reference":
|
|
152
|
+
return v.replace(/\s+/g, "").toUpperCase();
|
|
153
|
+
case "country": case "bic":
|
|
154
|
+
return v.toUpperCase();
|
|
155
|
+
case "uid":
|
|
156
|
+
return formatUid(v) || v.toUpperCase();
|
|
157
|
+
case "vat": {
|
|
158
|
+
const m = v.toUpperCase().match(/^(CHE[-.\s\d]+?)\s*(MWST|TVA|IVA)?$/);
|
|
159
|
+
const uid = m && formatUid(m[1]);
|
|
160
|
+
return uid ? `${uid} ${m[2] || "MWST"}` : v.toUpperCase();
|
|
161
|
+
}
|
|
162
|
+
case "url": case "email":
|
|
163
|
+
return v;
|
|
164
|
+
default:
|
|
165
|
+
return value;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function decimal(value, places, opts) {
|
|
170
|
+
const signed = !!(opts && opts.signed);
|
|
171
|
+
const max = opts && opts.max;
|
|
172
|
+
const v = normalizeNumber(value);
|
|
173
|
+
if (!/^-?[0-9]+([.][0-9]+)?$/.test(v) && !/^-?[.][0-9]+$/.test(v)) return { key: "number" };
|
|
174
|
+
if (!signed && v.startsWith("-")) return { key: "negative" };
|
|
175
|
+
const parts = v.replace("-", "").split(".");
|
|
176
|
+
const int = parts[0];
|
|
177
|
+
const frac = parts[1] || "";
|
|
178
|
+
if (frac.length > places) return { key: "decimals", values: { n: places } };
|
|
179
|
+
if (int.length > 16) return { key: "tooBig" };
|
|
180
|
+
if (max !== undefined && Number(v) > max) return { key: "max", values: { n: max } };
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function mod97(s) {
|
|
185
|
+
let rest = 0;
|
|
186
|
+
for (const c of s) {
|
|
187
|
+
const n = parseInt(c, 36).toString();
|
|
188
|
+
for (const d of n) rest = (rest * 10 + Number(d)) % 97;
|
|
189
|
+
}
|
|
190
|
+
return rest;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// ISO 13616 check (mod 97); Swiss and Liechtenstein IBANs have 21 characters.
|
|
194
|
+
function validIban(value) {
|
|
195
|
+
const iban = String(value).replace(/\s+/g, "").toUpperCase();
|
|
196
|
+
if (!/^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$/.test(iban)) return false;
|
|
197
|
+
if (SWISS.has(iban.slice(0, 2)) && iban.length !== 21) return false;
|
|
198
|
+
return mod97(iban.slice(4) + iban.slice(0, 4)) === 1;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// QR-IBAN: Swiss IBAN whose institution id is 30000 to 31999 (QR bill).
|
|
202
|
+
function validQrIban(value) {
|
|
203
|
+
const iban = String(value).replace(/\s+/g, "").toUpperCase();
|
|
204
|
+
const iid = Number(iban.slice(4, 9));
|
|
205
|
+
return validIban(iban) && SWISS.has(iban.slice(0, 2)) && iid >= 30000 && iid <= 31999;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// QR reference: 27 digits with recursive mod 10 check digit.
|
|
209
|
+
function validQrReference(ref) {
|
|
210
|
+
if (!/^[0-9]{27}$/.test(ref)) return false;
|
|
211
|
+
const table = [0, 9, 4, 6, 8, 2, 7, 1, 3, 5];
|
|
212
|
+
let carry = 0;
|
|
213
|
+
for (const c of ref.slice(0, 26)) carry = table[(carry + Number(c)) % 10];
|
|
214
|
+
return (10 - carry) % 10 === Number(ref[26]);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Creditor Reference ISO 11649 ("RF" + 2 check digits + up to 21 characters).
|
|
218
|
+
function validScor(ref) {
|
|
219
|
+
if (!/^RF[0-9]{2}[A-Z0-9]{1,21}$/.test(ref)) return false;
|
|
220
|
+
return mod97(ref.slice(4) + ref.slice(0, 4)) === 1;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const ZIP = {
|
|
224
|
+
CH: { re: /^[1-9][0-9]{3}$/, key: "zipCH" },
|
|
225
|
+
LI: { re: /^94[89][0-9]$/, key: "zipCH" },
|
|
226
|
+
AT: { re: /^[1-9][0-9]{3}$/, key: "zip4" },
|
|
227
|
+
DE: { re: /^[0-9]{5}$/, key: "zip5" },
|
|
228
|
+
FR: { re: /^[0-9]{5}$/, key: "zip5" },
|
|
229
|
+
IT: { re: /^[0-9]{5}$/, key: "zip5" },
|
|
230
|
+
ES: { re: /^[0-9]{5}$/, key: "zip5" },
|
|
231
|
+
US: { re: /^[0-9]{5}(-[0-9]{4})?$/, key: "zip" },
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// The problem with a value ({key, values}), or null if it is fine. An empty value is fine here; "required" is
|
|
235
|
+
// the input's own attribute. opts.country: the country of the address (zip, UID, MWST strict for CH and LI).
|
|
236
|
+
function problem(check, value, opts) {
|
|
237
|
+
const v = String(value == null ? "" : value).trim();
|
|
238
|
+
if (!v) return null;
|
|
239
|
+
const country = String((opts && opts.country) || "").toUpperCase();
|
|
240
|
+
switch (check) {
|
|
241
|
+
case "amount": case "signedAmount": {
|
|
242
|
+
const p = decimal(v, 2, { signed: check === "signedAmount" });
|
|
243
|
+
return p && p.key === "number" ? { key: "amount" } : p;
|
|
244
|
+
}
|
|
245
|
+
case "quantity":
|
|
246
|
+
return decimal(v, 4);
|
|
247
|
+
case "percent":
|
|
248
|
+
return decimal(v, 2, { max: 100 }) && { key: "percent" };
|
|
249
|
+
case "rate": {
|
|
250
|
+
const p = decimal(v, 8);
|
|
251
|
+
if (p) return p;
|
|
252
|
+
return Number(normalizeNumber(v)) > 0 ? null : { key: "positive" };
|
|
253
|
+
}
|
|
254
|
+
case "integer":
|
|
255
|
+
return /^[0-9]+$/.test(v) ? null : { key: "integer" };
|
|
256
|
+
case "date":
|
|
257
|
+
return /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test(v) && !Number.isNaN(Date.parse(v)) ? null : { key: "date" };
|
|
258
|
+
case "email":
|
|
259
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(v) && v.length <= 320 ? null : { key: "email" };
|
|
260
|
+
case "emails": {
|
|
261
|
+
const list = v.split(/[,;\s]+/).filter(Boolean);
|
|
262
|
+
return list.every((a) => problem("email", a) === null) ? null : { key: "emails" };
|
|
263
|
+
}
|
|
264
|
+
case "phone": {
|
|
265
|
+
const digits = v.replace(/[^0-9]/g, "").length;
|
|
266
|
+
return /^\+?[0-9 ()/.-]+$/.test(v) && digits >= 6 && digits <= 15 ? null : { key: "phone" };
|
|
267
|
+
}
|
|
268
|
+
case "url":
|
|
269
|
+
return /^(https?:\/\/)?([a-z0-9äöü](-*[a-z0-9äöü])*\.)+[a-z]{2,}(:[0-9]{1,5})?(\/\S*)?$/i.test(v)
|
|
270
|
+
? null : { key: "url" };
|
|
271
|
+
case "iban":
|
|
272
|
+
return validIban(v) ? null : { key: "iban" };
|
|
273
|
+
case "qrIban":
|
|
274
|
+
if (!validIban(v)) return { key: "iban" };
|
|
275
|
+
return validQrIban(v) ? null : { key: "qrIban" };
|
|
276
|
+
case "zip": {
|
|
277
|
+
const rule = ZIP[country];
|
|
278
|
+
if (rule) return rule.re.test(v) ? null : { key: rule.key };
|
|
279
|
+
return /^[A-Za-z0-9][A-Za-z0-9 -]{1,9}$/.test(v) ? null : { key: "zip" };
|
|
280
|
+
}
|
|
281
|
+
case "uid":
|
|
282
|
+
if (SWISS.has(country) || /^CHE/i.test(v)) return formatUid(v) ? null : { key: "uid" };
|
|
283
|
+
return /^[A-Za-z0-9 .\-/]{2,20}$/.test(v) ? null : { key: "pattern" };
|
|
284
|
+
case "vat": {
|
|
285
|
+
if (SWISS.has(country) || /^CHE/i.test(v)) {
|
|
286
|
+
const m = v.toUpperCase().match(/^(CHE[-.\s\d]+?)\s*(MWST|TVA|IVA)?$/);
|
|
287
|
+
return m && formatUid(m[1]) ? null : { key: "vat" };
|
|
288
|
+
}
|
|
289
|
+
return /^[A-Z]{2}[A-Z0-9 .+*-]{2,28}$/i.test(v) ? null : { key: "vatForeign" };
|
|
290
|
+
}
|
|
291
|
+
case "country":
|
|
292
|
+
return /^[A-Z]{2}$/i.test(v) ? null : { key: "country" };
|
|
293
|
+
case "account":
|
|
294
|
+
return /^[1-9][0-9]{3,5}$/.test(v) ? null : { key: "account" };
|
|
295
|
+
case "reference": {
|
|
296
|
+
const r = v.replace(/\s+/g, "").toUpperCase();
|
|
297
|
+
return validQrReference(r) || validScor(r) ? null : { key: "reference" };
|
|
298
|
+
}
|
|
299
|
+
case "bic":
|
|
300
|
+
return /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/i.test(v) ? null : { key: "bic" };
|
|
301
|
+
default:
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Defaults for the native input per check: type, keyboard on phones, autocomplete, length.
|
|
307
|
+
function inputDefaults(check) {
|
|
308
|
+
switch (check) {
|
|
309
|
+
case "amount": case "signedAmount": case "quantity": case "percent": case "rate":
|
|
310
|
+
return { inputMode: "decimal", maxLength: 24 };
|
|
311
|
+
case "integer": case "account":
|
|
312
|
+
return { inputMode: "numeric", maxLength: check === "account" ? 6 : 12 };
|
|
313
|
+
case "date":
|
|
314
|
+
return { type: "date", min: "1900-01-01", max: "2099-12-31" };
|
|
315
|
+
case "email":
|
|
316
|
+
return { type: "email", inputMode: "email", autoComplete: "email", maxLength: 320 };
|
|
317
|
+
case "phone":
|
|
318
|
+
return { type: "tel", inputMode: "tel", autoComplete: "tel", maxLength: 40 };
|
|
319
|
+
case "url":
|
|
320
|
+
return { inputMode: "url", autoComplete: "url", maxLength: 200 };
|
|
321
|
+
case "iban": case "qrIban":
|
|
322
|
+
return { maxLength: 42, autoComplete: "off" };
|
|
323
|
+
case "zip":
|
|
324
|
+
return { maxLength: 10, autoComplete: "postal-code" };
|
|
325
|
+
case "uid":
|
|
326
|
+
return { maxLength: 20 };
|
|
327
|
+
case "vat":
|
|
328
|
+
return { maxLength: 30 };
|
|
329
|
+
case "country":
|
|
330
|
+
return { maxLength: 2, autoComplete: "country" };
|
|
331
|
+
case "reference":
|
|
332
|
+
return { maxLength: 40, autoComplete: "off" };
|
|
333
|
+
case "bic":
|
|
334
|
+
return { maxLength: 11 };
|
|
335
|
+
default:
|
|
336
|
+
return {};
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// "{n}" placeholders filled in.
|
|
341
|
+
function fill(text, values) {
|
|
342
|
+
return String(text).replace(/\{(\w+)\}/g, (_, k) => String((values || {})[k] == null ? "" : values[k]));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function fieldTexts(lang) {
|
|
346
|
+
return FIELD_TEXTS[lang === "en" ? "en" : "de"];
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// The message for a problem in the given language ("" for null).
|
|
350
|
+
function problemText(p, lang) {
|
|
351
|
+
if (!p) return "";
|
|
352
|
+
return fill(fieldTexts(lang)[p.key] || fieldTexts(lang).pattern, p.values);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function pageLang() {
|
|
356
|
+
return typeof document !== "undefined" && document.documentElement.lang === "en" ? "en" : "de";
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// "2026-11-06" -> "06.11.2026" in German, ISO in English.
|
|
360
|
+
function day(iso, lang) {
|
|
361
|
+
const [y, m, d] = String(iso).split("-");
|
|
362
|
+
return lang === "de" && d && m && y ? `${d}.${m}.${y}` : iso;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Sets the value like a person would, so React's onChange runs (used for the tidied-up value).
|
|
366
|
+
function setValue(el, value) {
|
|
367
|
+
const proto = el.ownerDocument.defaultView.HTMLInputElement.prototype;
|
|
368
|
+
const desc = Object.getOwnPropertyDescriptor(proto, "value");
|
|
369
|
+
if (desc && desc.set) desc.set.call(el, value);
|
|
370
|
+
el.dispatchEvent(new el.ownerDocument.defaultView.Event("input", { bubbles: true }));
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// The message for the field's current value, or "" if it is fine.
|
|
374
|
+
function messageFor(el, check, lang, country) {
|
|
375
|
+
const V = fieldTexts(lang);
|
|
376
|
+
const v = el.validity;
|
|
377
|
+
if (v.valueMissing) return V.required;
|
|
378
|
+
if (v.badInput) return el.type === "date" ? V.date : V.number;
|
|
379
|
+
if (el.type === "date" && (v.rangeUnderflow || v.rangeOverflow))
|
|
380
|
+
return fill(v.rangeUnderflow ? V.dateMin : V.dateMax, { d: day(v.rangeUnderflow ? el.min : el.max, lang) });
|
|
381
|
+
if (v.rangeUnderflow) return fill(V.min, { n: el.min });
|
|
382
|
+
if (v.rangeOverflow) return fill(V.max, { n: el.max });
|
|
383
|
+
if (v.stepMismatch) return V.integer;
|
|
384
|
+
if (v.tooLong) return fill(V.tooLong, { n: el.maxLength });
|
|
385
|
+
if (v.tooShort) return fill(V.tooShort, { n: el.minLength });
|
|
386
|
+
if (v.typeMismatch) return el.type === "email" ? V.email : el.type === "url" ? V.url : V.pattern;
|
|
387
|
+
if (check) {
|
|
388
|
+
const p = problem(check, el.value, { country });
|
|
389
|
+
if (p) return problemText(p, lang);
|
|
390
|
+
}
|
|
391
|
+
if (v.patternMismatch) return el.title || V.pattern;
|
|
392
|
+
return "";
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// <Input check="iban" …>: the native input with checks. Takes only allowed characters, tidies the value up when the
|
|
396
|
+
// field is left, shows a clear message under the field and blocks the form (setCustomValidity) until it is right.
|
|
397
|
+
// Props: check, country (zip, UID, MWST), lang ("de" | "en", default the page's <html lang>), inputRef, and every
|
|
398
|
+
// prop of <input>. className defaults to "input"; a wrong field also gets "border-destructive".
|
|
399
|
+
function Input(props) {
|
|
400
|
+
const { check, country, lang: langProp, inputRef, onChange, onBlur, className = "input", testId, ...rest } = props;
|
|
401
|
+
const lang = langProp || pageLang();
|
|
402
|
+
const id = React.useId();
|
|
403
|
+
const own = React.useRef(null);
|
|
404
|
+
const [msg, setMsg] = React.useState("");
|
|
405
|
+
const [shown, setShown] = React.useState(false);
|
|
406
|
+
const attrs = Object.assign({}, check ? inputDefaults(check) : {}, rest);
|
|
407
|
+
|
|
408
|
+
// Re-check after every render: the value, required, min and max may all have changed.
|
|
409
|
+
React.useLayoutEffect(() => {
|
|
410
|
+
const el = own.current;
|
|
411
|
+
if (!el) return;
|
|
412
|
+
el.setCustomValidity("");
|
|
413
|
+
const m = messageFor(el, check, lang, country);
|
|
414
|
+
el.setCustomValidity(m);
|
|
415
|
+
if (m !== msg) setMsg(m);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
React.useLayoutEffect(() => {
|
|
419
|
+
const el = own.current;
|
|
420
|
+
if (!el) return undefined;
|
|
421
|
+
const show = () => setShown(true);
|
|
422
|
+
el.addEventListener("invalid", show);
|
|
423
|
+
return () => el.removeEventListener("invalid", show);
|
|
424
|
+
}, []);
|
|
425
|
+
|
|
426
|
+
function change(e) {
|
|
427
|
+
const el = e.target;
|
|
428
|
+
if (check && !allowed(check, el.value)) return; // not taken: the field keeps its value
|
|
429
|
+
if (check && upper(check) && el.value !== el.value.toUpperCase()) {
|
|
430
|
+
const pos = el.selectionStart;
|
|
431
|
+
el.value = el.value.toUpperCase();
|
|
432
|
+
if (pos !== null && pos !== undefined) el.setSelectionRange(pos, pos);
|
|
433
|
+
}
|
|
434
|
+
if (onChange) onChange(e);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function blur(e) {
|
|
438
|
+
const el = e.target;
|
|
439
|
+
if (check && !rest.readOnly && !rest.disabled) {
|
|
440
|
+
const tidy = normalize(check, el.value);
|
|
441
|
+
if (tidy !== el.value && problem(check, tidy, { country }) === null) setValue(el, tidy);
|
|
442
|
+
}
|
|
443
|
+
setShown(true);
|
|
444
|
+
if (onBlur) onBlur(e);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const error = shown && msg;
|
|
448
|
+
return h(React.Fragment, null,
|
|
449
|
+
h("input", Object.assign({}, attrs, {
|
|
450
|
+
ref: (el) => {
|
|
451
|
+
own.current = el;
|
|
452
|
+
if (typeof inputRef === "function") inputRef(el);
|
|
453
|
+
else if (inputRef) inputRef.current = el;
|
|
454
|
+
},
|
|
455
|
+
className: error ? `${className} border-destructive` : className,
|
|
456
|
+
"aria-invalid": error ? true : rest["aria-invalid"],
|
|
457
|
+
"aria-describedby": error ? `${id}-error` : rest["aria-describedby"],
|
|
458
|
+
"data-testid": testId,
|
|
459
|
+
onChange: change,
|
|
460
|
+
onBlur: blur,
|
|
461
|
+
})),
|
|
462
|
+
error ? h("small", { id: `${id}-error`, role: "alert", className: "text-xs text-destructive",
|
|
463
|
+
"data-testid": testId ? `${testId}-error` : undefined }, msg) : null);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// Checks all fields inside `root` (for steps and buttons that do not submit a form): shows the messages and puts
|
|
467
|
+
// the cursor into the first wrong field; true if all are fine.
|
|
468
|
+
function fieldsValid(root) {
|
|
469
|
+
if (!root) return true;
|
|
470
|
+
const fields = Array.from(root.querySelectorAll("input, select, textarea"));
|
|
471
|
+
const wrong = fields.filter((f) => !f.checkValidity());
|
|
472
|
+
if (wrong[0]) wrong[0].focus();
|
|
473
|
+
return wrong.length === 0;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// For a button outside a form: checks the fields of the nearest `data-fields` box, form, dialog or card.
|
|
477
|
+
function validNear(el) {
|
|
478
|
+
return fieldsValid(el && el.closest("[data-fields], form, [role=dialog], .card"));
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
module.exports = {
|
|
482
|
+
Input, FIELD_CHECKS: CHECKS, FIELD_TEXTS, fieldAllowed: allowed, fieldUpper: upper, normalizeNumber,
|
|
483
|
+
normalizeField: normalize, fieldProblem: problem, fieldProblemText: problemText, fieldMessageFor: messageFor,
|
|
484
|
+
inputDefaults, fillText: fill, validIban, validQrIban, formatUid, validQrReference, validScor, fieldsValid,
|
|
485
|
+
validNear,
|
|
486
|
+
};
|
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"), require("./tenant"));
|
|
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"));
|
|
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?",
|
|
@@ -572,6 +593,26 @@ const LABELS = {
|
|
|
572
593
|
microsoft: "Sign in with Microsoft",
|
|
573
594
|
redirecting: "Redirecting …",
|
|
574
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
|
+
},
|
|
575
616
|
email: "Email",
|
|
576
617
|
password: "Password",
|
|
577
618
|
forgotPassword: "Forgot password?",
|
|
@@ -1094,6 +1135,7 @@ function labelsFor(lang, overrides) {
|
|
|
1094
1135
|
passwordPolicy: Object.assign({}, base.passwordPolicy, o.passwordPolicy),
|
|
1095
1136
|
profile_: Object.assign({}, base.profile_, o.profile_),
|
|
1096
1137
|
wizard: Object.assign({}, base.wizard, o.wizard),
|
|
1138
|
+
setup: Object.assign({}, base.setup, o.setup),
|
|
1097
1139
|
backup: Object.assign({}, base.backup, o.backup),
|
|
1098
1140
|
});
|
|
1099
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 };
|