@scalio-cloud/ui 0.108.0 → 0.109.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.
Files changed (61) hide show
  1. package/dist/app-kit/ScalioAuditPages.d.ts +37 -0
  2. package/dist/app-kit/ScalioAuditPages.d.ts.map +1 -0
  3. package/dist/app-kit/ScalioBackupSection.d.ts +27 -0
  4. package/dist/app-kit/ScalioBackupSection.d.ts.map +1 -0
  5. package/dist/app-kit/ScalioInvitePage.d.ts +24 -0
  6. package/dist/app-kit/ScalioInvitePage.d.ts.map +1 -0
  7. package/dist/app-kit/ScalioLoginPage.d.ts +31 -0
  8. package/dist/app-kit/ScalioLoginPage.d.ts.map +1 -0
  9. package/dist/app-kit/ScalioPasswordChangePage.d.ts +21 -0
  10. package/dist/app-kit/ScalioPasswordChangePage.d.ts.map +1 -0
  11. package/dist/app-kit/ScalioProfilePage.d.ts +39 -0
  12. package/dist/app-kit/ScalioProfilePage.d.ts.map +1 -0
  13. package/dist/app-kit/ScalioSaasUpdatesSection.d.ts +23 -0
  14. package/dist/app-kit/ScalioSaasUpdatesSection.d.ts.map +1 -0
  15. package/dist/app-kit/ScalioSecurityFactors.d.ts +28 -0
  16. package/dist/app-kit/ScalioSecurityFactors.d.ts.map +1 -0
  17. package/dist/app-kit/ScalioSelfTestPage.d.ts +14 -0
  18. package/dist/app-kit/ScalioSelfTestPage.d.ts.map +1 -0
  19. package/dist/app-kit/ScalioSupportCard.d.ts +13 -0
  20. package/dist/app-kit/ScalioSupportCard.d.ts.map +1 -0
  21. package/dist/app-kit/ScalioUsersPage.d.ts +48 -0
  22. package/dist/app-kit/ScalioUsersPage.d.ts.map +1 -0
  23. package/dist/app-kit/index.d.ts +27 -0
  24. package/dist/app-kit/index.d.ts.map +1 -0
  25. package/dist/app-kit/index.js +931 -0
  26. package/dist/app-kit/index.js.map +1 -0
  27. package/dist/app-kit/index.mjs +878 -0
  28. package/dist/app-kit/index.mjs.map +1 -0
  29. package/dist/chunk-A7O3P4YV.mjs +457 -0
  30. package/dist/chunk-A7O3P4YV.mjs.map +1 -0
  31. package/dist/config/index.d.ts +35 -0
  32. package/dist/config/index.d.ts.map +1 -0
  33. package/dist/config/index.js +85 -0
  34. package/dist/config/index.js.map +1 -0
  35. package/dist/config/index.mjs +59 -0
  36. package/dist/config/index.mjs.map +1 -0
  37. package/dist/core/afterLogin.d.ts +6 -0
  38. package/dist/core/afterLogin.d.ts.map +1 -0
  39. package/dist/core/api.d.ts +48 -0
  40. package/dist/core/api.d.ts.map +1 -0
  41. package/dist/core/auditActions.d.ts +17 -0
  42. package/dist/core/auditActions.d.ts.map +1 -0
  43. package/dist/core/datetime.d.ts +18 -0
  44. package/dist/core/datetime.d.ts.map +1 -0
  45. package/dist/core/i18n.d.ts +51 -0
  46. package/dist/core/i18n.d.ts.map +1 -0
  47. package/dist/core/index.d.ts +14 -0
  48. package/dist/core/index.d.ts.map +1 -0
  49. package/dist/core/index.js +509 -0
  50. package/dist/core/index.js.map +1 -0
  51. package/dist/core/index.mjs +39 -0
  52. package/dist/core/index.mjs.map +1 -0
  53. package/dist/core/legal.d.ts +17 -0
  54. package/dist/core/legal.d.ts.map +1 -0
  55. package/dist/core/mailReady.d.ts +12 -0
  56. package/dist/core/mailReady.d.ts.map +1 -0
  57. package/dist/core/passkeys.d.ts +30 -0
  58. package/dist/core/passkeys.d.ts.map +1 -0
  59. package/dist/core/permissions.d.ts +10 -0
  60. package/dist/core/permissions.d.ts.map +1 -0
  61. package/package.json +47 -3
@@ -0,0 +1,878 @@
1
+ import {
2
+ N_,
3
+ can,
4
+ mailReady
5
+ } from "../chunk-A7O3P4YV.mjs";
6
+
7
+ // src/app-kit/ScalioSecurityFactors.tsx
8
+ import { useMemo } from "react";
9
+ import { toast } from "sonner";
10
+ import { SecurityFactors as SharedSecurityFactors, securityApi } from "@scalio-cloud/ui/react";
11
+ import { jsx } from "react/jsx-runtime";
12
+ var defaultNotify = (text, tone) => {
13
+ if (tone === "error") toast.error(text);
14
+ else toast.success(text);
15
+ };
16
+ function ScalioSecurityFactors({
17
+ api,
18
+ product,
19
+ lang,
20
+ email,
21
+ qr,
22
+ confirm,
23
+ formatApiErrorDetail,
24
+ startRegistration,
25
+ browserSupportsWebAuthn,
26
+ onMfaChange,
27
+ className = "mt-8 pt-6 border-t border-border"
28
+ }) {
29
+ const client = useMemo(
30
+ () => securityApi(api, { startRegistration, browserSupportsWebAuthn }),
31
+ [api, startRegistration, browserSupportsWebAuthn]
32
+ );
33
+ const formatError = (e) => {
34
+ const err = e;
35
+ return formatApiErrorDetail(err?.response?.data?.detail) || err?.message || "";
36
+ };
37
+ return /* @__PURE__ */ jsx(
38
+ SharedSecurityFactors,
39
+ {
40
+ client,
41
+ lang,
42
+ product,
43
+ email,
44
+ qr,
45
+ notify: defaultNotify,
46
+ confirm,
47
+ formatError,
48
+ className,
49
+ onMfaChange
50
+ }
51
+ );
52
+ }
53
+
54
+ // src/app-kit/ScalioPasswordChangePage.tsx
55
+ import { toast as toast2 } from "sonner";
56
+ import { AuthHeader, AuthLayout, PasswordChange } from "@scalio-cloud/ui/react";
57
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
58
+ function ScalioPasswordChangePage({
59
+ api,
60
+ brand,
61
+ legalUrl,
62
+ email,
63
+ lang,
64
+ onLangChange,
65
+ t,
66
+ minLength = 12,
67
+ onPasswordChanged,
68
+ onLogout
69
+ }) {
70
+ const change = async (current, next) => {
71
+ const { data } = await api.post("/auth/change-password", {
72
+ current_password: current,
73
+ new_password: next
74
+ });
75
+ return data;
76
+ };
77
+ return /* @__PURE__ */ jsx2(AuthLayout, { legalUrl, brand, lang, onLangChange, children: /* @__PURE__ */ jsxs("div", { className: "space-y-4", "data-testid": "password-change-required", children: [
78
+ /* @__PURE__ */ jsx2(
79
+ AuthHeader,
80
+ {
81
+ eyebrow: email,
82
+ title: t("Choose your password"),
83
+ subtitle: t("You signed in with a start password. Choose your own password to continue.")
84
+ }
85
+ ),
86
+ /* @__PURE__ */ jsx2(
87
+ PasswordChange,
88
+ {
89
+ onSubmit: change,
90
+ minLength,
91
+ lang,
92
+ onDone: () => {
93
+ toast2.success(t("Password changed."));
94
+ onPasswordChanged();
95
+ }
96
+ }
97
+ ),
98
+ /* @__PURE__ */ jsx2(
99
+ "button",
100
+ {
101
+ type: "button",
102
+ onClick: onLogout,
103
+ "data-testid": "password-change-logout",
104
+ className: "w-full h-9 text-xs font-bold uppercase tracking-wider text-muted-foreground hover:text-foreground",
105
+ children: t("Sign out")
106
+ }
107
+ )
108
+ ] }) });
109
+ }
110
+
111
+ // src/app-kit/ScalioProfilePage.tsx
112
+ import { useEffect, useState } from "react";
113
+ import { toast as toast3 } from "sonner";
114
+ import { Loader2 } from "lucide-react";
115
+ import {
116
+ LanguageChoice,
117
+ MicrosoftConnection,
118
+ PasswordChange as PasswordChange2,
119
+ ProfileIdentity,
120
+ ProfileSection,
121
+ ThemeChoice,
122
+ TimezoneChoice,
123
+ labelsFor
124
+ } from "@scalio-cloud/ui/react";
125
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
126
+ var FIELD_CLASS = "mt-1 w-full h-10 px-3 bg-background border border-input rounded-sm text-sm focus:outline-none focus:ring-1 focus:ring-ring focus:border-ring transition-colors";
127
+ var LABEL_CLASS = "text-[11px] font-bold uppercase tracking-widest text-muted-foreground";
128
+ var PRIMARY_CLASS = "inline-flex h-10 items-center justify-center gap-2 px-4 bg-primary text-primary-foreground rounded-sm text-xs font-bold uppercase tracking-wider hover:bg-primary/90 transition-colors disabled:opacity-60";
129
+ var MS_LINK_ERRORS = {
130
+ linked_elsewhere: N_("This Microsoft account belongs to another account here. Ask an administrator."),
131
+ already_linked: N_("Your account is already linked with Microsoft."),
132
+ failed: N_("Linking with Microsoft failed. Please try again.")
133
+ };
134
+ function ScalioProfilePage({
135
+ api,
136
+ apiBaseUrl,
137
+ user,
138
+ updateUser,
139
+ lang,
140
+ setLang,
141
+ t,
142
+ theme,
143
+ setTheme,
144
+ formatApiErrorDetail,
145
+ roleLabels,
146
+ languageEndpoint = "/auth/language",
147
+ minPasswordLength = 12,
148
+ securityFactors
149
+ }) {
150
+ const L = labelsFor(lang);
151
+ const P = L.profile_;
152
+ const [name, setName] = useState(user?.name || "");
153
+ const [savingName, setSavingName] = useState(false);
154
+ const [ssoOn, setSsoOn] = useState(false);
155
+ const saved = () => {
156
+ toast3.success(P.saved);
157
+ };
158
+ const errorText = (e) => {
159
+ const err = e;
160
+ return formatApiErrorDetail(err?.response?.data?.detail) || err?.message || t("Something went wrong. Please try again.");
161
+ };
162
+ const defaultRoles = {
163
+ admin: t("Administrator"),
164
+ operator: t("Operator"),
165
+ editor: t("Editor"),
166
+ reader: t("Reader")
167
+ };
168
+ const resolvedRoles = roleLabels ?? defaultRoles;
169
+ const roleName = user?.role && resolvedRoles[user.role] || t("Reader");
170
+ useEffect(() => {
171
+ api.get("/auth/scalio/status").then((r) => setSsoOn(Boolean(r.data?.enabled))).catch(() => setSsoOn(false));
172
+ if (typeof window === "undefined") return;
173
+ const result = new URLSearchParams(window.location.search).get("microsoft");
174
+ if (!result) return;
175
+ window.history.replaceState(null, "", window.location.pathname);
176
+ if (result === "linked") {
177
+ toast3.success(t("Your Microsoft account is linked."));
178
+ api.get("/auth/me").then((r) => updateUser(r.data)).catch(() => null);
179
+ } else {
180
+ toast3.error(t(MS_LINK_ERRORS[result] ?? MS_LINK_ERRORS.failed));
181
+ }
182
+ }, []);
183
+ const unlinkMicrosoft = async () => {
184
+ try {
185
+ await api.delete("/auth/scalio/link");
186
+ if (user) updateUser({ ...user, microsoft: false });
187
+ toast3.success(t("The Microsoft link was removed."));
188
+ } catch (err) {
189
+ toast3.error(errorText(err));
190
+ }
191
+ };
192
+ const chooseLang = async (nextLang) => {
193
+ setLang(nextLang);
194
+ try {
195
+ const { data } = await api.post(languageEndpoint, {
196
+ language: nextLang
197
+ });
198
+ if (user) updateUser({ ...user, language: data?.language ?? nextLang });
199
+ saved();
200
+ if (data?.language_sync && typeof window !== "undefined") {
201
+ window.location.assign(
202
+ `${apiBaseUrl.replace(/\/api$/, "")}${data.language_sync}?next=${encodeURIComponent("/profile")}`
203
+ );
204
+ }
205
+ } catch (err) {
206
+ if (languageEndpoint === "/auth/preferences") {
207
+ toast3.error(errorText(err));
208
+ } else {
209
+ saved();
210
+ }
211
+ }
212
+ };
213
+ const saveName = async (e) => {
214
+ e.preventDefault();
215
+ setSavingName(true);
216
+ try {
217
+ const { data } = await api.put("/auth/profile", { name });
218
+ updateUser(data);
219
+ toast3.success(t("Profile saved"));
220
+ } catch (err) {
221
+ toast3.error(errorText(err));
222
+ } finally {
223
+ setSavingName(false);
224
+ }
225
+ };
226
+ const chooseTz = async (tz) => {
227
+ try {
228
+ await api.post("/auth/preferences", { timezone: tz });
229
+ if (user) updateUser({ ...user, timezone: tz });
230
+ saved();
231
+ } catch (err) {
232
+ toast3.error(errorText(err));
233
+ }
234
+ };
235
+ const changePassword = async (current, next) => {
236
+ await api.post("/auth/change-password", { current_password: current, new_password: next });
237
+ };
238
+ return /* @__PURE__ */ jsxs2("div", { "data-testid": "profile-page", className: "space-y-6", children: [
239
+ /* @__PURE__ */ jsxs2("div", { children: [
240
+ /* @__PURE__ */ jsx3("h1", { className: "font-display font-black uppercase tracking-tight text-3xl sm:text-4xl", children: L.profile }),
241
+ /* @__PURE__ */ jsx3("p", { className: "text-sm text-muted-foreground", children: P.subtitle })
242
+ ] }),
243
+ /* @__PURE__ */ jsxs2("div", { children: [
244
+ /* @__PURE__ */ jsx3(ProfileSection, { id: "account", lang, children: /* @__PURE__ */ jsx3(ProfileIdentity, { name: user?.name, email: user?.email, role: roleName, children: /* @__PURE__ */ jsxs2("form", { onSubmit: saveName, className: "flex flex-col sm:flex-row sm:items-end gap-3", children: [
245
+ /* @__PURE__ */ jsxs2("div", { className: "flex-1", children: [
246
+ /* @__PURE__ */ jsx3("label", { className: LABEL_CLASS, htmlFor: "profile-name", children: t("Name") }),
247
+ /* @__PURE__ */ jsx3(
248
+ "input",
249
+ {
250
+ id: "profile-name",
251
+ className: FIELD_CLASS,
252
+ value: name,
253
+ onChange: (e) => setName(e.target.value),
254
+ required: true,
255
+ maxLength: 120,
256
+ autoComplete: "name",
257
+ "data-testid": "profile-name-input"
258
+ }
259
+ )
260
+ ] }),
261
+ /* @__PURE__ */ jsxs2(
262
+ "button",
263
+ {
264
+ type: "submit",
265
+ className: PRIMARY_CLASS,
266
+ disabled: savingName || !name.trim() || name.trim() === user?.name,
267
+ "data-testid": "profile-save-btn",
268
+ children: [
269
+ savingName && /* @__PURE__ */ jsx3(Loader2, { className: "w-4 h-4 animate-spin" }),
270
+ t("Save")
271
+ ]
272
+ }
273
+ )
274
+ ] }) }) }),
275
+ /* @__PURE__ */ jsx3(ProfileSection, { id: "appearance", lang, children: /* @__PURE__ */ jsx3(
276
+ ThemeChoice,
277
+ {
278
+ theme,
279
+ onChange: (m) => {
280
+ setTheme(m);
281
+ saved();
282
+ },
283
+ lang
284
+ }
285
+ ) }),
286
+ /* @__PURE__ */ jsxs2(ProfileSection, { id: "language", lang, children: [
287
+ /* @__PURE__ */ jsx3(LanguageChoice, { lang, onChange: chooseLang }),
288
+ /* @__PURE__ */ jsx3(TimezoneChoice, { value: user?.timezone || "", onChange: chooseTz, lang })
289
+ ] }),
290
+ /* @__PURE__ */ jsxs2(ProfileSection, { id: "security", lang, testId: "change-password-section", children: [
291
+ /* @__PURE__ */ jsx3(
292
+ PasswordChange2,
293
+ {
294
+ onSubmit: changePassword,
295
+ onDone: () => toast3.success(t("Password changed. Other devices have been signed out.")),
296
+ minLength: minPasswordLength,
297
+ lang
298
+ }
299
+ ),
300
+ securityFactors
301
+ ] }),
302
+ (ssoOn || user?.microsoft) && /* @__PURE__ */ jsx3(ProfileSection, { id: "connections", lang, testId: "connections-section", children: /* @__PURE__ */ jsx3(
303
+ MicrosoftConnection,
304
+ {
305
+ linked: Boolean(user?.microsoft),
306
+ canUnlink: Boolean(user?.has_password),
307
+ lang,
308
+ onLink: () => window.location.assign(`${apiBaseUrl}/auth/scalio/login?link=1`),
309
+ onUnlink: unlinkMicrosoft
310
+ }
311
+ ) })
312
+ ] })
313
+ ] });
314
+ }
315
+
316
+ // src/app-kit/ScalioUsersPage.tsx
317
+ import { useCallback, useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
318
+ import { Navigate, NavLink, useNavigate, useParams, useSearchParams } from "react-router-dom";
319
+ import { toast as toast4 } from "sonner";
320
+ import {
321
+ PasswordPolicySelect,
322
+ RoleAdmin,
323
+ SettingsLayout,
324
+ UserAdmin,
325
+ accountArea,
326
+ accountGroups,
327
+ customerAccessProps,
328
+ labelsFor as labelsFor2,
329
+ rolesApi,
330
+ usersApi
331
+ } from "@scalio-cloud/ui/react";
332
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
333
+ function roleLabel(name, lang) {
334
+ if (name && typeof name === "object") {
335
+ return (lang === "en" ? name.en || name.de : name.de || name.en) || "";
336
+ }
337
+ return name;
338
+ }
339
+ function ScalioUsersPage({
340
+ api,
341
+ user,
342
+ lang,
343
+ t,
344
+ confirm,
345
+ formatApiErrorDetail,
346
+ defaultRole = "reader",
347
+ customers,
348
+ emptyCustomersHint,
349
+ renderEntraTab
350
+ }) {
351
+ const L = labelsFor2(lang);
352
+ const [params] = useSearchParams();
353
+ const { area } = useParams();
354
+ const navigate = useNavigate();
355
+ const usersClient = useMemo2(() => usersApi(api), [api]);
356
+ const rolesClient = useMemo2(() => rolesApi(api), [api]);
357
+ const [rows, setRows] = useState2([]);
358
+ const [ssoOn, setSsoOn] = useState2(false);
359
+ const [mailOn, setMailOn] = useState2(false);
360
+ const [roles, setRoles] = useState2([]);
361
+ const [policy, setPolicy] = useState2(null);
362
+ const load = useCallback(() => {
363
+ api.get("/users").then((r) => setRows(r.data)).catch(() => setRows([]));
364
+ rolesClient.list().then(setRoles).catch(() => setRoles([]));
365
+ api.get("/users/login-policy").then((r) => setPolicy(r.data)).catch(() => setPolicy(null));
366
+ api.get("/auth/scalio/status").then((r) => setSsoOn(Boolean(r.data?.enabled))).catch(() => setSsoOn(false));
367
+ api.get("/mail/settings").then((r) => setMailOn(mailReady(r.data))).catch(() => setMailOn(false));
368
+ }, [api, rolesClient]);
369
+ useEffect2(() => {
370
+ load();
371
+ }, [load]);
372
+ const fail = (e) => {
373
+ const err = e;
374
+ if (err?.licenseShown) return;
375
+ toast4.error(err?.response?.data?.detail ? formatApiErrorDetail(err.response.data.detail) : t("The action failed."));
376
+ };
377
+ const savePolicy = async (value) => {
378
+ if (value !== "local" && !await confirm({
379
+ title: value === "off" ? t("Turn off sign-in with a password?") : t("Only the emergency administrator with a password?"),
380
+ text: value === "off" ? t(
381
+ "From now on, everybody signs in with Microsoft. Passwords and passkeys no longer work. If Microsoft is unreachable, FORCE_LOCAL_LOGIN=true in the environment brings them back."
382
+ ) : t(
383
+ "From now on, everybody signs in with Microsoft, except the administrators marked as emergency administrator."
384
+ ),
385
+ action: t("Save")
386
+ })) {
387
+ return;
388
+ }
389
+ try {
390
+ const { data } = await api.put("/users/login-policy", { value });
391
+ setPolicy(data);
392
+ toast4.success(t("Saved"));
393
+ } catch (e) {
394
+ fail(e);
395
+ }
396
+ };
397
+ if (user?.role !== "admin") {
398
+ return /* @__PURE__ */ jsx4("p", { className: "text-sm text-muted-foreground", children: t("Only administrators can manage users.") });
399
+ }
400
+ const pending = rows.filter((u) => u.access_pending).length;
401
+ const emergencyCount = rows.filter(
402
+ (u) => u.emergency_admin && u.role === "admin" && u.has_password && !u.access_pending
403
+ ).length;
404
+ const active = accountArea(area);
405
+ if (!area) {
406
+ const old = params.get("tab");
407
+ const target = old === "signIn" ? "sign-in" : old && ["roles", "entra"].includes(old) ? old : "users";
408
+ return /* @__PURE__ */ jsx4(Navigate, { to: `/accounts/${target}`, replace: true });
409
+ }
410
+ const notify2 = (text, tone) => {
411
+ if (tone === "error") toast4.error(text);
412
+ else toast4.success(text);
413
+ };
414
+ const formatErr = (e) => {
415
+ const err = e;
416
+ return err?.response?.data?.detail ? formatApiErrorDetail(err.response.data.detail) : t("The action failed.");
417
+ };
418
+ const groups = accountGroups({ lang }).map(
419
+ (g) => ({
420
+ ...g,
421
+ items: g.items.map(
422
+ (it) => it.id === "users" ? {
423
+ ...it,
424
+ hint: t("Who can use this app and what they may do"),
425
+ label: pending > 0 ? `${it.label} (${pending})` : it.label
426
+ } : it
427
+ )
428
+ })
429
+ );
430
+ const extraCustomerProps = customers ? customerAccessProps({
431
+ customers,
432
+ lang,
433
+ emptyHint: emptyCustomersHint ?? t("No customers yet. Add them under Settings, Tenants.")
434
+ }) : {};
435
+ return /* @__PURE__ */ jsx4("div", { "data-testid": "users-page", children: /* @__PURE__ */ jsxs3(
436
+ SettingsLayout,
437
+ {
438
+ groups,
439
+ active,
440
+ title: active === "users" ? L.accountTabs.users : void 0,
441
+ root: L.accounts,
442
+ link: NavLink,
443
+ onSelect: (it) => navigate(it.to),
444
+ lang,
445
+ search: false,
446
+ testId: "accounts-layout",
447
+ children: [
448
+ active === "users" && /* @__PURE__ */ jsx4(
449
+ UserAdmin,
450
+ {
451
+ client: usersClient,
452
+ me: user.id,
453
+ lang,
454
+ canLock: true,
455
+ onChange: load,
456
+ roles: roles.map((r) => ({ value: r.id, label: roleLabel(r.name, lang) })),
457
+ defaultRole,
458
+ signInModes: mailOn ? ["microsoft", "password", "invite"] : ["microsoft", "password"],
459
+ microsoftEnabled: ssoOn,
460
+ ...extraCustomerProps,
461
+ notify: notify2,
462
+ confirm,
463
+ formatError: formatErr
464
+ }
465
+ ),
466
+ active === "roles" && /* @__PURE__ */ jsx4(
467
+ RoleAdmin,
468
+ {
469
+ client: rolesClient,
470
+ lang,
471
+ onChange: load,
472
+ currentRole: user.role,
473
+ notify: notify2,
474
+ confirm,
475
+ formatError: formatErr
476
+ }
477
+ ),
478
+ active === "entra" && renderEntraTab?.(load),
479
+ active === "signIn" && policy && /* @__PURE__ */ jsx4("div", { "data-testid": "login-policy-card", className: "bg-card border border-border rounded-sm px-4 py-3", children: /* @__PURE__ */ jsx4(
480
+ PasswordPolicySelect,
481
+ {
482
+ value: policy.value,
483
+ emergencyCount,
484
+ forced: policy.forced,
485
+ onChange: savePolicy,
486
+ lang,
487
+ testId: "login-policy"
488
+ }
489
+ ) })
490
+ ]
491
+ }
492
+ ) });
493
+ }
494
+
495
+ // src/app-kit/ScalioLoginPage.tsx
496
+ import { useCallback as useCallback2, useEffect as useEffect3 } from "react";
497
+ import { useNavigate as useNavigate2 } from "react-router-dom";
498
+ import { LoginPage } from "@scalio-cloud/ui/react";
499
+ import { jsx as jsx5 } from "react/jsx-runtime";
500
+ function ScalioLoginPage({
501
+ api,
502
+ apiBase,
503
+ auth,
504
+ appName,
505
+ brand,
506
+ lang,
507
+ onLangChange,
508
+ legalUrl,
509
+ passkeys = false,
510
+ clearSessionKeys = [],
511
+ afterLoginTo = "/",
512
+ onSignedIn
513
+ }) {
514
+ const navigate = useNavigate2();
515
+ useEffect3(() => {
516
+ if (clearSessionKeys.length === 0) return;
517
+ try {
518
+ for (const key of clearSessionKeys) {
519
+ sessionStorage.removeItem(key);
520
+ }
521
+ } catch {
522
+ }
523
+ }, [clearSessionKeys]);
524
+ const handleSignedIn = useCallback2(() => {
525
+ if (onSignedIn) onSignedIn();
526
+ else navigate(afterLoginTo, { replace: true });
527
+ }, [onSignedIn, navigate, afterLoginTo]);
528
+ return /* @__PURE__ */ jsx5(
529
+ LoginPage,
530
+ {
531
+ api,
532
+ apiBase,
533
+ auth,
534
+ appName,
535
+ brand,
536
+ lang,
537
+ onLangChange,
538
+ legalUrl,
539
+ passkeys,
540
+ onSignedIn: handleSignedIn
541
+ }
542
+ );
543
+ }
544
+
545
+ // src/app-kit/ScalioInvitePage.tsx
546
+ import { useEffect as useEffect4, useState as useState3 } from "react";
547
+ import { useNavigate as useNavigate3 } from "react-router-dom";
548
+ import { Loader2 as Loader22 } from "lucide-react";
549
+ import { AuthHeader as AuthHeader2, AuthLayout as AuthLayout2, AuthMessage } from "@scalio-cloud/ui/react";
550
+ import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
551
+ var FIELD_CLASS2 = "mt-1 w-full h-11 px-3 bg-background border border-input rounded-sm text-sm focus:outline-none focus:ring-1 focus:ring-ring";
552
+ var LABEL_CLASS2 = "text-[11px] font-bold uppercase tracking-widest text-muted-foreground";
553
+ function ScalioInvitePage({
554
+ api,
555
+ brand,
556
+ welcomeTitle,
557
+ legalUrl,
558
+ lang,
559
+ onLangChange,
560
+ t,
561
+ formatApiErrorDetail,
562
+ onAuthenticated,
563
+ redirectTo = "/"
564
+ }) {
565
+ const navigate = useNavigate3();
566
+ const [token] = useState3(() => typeof window !== "undefined" ? window.location.hash.replace(/^#/, "") : "");
567
+ const [info, setInfo] = useState3(null);
568
+ const [invalid, setInvalid] = useState3(false);
569
+ const [pw, setPw] = useState3("");
570
+ const [pw2, setPw2] = useState3("");
571
+ const [error, setError] = useState3("");
572
+ const [busy, setBusy] = useState3(false);
573
+ useEffect4(() => {
574
+ if (!token) {
575
+ setInvalid(true);
576
+ return;
577
+ }
578
+ api.get(`/auth/invite/${encodeURIComponent(token)}`).then((r) => setInfo(r.data)).catch(() => setInvalid(true));
579
+ }, [api, token]);
580
+ const submit = async (e) => {
581
+ e.preventDefault();
582
+ setError("");
583
+ if (pw !== pw2) {
584
+ setError(t("The passwords do not match."));
585
+ return;
586
+ }
587
+ setBusy(true);
588
+ try {
589
+ const { data } = await api.post(`/auth/invite/${encodeURIComponent(token)}`, { password: pw });
590
+ onAuthenticated(data.user);
591
+ if (typeof window !== "undefined") {
592
+ window.history.replaceState(null, "", "/invite");
593
+ }
594
+ navigate(redirectTo, { replace: true });
595
+ } catch (err) {
596
+ const eObj = err;
597
+ setError(formatApiErrorDetail(eObj?.response?.data?.detail) || eObj?.message || t("The action failed."));
598
+ } finally {
599
+ setBusy(false);
600
+ }
601
+ };
602
+ return /* @__PURE__ */ jsx6(AuthLayout2, { legalUrl, brand, lang, onLangChange, children: /* @__PURE__ */ jsxs4("div", { className: "space-y-4", "data-testid": "invite-page", children: [
603
+ /* @__PURE__ */ jsx6(
604
+ AuthHeader2,
605
+ {
606
+ eyebrow: info?.email,
607
+ title: welcomeTitle,
608
+ subtitle: t("Choose your password to finish the invitation.")
609
+ }
610
+ ),
611
+ invalid && /* @__PURE__ */ jsx6(AuthMessage, { kind: "error", testId: "invite-invalid", children: t("This invitation is no longer valid. Ask an administrator for a new one.") }),
612
+ !invalid && !info && /* @__PURE__ */ jsx6(Loader22, { className: "w-5 h-5 animate-spin text-primary" }),
613
+ info && /* @__PURE__ */ jsxs4("form", { onSubmit: submit, className: "space-y-3", children: [
614
+ /* @__PURE__ */ jsxs4("label", { className: "block", children: [
615
+ /* @__PURE__ */ jsx6("span", { className: LABEL_CLASS2, children: t("New password") }),
616
+ /* @__PURE__ */ jsx6(
617
+ "input",
618
+ {
619
+ type: "password",
620
+ autoComplete: "new-password",
621
+ className: FIELD_CLASS2,
622
+ value: pw,
623
+ onChange: (e) => setPw(e.target.value),
624
+ "data-testid": "invite-password"
625
+ }
626
+ )
627
+ ] }),
628
+ /* @__PURE__ */ jsxs4("label", { className: "block", children: [
629
+ /* @__PURE__ */ jsx6("span", { className: LABEL_CLASS2, children: t("Repeat password") }),
630
+ /* @__PURE__ */ jsx6(
631
+ "input",
632
+ {
633
+ type: "password",
634
+ autoComplete: "new-password",
635
+ className: FIELD_CLASS2,
636
+ value: pw2,
637
+ onChange: (e) => setPw2(e.target.value),
638
+ "data-testid": "invite-password2"
639
+ }
640
+ )
641
+ ] }),
642
+ error && /* @__PURE__ */ jsx6(AuthMessage, { kind: "error", testId: "invite-error", children: error }),
643
+ /* @__PURE__ */ jsxs4(
644
+ "button",
645
+ {
646
+ type: "submit",
647
+ disabled: busy,
648
+ "data-testid": "invite-submit",
649
+ className: "w-full h-11 flex items-center justify-center gap-2 bg-primary text-primary-foreground rounded-sm text-sm font-bold uppercase tracking-wider hover:bg-primary/90 disabled:opacity-60",
650
+ children: [
651
+ busy && /* @__PURE__ */ jsx6(Loader22, { className: "w-4 h-4 animate-spin" }),
652
+ t("Save password and sign in")
653
+ ]
654
+ }
655
+ )
656
+ ] })
657
+ ] }) });
658
+ }
659
+
660
+ // src/app-kit/ScalioAuditPages.tsx
661
+ import { useMemo as useMemo3 } from "react";
662
+ import { Link, NavLink as NavLink2 } from "react-router-dom";
663
+ import { toast as toast5 } from "sonner";
664
+ import { AuditLog, AuditNav, JobsPanel, PageHeader, auditApi, jobsApi, labelsFor as labelsFor3 } from "@scalio-cloud/ui/react";
665
+ import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
666
+ var defaultNotify2 = (text, tone) => {
667
+ if (tone === "error") toast5.error(text);
668
+ else toast5.success(text);
669
+ };
670
+ function ScalioAuditHeader({ lang, t }) {
671
+ const L = labelsFor3(lang);
672
+ return /* @__PURE__ */ jsxs5("div", { className: "space-y-3", children: [
673
+ /* @__PURE__ */ jsx7(PageHeader, { title: L.auditLog, subtitle: t("Who changed what, and the background jobs of this installation") }),
674
+ /* @__PURE__ */ jsx7(AuditNav, { link: NavLink2, lang })
675
+ ] });
676
+ }
677
+ function ScalioAuditPage({
678
+ api,
679
+ user,
680
+ lang,
681
+ t,
682
+ actionLabel,
683
+ storageKey
684
+ }) {
685
+ const client = useMemo3(() => auditApi(api), [api]);
686
+ if (!can(user, "audit.view")) return null;
687
+ return /* @__PURE__ */ jsxs5("div", { "data-testid": "audit-page", className: "space-y-5", children: [
688
+ /* @__PURE__ */ jsx7(ScalioAuditHeader, { lang, t }),
689
+ /* @__PURE__ */ jsx7(AuditLog, { client, lang, notify: defaultNotify2, actionLabel, storageKey })
690
+ ] });
691
+ }
692
+ function ScalioJobsPage({ api, user, lang, t, confirm }) {
693
+ const client = useMemo3(() => jobsApi(api), [api]);
694
+ if (!can(user, "audit.view")) return null;
695
+ return /* @__PURE__ */ jsxs5("div", { "data-testid": "jobs-page", className: "space-y-5", children: [
696
+ /* @__PURE__ */ jsx7(ScalioAuditHeader, { lang, t }),
697
+ /* @__PURE__ */ jsx7(
698
+ JobsPanel,
699
+ {
700
+ client,
701
+ lang,
702
+ canRun: can(user, "jobs.run"),
703
+ link: Link,
704
+ confirm,
705
+ notify: defaultNotify2
706
+ }
707
+ )
708
+ ] });
709
+ }
710
+
711
+ // src/app-kit/ScalioSelfTestPage.tsx
712
+ import { useEffect as useEffect5, useMemo as useMemo4, useState as useState4 } from "react";
713
+ import { Navigate as Navigate2 } from "react-router-dom";
714
+ import { toast as toast6 } from "sonner";
715
+ import { PageHeader as PageHeader2, SelfTestPanel, selftestApi } from "@scalio-cloud/ui/react";
716
+ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
717
+ function ScalioSelfTestPage({ api, user, lang, t }) {
718
+ const [on, setOn] = useState4(null);
719
+ const client = useMemo4(() => selftestApi(api), [api]);
720
+ useEffect5(() => {
721
+ api.get("/e2e/status").then((r) => setOn(Boolean(r.data?.enabled))).catch(() => setOn(false));
722
+ }, [api]);
723
+ if (user?.role !== "admin" || on === false) return /* @__PURE__ */ jsx8(Navigate2, { to: "/", replace: true });
724
+ if (on === null) return null;
725
+ return /* @__PURE__ */ jsxs6("div", { "data-testid": "selftest-page", className: "space-y-5", children: [
726
+ /* @__PURE__ */ jsx8(PageHeader2, { eyebrow: t("Tests"), title: t("E2E self-check"), subtitle: t("Self-check of this test instance") }),
727
+ /* @__PURE__ */ jsx8(
728
+ SelfTestPanel,
729
+ {
730
+ client,
731
+ lang,
732
+ notify: (text, tone) => tone === "error" ? toast6.error(text) : toast6.success(text)
733
+ }
734
+ )
735
+ ] });
736
+ }
737
+
738
+ // src/app-kit/ScalioBackupSection.tsx
739
+ import { useEffect as useEffect6, useMemo as useMemo5, useState as useState5 } from "react";
740
+ import { Link as Link2 } from "react-router-dom";
741
+ import { toast as toast7 } from "sonner";
742
+ import { BackupPanel, MaintenanceNotice, SettingsSection, backupApi } from "@scalio-cloud/ui/react";
743
+ import { jsx as jsx9 } from "react/jsx-runtime";
744
+ var notify = (text, tone) => {
745
+ if (tone === "error") toast7.error(text);
746
+ else toast7.success(text);
747
+ };
748
+ function ScalioBackupSection({
749
+ api,
750
+ lang,
751
+ t,
752
+ onSignIn,
753
+ withDataOnLabel,
754
+ description,
755
+ accountTo = "/profile"
756
+ }) {
757
+ const client = useMemo5(() => backupApi(api), [api]);
758
+ const labels = useMemo5(
759
+ () => withDataOnLabel ? { backup: { withDataOn: withDataOnLabel } } : void 0,
760
+ [withDataOnLabel]
761
+ );
762
+ return /* @__PURE__ */ jsx9(
763
+ SettingsSection,
764
+ {
765
+ id: "backup",
766
+ title: t("Backup"),
767
+ testId: "backup-card",
768
+ description: description ?? t("Encrypted export and import, e.g. to move to another instance. After a move the tenants are connected again."),
769
+ children: /* @__PURE__ */ jsx9(
770
+ BackupPanel,
771
+ {
772
+ client,
773
+ lang,
774
+ labels,
775
+ accountTo,
776
+ link: Link2,
777
+ notify,
778
+ onSignIn
779
+ }
780
+ )
781
+ }
782
+ );
783
+ }
784
+ function ScalioMaintenanceBanner({ api, lang }) {
785
+ const client = useMemo5(() => backupApi(api), [api]);
786
+ const [on, setOn] = useState5(false);
787
+ useEffect6(() => {
788
+ const show = () => setOn(true);
789
+ window.addEventListener("scalio-maintenance", show);
790
+ return () => window.removeEventListener("scalio-maintenance", show);
791
+ }, []);
792
+ return on ? /* @__PURE__ */ jsx9(MaintenanceNotice, { client, lang }) : null;
793
+ }
794
+
795
+ // src/app-kit/ScalioSaasUpdatesSection.tsx
796
+ import { useEffect as useEffect7, useMemo as useMemo6, useState as useState6 } from "react";
797
+ import { toast as toast8 } from "sonner";
798
+ import { SaasUpdatesPanel, SettingsSection as SettingsSection2, UpdateBanner, saasUpdatesApi } from "@scalio-cloud/ui/react";
799
+ import { jsx as jsx10 } from "react/jsx-runtime";
800
+ function ScalioSaasUpdateBanner({ api, lang, onOpen }) {
801
+ const client = useMemo6(() => saasUpdatesApi(api), [api]);
802
+ return /* @__PURE__ */ jsx10(UpdateBanner, { client, lang, onOpen });
803
+ }
804
+ function ScalioSaasUpdatesSection({
805
+ api,
806
+ lang,
807
+ t,
808
+ admin = true
809
+ }) {
810
+ const client = useMemo6(() => saasUpdatesApi(api), [api]);
811
+ const notify2 = useMemo6(
812
+ () => (msg, tone) => tone === "error" ? toast8.error(msg) : toast8.success(msg),
813
+ []
814
+ );
815
+ const [prerelease, setPrerelease] = useState6(false);
816
+ useEffect7(() => {
817
+ let alive = true;
818
+ client.state().then((d) => {
819
+ if (alive) setPrerelease(Boolean(d?.prerelease?.opt_in));
820
+ }).catch(() => {
821
+ });
822
+ return () => {
823
+ alive = false;
824
+ };
825
+ }, [client]);
826
+ const onPrereleaseChange = async (on, opts) => {
827
+ await api.put("/saas-updates/prerelease-error-reports", { enabled: Boolean(on && opts?.errorReports) });
828
+ const d = await client.act("prerelease", { enabled: Boolean(on) });
829
+ setPrerelease(d?.prerelease ? Boolean(d.prerelease.opt_in) : Boolean(on));
830
+ };
831
+ return /* @__PURE__ */ jsx10(
832
+ SettingsSection2,
833
+ {
834
+ id: "updates",
835
+ title: t("Updates"),
836
+ description: t("New versions from Scalio, your maintenance window and the deadline"),
837
+ testId: "saas-updates-card",
838
+ children: /* @__PURE__ */ jsx10(
839
+ SaasUpdatesPanel,
840
+ {
841
+ client,
842
+ lang,
843
+ notify: notify2,
844
+ admin,
845
+ prerelease,
846
+ onPrereleaseChange
847
+ }
848
+ )
849
+ }
850
+ );
851
+ }
852
+
853
+ // src/app-kit/ScalioSupportCard.tsx
854
+ import { useMemo as useMemo7 } from "react";
855
+ import { SettingsSection as SettingsSection3, SupportConnection, supportApi } from "@scalio-cloud/ui/react";
856
+ import { jsx as jsx11 } from "react/jsx-runtime";
857
+ function ScalioSupportCard({ api, lang, t }) {
858
+ const client = useMemo7(() => supportApi(api), [api]);
859
+ return /* @__PURE__ */ jsx11(SettingsSection3, { id: "support", title: t("Support connection"), testId: "support-connection-card", children: /* @__PURE__ */ jsx11(SupportConnection, { client, lang }) });
860
+ }
861
+ export {
862
+ ScalioAuditHeader,
863
+ ScalioAuditPage,
864
+ ScalioBackupSection,
865
+ ScalioInvitePage,
866
+ ScalioJobsPage,
867
+ ScalioLoginPage,
868
+ ScalioMaintenanceBanner,
869
+ ScalioPasswordChangePage,
870
+ ScalioProfilePage,
871
+ ScalioSaasUpdateBanner,
872
+ ScalioSaasUpdatesSection,
873
+ ScalioSecurityFactors,
874
+ ScalioSelfTestPage,
875
+ ScalioSupportCard,
876
+ ScalioUsersPage
877
+ };
878
+ //# sourceMappingURL=index.mjs.map