@mano8/astro-auth-m8 2.0.0 → 2.2.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 (38) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +41 -1
  3. package/dist/src/runtime/react/AuthErrorBoundary.d.ts +53 -0
  4. package/dist/src/runtime/react/AuthErrorBoundary.d.ts.map +1 -0
  5. package/dist/src/runtime/react/AuthErrorBoundary.js +58 -0
  6. package/dist/src/runtime/react/AuthErrorBoundary.js.map +1 -0
  7. package/dist/src/runtime/react/RequireRole.d.ts +39 -2
  8. package/dist/src/runtime/react/RequireRole.d.ts.map +1 -1
  9. package/dist/src/runtime/react/RequireRole.js +16 -1
  10. package/dist/src/runtime/react/RequireRole.js.map +1 -1
  11. package/dist/src/runtime/react/default-ui/CallbackView.d.ts.map +1 -1
  12. package/dist/src/runtime/react/default-ui/CallbackView.js +5 -1
  13. package/dist/src/runtime/react/default-ui/CallbackView.js.map +1 -1
  14. package/dist/src/runtime/react/default-ui/SignupView.d.ts.map +1 -1
  15. package/dist/src/runtime/react/default-ui/SignupView.js +4 -1
  16. package/dist/src/runtime/react/default-ui/SignupView.js.map +1 -1
  17. package/dist/src/runtime/react/default-ui/StarterAccountPage.d.ts.map +1 -1
  18. package/dist/src/runtime/react/default-ui/StarterAccountPage.js +4 -1
  19. package/dist/src/runtime/react/default-ui/StarterAccountPage.js.map +1 -1
  20. package/dist/src/runtime/react/default-ui/StarterLoginPage.d.ts.map +1 -1
  21. package/dist/src/runtime/react/default-ui/StarterLoginPage.js +5 -1
  22. package/dist/src/runtime/react/default-ui/StarterLoginPage.js.map +1 -1
  23. package/dist/src/runtime/react/default-ui/StarterLogoutPage.d.ts +20 -0
  24. package/dist/src/runtime/react/default-ui/StarterLogoutPage.d.ts.map +1 -0
  25. package/dist/src/runtime/react/default-ui/StarterLogoutPage.js +20 -0
  26. package/dist/src/runtime/react/default-ui/StarterLogoutPage.js.map +1 -0
  27. package/dist/src/runtime/react/default-ui/index.d.ts +1 -0
  28. package/dist/src/runtime/react/default-ui/index.d.ts.map +1 -1
  29. package/dist/src/runtime/react/default-ui/index.js +1 -0
  30. package/dist/src/runtime/react/default-ui/index.js.map +1 -1
  31. package/dist/src/runtime/react/index.d.ts +2 -0
  32. package/dist/src/runtime/react/index.d.ts.map +1 -1
  33. package/dist/src/runtime/react/index.js +8 -0
  34. package/dist/src/runtime/react/index.js.map +1 -1
  35. package/package.json +11 -4
  36. package/registry/r/account-dashboard.json +1 -1
  37. package/registry/r/security-panel.json +1 -1
  38. package/src/routes/logout.astro +3 -3
package/CHANGELOG.md CHANGED
@@ -6,6 +6,67 @@ This project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
  The major version tracks the supported `fa-auth-m8` **API contract**, not just
7
7
  this package's own surface: a backend contract repoint is always a major.
8
8
 
9
+ ## 2.2.0
10
+
11
+ Additive only; the supported backend contract stays `fa-auth-m8@2.0`, range
12
+ `>=2.0.0 <3.0.0`.
13
+
14
+ ### Added
15
+
16
+ - **`AuthErrorBoundary` from `./react`**, with a safe default fallback, custom
17
+ fallback and reporting hooks, retry support, and reset keys. Every starter
18
+ island root now mounts beneath this boundary so a render failure leaves a
19
+ usable recovery surface instead of a blank login, signup, callback, account,
20
+ or logout region.
21
+ - **A dev-only `/_preview` gallery** for exercising every auth island against a
22
+ deterministic in-browser service stub. Run it with `npm run preview:dev`;
23
+ `npm run preview:build` typechecks and bundles the same gallery in CI.
24
+ - **Standalone package-consumer gates** for generated registry skins and the
25
+ packed tarball, plus fleet-alignment and registry-drift checks in CI.
26
+
27
+ ### Changed
28
+
29
+ - Raised the runtime dependency on `@mano8/astro-ui-m8` from `^1.4.2` to
30
+ `^1.5.0`, the published shared-UI release required by the registry gates.
31
+ - Expanded linting to the maintained repository surface and kept development
32
+ dependencies inside the high-severity audit that protects the build and
33
+ signing environment.
34
+
35
+ ## 2.1.0
36
+
37
+ Additive only; the supported backend contract stays `fa-auth-m8@2.0`, range
38
+ `>=2.0.0 <3.0.0`.
39
+
40
+ ### Added
41
+
42
+ - **`RequireRole minimumRole`**, an explicit minimum-role mode:
43
+ `minimumRole="admin"` renders when the signed-in role meets or exceeds
44
+ `admin` on the ordered hierarchy. It decides identically to
45
+ `roles={["admin"]}` — each array entry has been a floor since 2.0.0 — but
46
+ says what the backend dependency says instead of reading as exact membership,
47
+ so a consumer expressing a single floor no longer hand-enumerates a role
48
+ array. `roles` is unchanged and stays for guards that accept several
49
+ unrelated tiers; `superuser` remains the separate dual-evidence gate. A guard
50
+ may carry more than one mode and grants on the first that holds; one carrying
51
+ no mode grants nothing, as before.
52
+ - **`hasMinimumRole`, `hasSuperuserPrivileges`, `privilegeClaimsAreConsistent`
53
+ and `ORDERED_ROLES` re-exported from `./react`**, as the same bindings the
54
+ `./authorization` subpath exports — not a second implementation. Gating
55
+ something that is not a subtree (a menu entry, a row action, a `disabled`
56
+ attribute) now reaches the comparison from the subpath the guard already
57
+ comes from.
58
+
59
+ ### Changed
60
+
61
+ - `security-panel` gates its audit-log read with `minimumRole="admin"` rather
62
+ than `roles={["admin"]}`. Behaviour is identical; the copied file and the
63
+ `registry/r` output both change, so a consumer re-adding the block picks up
64
+ the new spelling.
65
+ - `compatibility.test.ts` now pins the published `faAuthM8` package-metadata
66
+ block against the `compatibility.ts` constants, so the machine-readable half
67
+ of the contract claim cannot drift from the half the browser preflight
68
+ enforces.
69
+
9
70
  ## 2.0.0
10
71
 
11
72
  Aligns the plugin with the `fa-auth-m8@2.0` contract (service `2.0.0`,
package/README.md CHANGED
@@ -52,6 +52,19 @@ hasSuperuserPrivileges(user.role, user.is_superuser);
52
52
 
53
53
  The valid role/flag pairs are `superadmin` with `is_superuser: true`, and every other role with `is_superuser: false`. `privilegeClaimsAreConsistent` exposes that invariant on its own, and `ORDERED_ROLES` exposes the hierarchy, highest privilege first. Any other pair - including an unrecognised role - grants nothing. These are display predicates; the backend stays the authority.
54
54
 
55
+ All four are also re-exported from `@mano8/astro-auth-m8/react`, as the same bindings, so a consumer gating something that is not a subtree - a menu entry, a table row action, a `disabled` attribute - reaches the comparison from the subpath it already imports `RequireRole` from. Wherever a subtree *is* what you are gating, `RequireRole` is the shorter spelling:
56
+
57
+ ```tsx
58
+ import { RequireRole } from "@mano8/astro-auth-m8/react";
59
+
60
+ // Minimum-role mode: at least admin, so a superadmin is admitted too.
61
+ <RequireRole minimumRole="admin" fallback={<p>Admin access required.</p>}>
62
+ <AuditLog />
63
+ </RequireRole>
64
+ ```
65
+
66
+ `minimumRole` is the form to reach for: it says what the backend dependency says. `roles={[...]}` remains for a guard that genuinely accepts several unrelated tiers - each entry is a floor there too, so `roles={["admin"]}` and `minimumRole="admin"` decide identically, but the array reads as exact membership and invites hand-enumeration. `superuser` is the separate dual-evidence gate. A guard may carry more than one mode and grants on the first that holds; one carrying none grants nothing.
67
+
55
68
  ## Error presentation
56
69
 
57
70
  `@mano8/astro-auth-m8/errors` exports `ApiError` plus `describeApiError(error, fallback)`, which maps the `fa-auth-m8` 2.0.0 authorization/rate-limit/retention error contracts to an operator-readable `{ title, description? }` (used by the `errorMessage` helper in the account registry blocks):
@@ -64,6 +77,28 @@ const { title, description } = describeApiError(error, "Update failed");
64
77
 
65
78
  `409` `last_superuser_required` is labelled (the raw token is never surfaced); `403` is titled by status (`Not permitted`) with the backend's own readable detail as the description, since several surfaces produce a `403` and the detail that distinguishes them is not a stable contract; `429` and `503` are distinguished (rate limited vs. an unknown outcome that must not be retried); `400` free-text detail (e.g. a purge's retention-floor rejection) is surfaced verbatim under a labelled heading rather than pattern-matched.
66
79
 
80
+ ### Island error boundaries
81
+
82
+ Every starter island root is wrapped in `AuthErrorBoundary`, exported from
83
+ `@mano8/astro-auth-m8/react`. Its default fallback deliberately hides the
84
+ caught message so a token fragment, username, or API URL cannot leak onto a
85
+ public auth page. Applications can replace the fallback, report the error, or
86
+ reset the boundary when route-specific keys change:
87
+
88
+ ```tsx
89
+ import { AuthErrorBoundary } from "@mano8/astro-auth-m8/react";
90
+
91
+ <AuthErrorBoundary
92
+ onError={(error, info) => reportAuthViewError(error, info)}
93
+ resetKeys={[locale]}
94
+ >
95
+ <AuthView />
96
+ </AuthErrorBoundary>
97
+ ```
98
+
99
+ The retry action resets the failed subtree; it does not automatically repeat a
100
+ request whose outcome may be unknown.
101
+
67
102
  ## Admin API-key and security surfaces (fa-auth-m8 2.0.0)
68
103
 
69
104
  `@mano8/astro-auth-m8/api` and `@mano8/astro-auth-m8/hooks` wrap the five 2.0.0 admin routes:
@@ -100,6 +135,11 @@ A mounted `AuthProvider` listens for it and, when the id is the signed-in princi
100
135
  - `starter`: injects small default login, logout, callback, and account routes with `injectRoute()`.
101
136
  - `scaffold`: copies editable Astro/React/CSS files into a consumer app with `astro-auth-m8 scaffold --views --target src/auth`.
102
137
 
138
+ For package development, `npm run preview:dev` serves a dev-only `/_preview`
139
+ gallery backed by a deterministic browser stub. `npm run preview:build` runs
140
+ the typecheck-and-bundle gate used by CI; the preview is a repository fixture
141
+ and is not shipped as a consumer route.
142
+
103
143
  ```ts
104
144
  import { defineConfig } from "astro/config";
105
145
  import react from "@astrojs/react";
@@ -152,7 +192,7 @@ Install `@mano8/astro-auth-m8` from npm first, then consume the registry as a **
152
192
 
153
193
  `dashboard-overview` is the landing view; `profile-panel`, `sessions-panel`, `api-keys-panel`, `admin-users-panel`, and `security-panel` are the secondary account tabs (drop them into `account-dashboard`'s `extraTabs`, or into your own shell). Each reads its headless logic straight from the package hooks - no local adapter layer - and takes its strings via `labels`. `api-keys-panel` and `admin-users-panel` use the canonical `astro-ui-m8` data-table with client-side search, sorting, pagination, column visibility, and row selection. Their shared `account-crud` dependency is installed automatically; it supplies the popup form, destructive-action confirmation, fixed row actions, and bottom-right toast host. `admin-users-panel` self-gates with `RequireRole superuser`.
154
194
 
155
- `security-panel` carries both 2.0.0 admin tiers in one tab and gates them differently, mirroring the service: the audit log is behind `RequireRole roles={["admin"]}` (role hierarchy alone, so an admin sees its own surface and a superadmin is admitted too) and the two retention purges are behind `RequireRole superuser` (dual evidence). Each purge picks its window from the closed `RetentionWindowSchema` enum and runs only through a confirmation that names what is deleted and that a window below the service's retention floor is refused - the floor is server-side configuration published by no endpoint, so the service's rejection is surfaced verbatim instead of pre-validated. A `503` locks the purge control and reports the outcome as *unknown* until the operator explicitly acknowledges having checked, so the next click can never be a blind retry. Drop it into `account-dashboard`'s `extraTabs` with `minRole: "admin"`.
195
+ `security-panel` carries both 2.0.0 admin tiers in one tab and gates them differently, mirroring the service: the audit log is behind `RequireRole minimumRole="admin"` (role hierarchy alone, so an admin sees its own surface and a superadmin is admitted too) and the two retention purges are behind `RequireRole superuser` (dual evidence). Each purge picks its window from the closed `RetentionWindowSchema` enum and runs only through a confirmation that names what is deleted and that a window below the service's retention floor is refused - the floor is server-side configuration published by no endpoint, so the service's rejection is surfaced verbatim instead of pre-validated. A `503` locks the purge control and reports the outcome as *unknown* until the operator explicitly acknowledges having checked, so the next click can never be a blind retry. Drop it into `account-dashboard`'s `extraTabs` with `minRole: "admin"`.
156
196
 
157
197
  Files land under `src/components/fa-auth/` (the items' `target`), import shadcn primitives via `@/components/ui/*`, and pull headless logic from the installed package. The plugin package is intentionally **not** listed in registry item `dependencies`; install the published `@mano8/astro-auth-m8` package from npm yourself so shadcn only copies the skin files.
158
198
 
@@ -0,0 +1,53 @@
1
+ import * as React from "react";
2
+ /**
3
+ * Island-root error boundary for the auth plugin (`A-C3`).
4
+ *
5
+ * Every auth view is mounted as an Astro island. A render throw anywhere inside
6
+ * one unmounts the entire island tree, so the route is left with a blank region
7
+ * and a console trace. On this plugin that lands harder than elsewhere: the
8
+ * blanked island is the login form, and a user with no visible way to sign in
9
+ * has no way to reach any other plugin either.
10
+ *
11
+ * A class on purpose: `getDerivedStateFromError`/`componentDidCatch` still have
12
+ * no hook equivalent.
13
+ *
14
+ * The prop contract mirrors `@mano8/astro-ui-m8`'s canonical `error-boundary`
15
+ * registry block deliberately, so the two can be collapsed onto one
16
+ * implementation once that block is reachable from this package. It is not
17
+ * reachable today: the block ships in an unpublished `astro-ui-m8`, and copied
18
+ * registry items are consumer-side artifacts rather than package runtime.
19
+ */
20
+ export interface AuthErrorBoundaryFallbackProps {
21
+ error: Error;
22
+ reset: () => void;
23
+ }
24
+ export interface AuthErrorBoundaryLabels {
25
+ title: string;
26
+ description: string;
27
+ retry: string;
28
+ }
29
+ export interface AuthErrorBoundaryProps {
30
+ children: React.ReactNode;
31
+ /** Replaces the default surface. Receives the error and a `reset`. */
32
+ fallback?: (props: AuthErrorBoundaryFallbackProps) => React.ReactNode;
33
+ /** Reporting hook. The boundary never logs on its own. */
34
+ onError?: (error: Error, info: {
35
+ componentStack: string;
36
+ }) => void;
37
+ /** Clears the boundary when any member changes, compared by `Object.is`. */
38
+ resetKeys?: readonly unknown[];
39
+ labels?: Partial<AuthErrorBoundaryLabels>;
40
+ }
41
+ interface AuthErrorBoundaryState {
42
+ error: Error | null;
43
+ }
44
+ export declare class AuthErrorBoundary extends React.Component<AuthErrorBoundaryProps, AuthErrorBoundaryState> {
45
+ state: AuthErrorBoundaryState;
46
+ static getDerivedStateFromError(thrown: unknown): AuthErrorBoundaryState;
47
+ componentDidCatch(thrown: unknown, info: React.ErrorInfo): void;
48
+ componentDidUpdate(previous: AuthErrorBoundaryProps): void;
49
+ reset: () => void;
50
+ render(): React.ReactNode;
51
+ }
52
+ export {};
53
+ //# sourceMappingURL=AuthErrorBoundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthErrorBoundary.d.ts","sourceRoot":"","sources":["../../../../src/runtime/react/AuthErrorBoundary.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,8BAA8B;IAC7C,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAQD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,sEAAsE;IACtE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,8BAA8B,KAAK,KAAK,CAAC,SAAS,CAAC;IACtE,0DAA0D;IAC1D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACnE,4EAA4E;IAC5E,SAAS,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;IAC/B,MAAM,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,CAAC;CAC3C;AAED,UAAU,sBAAsB;IAC9B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAkBD,qBAAa,iBAAkB,SAAQ,KAAK,CAAC,SAAS,CACpD,sBAAsB,EACtB,sBAAsB,CACvB;IACU,KAAK,EAAE,sBAAsB,CAAmB;IAEzD,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,sBAAsB;IAI/D,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,SAAS,GAAG,IAAI;IAM/D,kBAAkB,CAAC,QAAQ,EAAE,sBAAsB,GAAG,IAAI;IAMnE,KAAK,QAAO,IAAI,CAEd;IAEO,MAAM,IAAI,KAAK,CAAC,SAAS;CAkCnC"}
@@ -0,0 +1,58 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ const DEFAULT_LABELS = {
4
+ title: "This view stopped responding",
5
+ description: "The page hit an unexpected error and could not finish rendering.",
6
+ retry: "Reload this view"
7
+ };
8
+ /** `throw "boom"` is legal, so normalize before handing anything on. */
9
+ function toError(thrown) {
10
+ if (thrown instanceof Error)
11
+ return thrown;
12
+ if (typeof thrown === "string")
13
+ return new Error(thrown);
14
+ return new Error("The view failed to render.");
15
+ }
16
+ function resetKeysChanged(previous, next) {
17
+ if (previous === undefined || next === undefined)
18
+ return false;
19
+ if (previous.length !== next.length)
20
+ return true;
21
+ return previous.some((value, index) => !Object.is(value, next[index]));
22
+ }
23
+ export class AuthErrorBoundary extends React.Component {
24
+ state = { error: null };
25
+ static getDerivedStateFromError(thrown) {
26
+ return { error: toError(thrown) };
27
+ }
28
+ componentDidCatch(thrown, info) {
29
+ this.props.onError?.(toError(thrown), {
30
+ componentStack: info.componentStack ?? ""
31
+ });
32
+ }
33
+ componentDidUpdate(previous) {
34
+ if (this.state.error === null)
35
+ return;
36
+ if (!resetKeysChanged(previous.resetKeys, this.props.resetKeys))
37
+ return;
38
+ this.reset();
39
+ }
40
+ reset = () => {
41
+ this.setState({ error: null });
42
+ };
43
+ render() {
44
+ const { error } = this.state;
45
+ if (error === null)
46
+ return this.props.children;
47
+ if (this.props.fallback) {
48
+ return this.props.fallback({ error, reset: this.reset });
49
+ }
50
+ const labels = { ...DEFAULT_LABELS, ...this.props.labels };
51
+ // The caught message is deliberately not rendered. That matters more here
52
+ // than in the other plugins: a throw on this surface can carry a username,
53
+ // a token fragment or an API URL, and the login page is the one view an
54
+ // unauthenticated stranger can always reach.
55
+ return (_jsxs("section", { className: "not-content fa-auth-panel mx-auto flex w-full max-w-md flex-col gap-4 rounded-2xl border border-border/70 bg-card/95 p-6 text-card-foreground shadow-sm", "data-auth-error-boundary": "fallback", children: [_jsx("h1", { className: "text-3xl font-semibold tracking-tight text-foreground", children: labels.title }), _jsx("p", { role: "alert", className: "text-sm text-muted-foreground", children: labels.description }), _jsx("button", { type: "button", className: "inline-flex min-h-10 items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground", "data-auth-error-boundary-retry": "", onClick: this.reset, children: labels.retry })] }));
56
+ }
57
+ }
58
+ //# sourceMappingURL=AuthErrorBoundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthErrorBoundary.js","sourceRoot":"","sources":["../../../../src/runtime/react/AuthErrorBoundary.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AA+B/B,MAAM,cAAc,GAA4B;IAC9C,KAAK,EAAE,8BAA8B;IACrC,WAAW,EAAE,kEAAkE;IAC/E,KAAK,EAAE,kBAAkB;CAC1B,CAAC;AAiBF,wEAAwE;AACxE,SAAS,OAAO,CAAC,MAAe;IAC9B,IAAI,MAAM,YAAY,KAAK;QAAE,OAAO,MAAM,CAAC;IAC3C,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;IACzD,OAAO,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,gBAAgB,CACvB,QAAwC,EACxC,IAAoC;IAEpC,IAAI,QAAQ,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAC/D,IAAI,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACjD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,OAAO,iBAAkB,SAAQ,KAAK,CAAC,SAG5C;IACU,KAAK,GAA2B,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAEzD,MAAM,CAAC,wBAAwB,CAAC,MAAe;QAC7C,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;IACpC,CAAC;IAEQ,iBAAiB,CAAC,MAAe,EAAE,IAAqB;QAC/D,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACpC,cAAc,EAAE,IAAI,CAAC,cAAc,IAAI,EAAE;SAC1C,CAAC,CAAC;IACL,CAAC;IAEQ,kBAAkB,CAAC,QAAgC;QAC1D,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,IAAI;YAAE,OAAO;QACtC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;YAAE,OAAO;QACxE,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAED,KAAK,GAAG,GAAS,EAAE;QACjB,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACjC,CAAC,CAAC;IAEO,MAAM;QACb,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAC7B,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;QAE/C,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAC3D,CAAC;QAED,MAAM,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QAE3D,0EAA0E;QAC1E,2EAA2E;QAC3E,wEAAwE;QACxE,6CAA6C;QAC7C,OAAO,CACL,mBACE,SAAS,EAAC,yJAAyJ,8BAC1I,UAAU,aAEnC,aAAI,SAAS,EAAC,uDAAuD,YAAE,MAAM,CAAC,KAAK,GAAM,EACzF,YAAG,IAAI,EAAC,OAAO,EAAC,SAAS,EAAC,+BAA+B,YACtD,MAAM,CAAC,WAAW,GACjB,EACJ,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,8HAA8H,oCACzG,EAAE,EACjC,OAAO,EAAE,IAAI,CAAC,KAAK,YAElB,MAAM,CAAC,KAAK,GACN,IACD,CACX,CAAC;IACJ,CAAC;CACF"}
@@ -1,9 +1,46 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { RoleType } from "../schemas.js";
3
- export declare function RequireRole({ children, roles, superuser, fallback }: {
3
+ export type RequireRoleProps = {
4
4
  children: ReactNode;
5
+ /**
6
+ * Minimum-role mode: render when the signed-in role meets or exceeds this
7
+ * one on the ordered hierarchy (`hasMinimumRole`).
8
+ *
9
+ * This is the form to reach for. `minimumRole="admin"` says what the backend
10
+ * dependency says - *at least* admin - where the equivalent `roles={["admin"]}`
11
+ * reads as exact membership and only behaves as a floor because this guard
12
+ * compares hierarchically. Consumers were hand-enumerating role arrays to
13
+ * express a floor; a single role is the honest spelling of it (`RBAC-06`).
14
+ */
15
+ minimumRole?: RoleType;
16
+ /**
17
+ * Any-of mode: render when the signed-in role meets or exceeds *any* listed
18
+ * role. Each entry is still a floor, not an exact match, so
19
+ * `roles={["admin"]}` admits a `superadmin`.
20
+ *
21
+ * Kept for guards that genuinely accept several unrelated tiers. For a single
22
+ * floor, prefer {@link minimumRole}.
23
+ */
5
24
  roles?: RoleType[];
25
+ /**
26
+ * Superuser mode: render only on dual evidence (`role === "superadmin"` and
27
+ * `is_superuser === true`), never on either claim alone.
28
+ */
6
29
  superuser?: boolean;
7
30
  fallback?: ReactNode;
8
- }): ReactNode;
31
+ };
32
+ /**
33
+ * Render `children` when the signed-in user satisfies any supplied mode.
34
+ *
35
+ * The modes are a union, evaluated independently, so a guard carrying more
36
+ * than one grants on the first that holds. With no mode supplied nothing is
37
+ * granted - an unqualified guard is a mistake, and failing closed makes it a
38
+ * visible one.
39
+ *
40
+ * Every comparison goes through `../authorization.js`, this package's single
41
+ * encoding of the hierarchy and of the `role`/`is_superuser` invariant. The
42
+ * backend remains the authority; this only keeps the UI from offering surfaces
43
+ * the service would refuse.
44
+ */
45
+ export declare function RequireRole({ children, minimumRole, roles, superuser, fallback }: RequireRoleProps): ReactNode;
9
46
  //# sourceMappingURL=RequireRole.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RequireRole.d.ts","sourceRoot":"","sources":["../../../../src/runtime/react/RequireRole.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,wBAAgB,WAAW,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAiB,EAAE,QAAe,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAC;IAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,aAM1K"}
1
+ {"version":3,"file":"RequireRole.d.ts","sourceRoot":"","sources":["../../../../src/runtime/react/RequireRole.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,SAAS,CAAC;IACpB;;;;;;;;;OASG;IACH,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,SAAiB,EAAE,QAAe,EAAE,EAAE,gBAAgB,aAOjH"}
@@ -1,11 +1,26 @@
1
1
  import { useAuth } from "./AuthProvider.js";
2
2
  import { hasMinimumRole, hasSuperuserPrivileges } from "../authorization.js";
3
- export function RequireRole({ children, roles, superuser = false, fallback = null }) {
3
+ /**
4
+ * Render `children` when the signed-in user satisfies any supplied mode.
5
+ *
6
+ * The modes are a union, evaluated independently, so a guard carrying more
7
+ * than one grants on the first that holds. With no mode supplied nothing is
8
+ * granted - an unqualified guard is a mistake, and failing closed makes it a
9
+ * visible one.
10
+ *
11
+ * Every comparison goes through `../authorization.js`, this package's single
12
+ * encoding of the hierarchy and of the `role`/`is_superuser` invariant. The
13
+ * backend remains the authority; this only keeps the UI from offering surfaces
14
+ * the service would refuse.
15
+ */
16
+ export function RequireRole({ children, minimumRole, roles, superuser = false, fallback = null }) {
4
17
  const { user, loading } = useAuth();
5
18
  if (loading || !user)
6
19
  return fallback;
7
20
  if (superuser && hasSuperuserPrivileges(user.role, user.is_superuser))
8
21
  return children;
22
+ if (minimumRole && hasMinimumRole(user.role, minimumRole))
23
+ return children;
9
24
  if (roles?.some((requiredRole) => hasMinimumRole(user.role, requiredRole)))
10
25
  return children;
11
26
  return fallback;
@@ -1 +1 @@
1
- {"version":3,"file":"RequireRole.js","sourceRoot":"","sources":["../../../../src/runtime/react/RequireRole.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7E,MAAM,UAAU,WAAW,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,GAAG,KAAK,EAAE,QAAQ,GAAG,IAAI,EAA0F;IACzK,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;IACpC,IAAI,OAAO,IAAI,CAAC,IAAI;QAAE,OAAO,QAAQ,CAAC;IACtC,IAAI,SAAS,IAAI,sBAAsB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC;QAAE,OAAO,QAAQ,CAAC;IACvF,IAAI,KAAK,EAAE,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC5F,OAAO,QAAQ,CAAC;AAClB,CAAC"}
1
+ {"version":3,"file":"RequireRole.js","sourceRoot":"","sources":["../../../../src/runtime/react/RequireRole.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAgC7E;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,GAAG,KAAK,EAAE,QAAQ,GAAG,IAAI,EAAoB;IAChH,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;IACpC,IAAI,OAAO,IAAI,CAAC,IAAI;QAAE,OAAO,QAAQ,CAAC;IACtC,IAAI,SAAS,IAAI,sBAAsB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC;QAAE,OAAO,QAAQ,CAAC;IACvF,IAAI,WAAW,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC3E,IAAI,KAAK,EAAE,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC5F,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"CallbackView.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/CallbackView.tsx"],"names":[],"mappings":"AAQA,wBAAgB,YAAY,gCAyB3B"}
1
+ {"version":3,"file":"CallbackView.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/CallbackView.tsx"],"names":[],"mappings":"AASA,wBAAgB,YAAY,gCA8B3B"}
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useEffect, useState } from "react";
3
3
  import { exchangeGoogleCode, takePkceVerifier } from "../../api/oauth.js";
4
+ import { AuthErrorBoundary } from "../AuthErrorBoundary.js";
4
5
  export function CallbackView() {
5
6
  const [state, setState] = useState({ message: "Completing sign in", role: "status" });
6
7
  useEffect(() => {
@@ -17,6 +18,9 @@ export function CallbackView() {
17
18
  })
18
19
  .catch(() => setState({ message: "Unable to complete OAuth sign in.", role: "alert" }));
19
20
  }, []);
20
- return (_jsx("section", { className: "not-content fa-auth-panel mx-auto flex w-full max-w-md flex-col gap-4 rounded-2xl border border-border/70 bg-card/95 p-6 text-card-foreground shadow-sm backdrop-blur supports-[backdrop-filter]:bg-card/90", children: _jsx("p", { className: state.role === "alert" ? "text-sm text-destructive" : "text-sm text-muted-foreground", role: state.role, children: state.message }) }));
21
+ // Wrapped here rather than at the route, because this view *is* the island
22
+ // root `callback.astro` mounts (`A-C3`). A headless consumer that renders it
23
+ // directly gets the same protection.
24
+ return (_jsx(AuthErrorBoundary, { children: _jsx("section", { className: "not-content fa-auth-panel mx-auto flex w-full max-w-md flex-col gap-4 rounded-2xl border border-border/70 bg-card/95 p-6 text-card-foreground shadow-sm backdrop-blur supports-[backdrop-filter]:bg-card/90", children: _jsx("p", { className: state.role === "alert" ? "text-sm text-destructive" : "text-sm text-muted-foreground", role: state.role, children: state.message }) }) }));
21
25
  }
22
26
  //# sourceMappingURL=CallbackView.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CallbackView.js","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/CallbackView.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAO1E,MAAM,UAAU,YAAY;IAC1B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,EAAE,OAAO,EAAE,oBAAoB,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IAErG,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC1C,MAAM,IAAI,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC1C,MAAM,QAAQ,GAAG,gBAAgB,EAAE,CAAC;QACpC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACvB,QAAQ,CAAC,EAAE,OAAO,EAAE,2CAA2C,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;YAClF,OAAO;QACT,CAAC;QACD,kBAAkB,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC;aAClD,IAAI,CAAC,GAAG,EAAE;YACT,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;QAC5C,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,mCAAmC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAC5F,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,kBAAS,SAAS,EAAC,6MAA6M,YAC9N,YAAG,SAAS,EAAE,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,+BAA+B,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,YAClH,KAAK,CAAC,OAAO,GACZ,GACI,CACX,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"CallbackView.js","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/CallbackView.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAO5D,MAAM,UAAU,YAAY;IAC1B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,EAAE,OAAO,EAAE,oBAAoB,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IAErG,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC1C,MAAM,IAAI,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC1C,MAAM,QAAQ,GAAG,gBAAgB,EAAE,CAAC;QACpC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACvB,QAAQ,CAAC,EAAE,OAAO,EAAE,2CAA2C,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;YAClF,OAAO;QACT,CAAC;QACD,kBAAkB,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC;aAClD,IAAI,CAAC,GAAG,EAAE;YACT,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;QAC5C,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,mCAAmC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAC5F,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,2EAA2E;IAC3E,6EAA6E;IAC7E,qCAAqC;IACrC,OAAO,CACL,KAAC,iBAAiB,cAClB,kBAAS,SAAS,EAAC,6MAA6M,YAC9N,YAAG,SAAS,EAAE,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,+BAA+B,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,YAClH,KAAK,CAAC,OAAO,GACZ,GACI,GACU,CACrB,CAAC;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"SignupView.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/SignupView.tsx"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,gCASzB"}
1
+ {"version":3,"file":"SignupView.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/SignupView.tsx"],"names":[],"mappings":"AAIA,wBAAgB,UAAU,gCAWzB"}
@@ -1,5 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { AuthErrorBoundary } from "../AuthErrorBoundary.js";
3
+ // Wrapped here rather than at the route, because this view *is* the island
4
+ // root `signup.astro` mounts (`A-C3`).
2
5
  export function SignupView() {
3
- return (_jsxs("section", { className: "not-content fa-auth-panel mx-auto flex w-full max-w-md flex-col gap-4 rounded-2xl border border-border/70 bg-card/95 p-6 text-card-foreground shadow-sm backdrop-blur supports-[backdrop-filter]:bg-card/90", children: [_jsx("h1", { className: "text-3xl font-semibold tracking-tight text-foreground", children: "Signup unavailable" }), _jsx("p", { className: "text-sm text-muted-foreground", children: "This backend protects public signup by default. Use the headless user APIs for admin-created users." })] }));
6
+ return (_jsx(AuthErrorBoundary, { children: _jsxs("section", { className: "not-content fa-auth-panel mx-auto flex w-full max-w-md flex-col gap-4 rounded-2xl border border-border/70 bg-card/95 p-6 text-card-foreground shadow-sm backdrop-blur supports-[backdrop-filter]:bg-card/90", children: [_jsx("h1", { className: "text-3xl font-semibold tracking-tight text-foreground", children: "Signup unavailable" }), _jsx("p", { className: "text-sm text-muted-foreground", children: "This backend protects public signup by default. Use the headless user APIs for admin-created users." })] }) }));
4
7
  }
5
8
  //# sourceMappingURL=SignupView.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SignupView.js","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/SignupView.tsx"],"names":[],"mappings":";AAAA,MAAM,UAAU,UAAU;IACxB,OAAO,CACL,mBAAS,SAAS,EAAC,6MAA6M,aAC9N,aAAI,SAAS,EAAC,uDAAuD,mCAAwB,EAC7F,YAAG,SAAS,EAAC,+BAA+B,oHAExC,IACI,CACX,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"SignupView.js","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/SignupView.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,2EAA2E;AAC3E,uCAAuC;AACvC,MAAM,UAAU,UAAU;IACxB,OAAO,CACL,KAAC,iBAAiB,cAClB,mBAAS,SAAS,EAAC,6MAA6M,aAC9N,aAAI,SAAS,EAAC,uDAAuD,mCAAwB,EAC7F,YAAG,SAAS,EAAC,+BAA+B,oHAExC,IACI,GACU,CACrB,CAAC;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"StarterAccountPage.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/StarterAccountPage.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGzD,wBAAgB,kBAAkB,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAA;CAAE,+BAMrF"}
1
+ {"version":3,"file":"StarterAccountPage.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/StarterAccountPage.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAKzD,wBAAgB,kBAAkB,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAA;CAAE,+BAQrF"}
@@ -1,7 +1,10 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { AuthProvider } from "../AuthProvider.js";
3
+ import { AuthErrorBoundary } from "../AuthErrorBoundary.js";
3
4
  import { AccountView } from "./AccountView.js";
5
+ // The boundary is the outermost wrapper on purpose (`A-C3`); see
6
+ // StarterLoginPage for why it sits outside `AuthProvider`.
4
7
  export function StarterAccountPage({ config }) {
5
- return (_jsx(AuthProvider, { config: config, children: _jsx(AccountView, {}) }));
8
+ return (_jsx(AuthErrorBoundary, { children: _jsx(AuthProvider, { config: config, children: _jsx(AccountView, {}) }) }));
6
9
  }
7
10
  //# sourceMappingURL=StarterAccountPage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"StarterAccountPage.js","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/StarterAccountPage.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,UAAU,kBAAkB,CAAC,EAAE,MAAM,EAA2C;IACpF,OAAO,CACL,KAAC,YAAY,IAAC,MAAM,EAAE,MAAM,YAC1B,KAAC,WAAW,KAAG,GACF,CAChB,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"StarterAccountPage.js","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/StarterAccountPage.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,iEAAiE;AACjE,2DAA2D;AAC3D,MAAM,UAAU,kBAAkB,CAAC,EAAE,MAAM,EAA2C;IACpF,OAAO,CACL,KAAC,iBAAiB,cAChB,KAAC,YAAY,IAAC,MAAM,EAAE,MAAM,YAC1B,KAAC,WAAW,KAAG,GACF,GACG,CACrB,CAAC;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"StarterLoginPage.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/StarterLoginPage.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGzD,wBAAgB,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAA;CAAE,+BAMnF"}
1
+ {"version":3,"file":"StarterLoginPage.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/StarterLoginPage.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAMzD,wBAAgB,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAA;CAAE,+BAQnF"}
@@ -1,7 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { AuthProvider } from "../AuthProvider.js";
3
+ import { AuthErrorBoundary } from "../AuthErrorBoundary.js";
3
4
  import { LoginView } from "./LoginView.js";
5
+ // The boundary is the outermost wrapper on purpose (`A-C3`). `AuthProvider`
6
+ // calls `configureAuth` in its own body, so a boundary mounted inside it would
7
+ // be unmounted by exactly the throw most likely to happen here.
4
8
  export function StarterLoginPage({ config }) {
5
- return (_jsx(AuthProvider, { config: config, children: _jsx(LoginView, {}) }));
9
+ return (_jsx(AuthErrorBoundary, { children: _jsx(AuthProvider, { config: config, children: _jsx(LoginView, {}) }) }));
6
10
  }
7
11
  //# sourceMappingURL=StarterLoginPage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"StarterLoginPage.js","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/StarterLoginPage.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,UAAU,gBAAgB,CAAC,EAAE,MAAM,EAA2C;IAClF,OAAO,CACL,KAAC,YAAY,IAAC,MAAM,EAAE,MAAM,YAC1B,KAAC,SAAS,KAAG,GACA,CAChB,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"StarterLoginPage.js","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/StarterLoginPage.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,4EAA4E;AAC5E,+EAA+E;AAC/E,gEAAgE;AAChE,MAAM,UAAU,gBAAgB,CAAC,EAAE,MAAM,EAA2C;IAClF,OAAO,CACL,KAAC,iBAAiB,cAChB,KAAC,YAAY,IAAC,MAAM,EAAE,MAAM,YAC1B,KAAC,SAAS,KAAG,GACA,GACG,CACrB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { ReactNode } from "react";
2
+ import type { AuthRuntimeConfig } from "../../config.js";
3
+ /**
4
+ * Island root for `logout.astro` (`A-C3`).
5
+ *
6
+ * The route used to mount `AuthProvider` itself, which left the one island with
7
+ * no boundary above it — and a boundary *inside* `AuthProvider` would not help,
8
+ * because `configureAuth` runs in that component's own body. Wrapping there is
9
+ * the whole point, so the route mounts this instead.
10
+ *
11
+ * It is deliberately a pass-through for children: the sign-out form is authored
12
+ * as markup in the `.astro` route and arrives here as slot content, so this
13
+ * component adds the boundary and the provider without claiming ownership of
14
+ * the page's copy.
15
+ */
16
+ export declare function StarterLogoutPage({ children, config }: {
17
+ children?: ReactNode;
18
+ config?: Partial<AuthRuntimeConfig>;
19
+ }): import("react").JSX.Element;
20
+ //# sourceMappingURL=StarterLogoutPage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StarterLogoutPage.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/StarterLogoutPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,MAAM,EACP,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACrC,+BAMA"}
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { AuthProvider } from "../AuthProvider.js";
3
+ import { AuthErrorBoundary } from "../AuthErrorBoundary.js";
4
+ /**
5
+ * Island root for `logout.astro` (`A-C3`).
6
+ *
7
+ * The route used to mount `AuthProvider` itself, which left the one island with
8
+ * no boundary above it — and a boundary *inside* `AuthProvider` would not help,
9
+ * because `configureAuth` runs in that component's own body. Wrapping there is
10
+ * the whole point, so the route mounts this instead.
11
+ *
12
+ * It is deliberately a pass-through for children: the sign-out form is authored
13
+ * as markup in the `.astro` route and arrives here as slot content, so this
14
+ * component adds the boundary and the provider without claiming ownership of
15
+ * the page's copy.
16
+ */
17
+ export function StarterLogoutPage({ children, config }) {
18
+ return (_jsx(AuthErrorBoundary, { children: _jsx(AuthProvider, { config: config, children: children }) }));
19
+ }
20
+ //# sourceMappingURL=StarterLogoutPage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StarterLogoutPage.js","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/StarterLogoutPage.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAChC,QAAQ,EACR,MAAM,EAIP;IACC,OAAO,CACL,KAAC,iBAAiB,cAChB,KAAC,YAAY,IAAC,MAAM,EAAE,MAAM,YAAG,QAAQ,GAAgB,GACrC,CACrB,CAAC;AACJ,CAAC"}
@@ -5,4 +5,5 @@ export * from "./LoginView.js";
5
5
  export * from "./SignupView.js";
6
6
  export * from "./StarterAccountPage.js";
7
7
  export * from "./StarterLoginPage.js";
8
+ export * from "./StarterLogoutPage.js";
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC"}
@@ -5,4 +5,5 @@ export * from "./LoginView.js";
5
5
  export * from "./SignupView.js";
6
6
  export * from "./StarterAccountPage.js";
7
7
  export * from "./StarterLoginPage.js";
8
+ export * from "./StarterLogoutPage.js";
8
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/runtime/react/default-ui/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC"}
@@ -1,6 +1,8 @@
1
1
  export { AUTH_REVOCATION_EVENT, emitAuthRevocation, type AuthRevocationDetail } from "../authEvents.js";
2
2
  export * from "./AuthQueryProvider.js";
3
3
  export * from "./AuthProvider.js";
4
+ export * from "./AuthErrorBoundary.js";
4
5
  export * from "./RequireAuth.js";
5
6
  export * from "./RequireRole.js";
7
+ export { ORDERED_ROLES, hasMinimumRole, hasSuperuserPrivileges, privilegeClaimsAreConsistent } from "../authorization.js";
6
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/react/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxG,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/react/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxG,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AAOjC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,sBAAsB,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC"}
@@ -4,6 +4,14 @@
4
4
  export { AUTH_REVOCATION_EVENT, emitAuthRevocation } from "../authEvents.js";
5
5
  export * from "./AuthQueryProvider.js";
6
6
  export * from "./AuthProvider.js";
7
+ export * from "./AuthErrorBoundary.js";
7
8
  export * from "./RequireAuth.js";
8
9
  export * from "./RequireRole.js";
10
+ // The hierarchy primitives, re-exported alongside `RequireRole` so a consumer
11
+ // gating something that is not a subtree - a menu entry, a table row action, a
12
+ // disabled attribute - reaches the same comparison from the same subpath it
13
+ // already imports the guard from, instead of hand-rolling a role-ordered list
14
+ // (`RBAC-06`). `./authorization` remains the framework-neutral home; these are
15
+ // the same bindings, not a second implementation.
16
+ export { ORDERED_ROLES, hasMinimumRole, hasSuperuserPrivileges, privilegeClaimsAreConsistent } from "../authorization.js";
9
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtime/react/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,gFAAgF;AAChF,uDAAuD;AACvD,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAA6B,MAAM,kBAAkB,CAAC;AACxG,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtime/react/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,gFAAgF;AAChF,uDAAuD;AACvD,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAA6B,MAAM,kBAAkB,CAAC;AACxG,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,8EAA8E;AAC9E,+EAA+E;AAC/E,4EAA4E;AAC5E,8EAA8E;AAC9E,+EAA+E;AAC/E,kDAAkD;AAClD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,sBAAsB,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mano8/astro-auth-m8",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Astro integration and headless client for fa-auth-m8.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -55,14 +55,20 @@
55
55
  "scripts": {
56
56
  "build": "tsc -p tsconfig.json && npm run build:registry",
57
57
  "build:registry": "node scripts/build-registry.mjs",
58
+ "preview:dev": "vite --config fixtures/preview/vite.config.ts",
59
+ "preview:build": "tsc -p fixtures/preview/tsconfig.json --noEmit && vite build --config fixtures/preview/vite.config.ts",
60
+ "verify:fleet-gates": "node scripts/verify-fleet-gates.mjs",
61
+ "verify:registry-consumer": "node scripts/verify-registry-consumer.mjs",
62
+ "verify:registry-drift": "node scripts/verify-registry-drift.mjs",
58
63
  "verify:starter-routes": "node scripts/verify-starter-routes.mjs",
64
+ "verify:tarball-install": "node scripts/verify-tarball-install.mjs",
59
65
  "test": "vitest run --coverage",
60
66
  "typecheck": "tsc -p tsconfig.json --noEmit",
61
- "lint": "eslint \"src/**/*.{ts,tsx}\"",
67
+ "lint": "eslint .",
62
68
  "test:unit": "vitest run"
63
69
  },
64
70
  "dependencies": {
65
- "@mano8/astro-ui-m8": "^1.4.1"
71
+ "@mano8/astro-ui-m8": "^1.5.0"
66
72
  },
67
73
  "peerDependencies": {
68
74
  "@astrojs/react": "^6.0.1",
@@ -76,9 +82,10 @@
76
82
  "devDependencies": {
77
83
  "@astrojs/react": "^6.0.1",
78
84
  "@astrojs/starlight": "^0.41.3",
79
- "@eslint/js": "^10.0.1",
80
85
  "@eslint-react/eslint-plugin": "^5.18.0",
86
+ "@eslint/js": "^10.0.1",
81
87
  "@tanstack/react-query": "5.101.1",
88
+ "@tanstack/react-table": "^8.21.3",
82
89
  "@types/node": "^22.0.0",
83
90
  "@types/react": "^19.0.0",
84
91
  "@typescript-eslint/eslint-plugin": "^8.65.0",
@@ -13,7 +13,7 @@
13
13
  "files": [
14
14
  {
15
15
  "path": "registry/blocks/account/account-dashboard.tsx",
16
- "content": "\"use client\";\n\n// fa-auth account view whose FIRST/landing tab is the activity dashboard.\n// Headless auth state comes from the package (@mano8/astro-auth-m8/react); this\n// file is only the shadcn skin and is copied into the consumer via the\n// @fa-m8-auth registry. Secondary tabs (profile/sessions/api-keys/admin) are\n// passed in by the consumer via `extraTabs`, so locale + app-specific panels\n// stay owned by the app. Edit freely per app.\nimport * as React from \"react\";\nimport { LayoutDashboard, LogOut } from \"lucide-react\";\nimport {\n AuthProvider,\n useAuth,\n type AuthContextValue,\n} from \"@mano8/astro-auth-m8/react\";\nimport {\n hasMinimumRole,\n hasSuperuserPrivileges,\n} from \"@mano8/astro-auth-m8/authorization\";\nimport type { RoleType } from \"@mano8/astro-auth-m8/schemas\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { Skeleton } from \"@/components/ui/skeleton\";\nimport {\n NavigationMenu,\n NavigationMenuItem,\n NavigationMenuList,\n} from \"@/components/ui/navigation-menu\";\nimport {\n DashboardOverview,\n type DashboardOverviewLabels,\n} from \"@/components/fa-auth/dashboard-overview\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface AccountTab {\n id: string;\n label: string;\n icon?: React.ComponentType<{ className?: string }>;\n content: React.ReactNode;\n /** Only render this tab when the signed-in user is a superuser. */\n superuserOnly?: boolean;\n /**\n * Only render this tab when the signed-in user holds at least this role.\n * Uses the ordered hierarchy, so `minRole: \"admin\"` also admits a superadmin.\n * This is the admin tier: `fa-auth-m8` 2.0.0 authorizes the audit-log read\n * from the role hierarchy alone, so gating it with `superuserOnly` would hide\n * an admin's own surface from them.\n */\n minRole?: RoleType;\n}\n\nexport interface AccountDashboardLabels {\n dashboardTab: string;\n signOut: string;\n signInRequired: string;\n dashboard: Partial<DashboardOverviewLabels>;\n}\n\nconst DEFAULT_LABELS: AccountDashboardLabels = {\n dashboardTab: \"Dashboard\",\n signOut: \"Sign out\",\n signInRequired: \"Please sign in to view your account.\",\n dashboard: {},\n};\n\nexport interface AccountDashboardProps {\n /** Auth API base path; defaults to PUBLIC_FA_AUTH_API_BASE or \"/user\". */\n apiBase?: string;\n /** Dashboard scope: \"me\" (default) or \"global\" for superuser fleet stats. */\n scope?: \"me\" | \"global\";\n extraTabs?: AccountTab[];\n labels?: Partial<AccountDashboardLabels>;\n /** Rendered when the user is not authenticated. */\n signIn?: React.ReactNode;\n}\n\nfunction AccountShell({\n scope,\n extraTabs,\n labels,\n signIn,\n}: Required<Pick<AccountDashboardProps, \"scope\" | \"extraTabs\">> & {\n labels: AccountDashboardLabels;\n signIn?: React.ReactNode;\n}) {\n const { user, loading, logout }: AuthContextValue = useAuth();\n\n if (loading) {\n return (\n <div className=\"not-content mx-auto w-full max-w-6xl space-y-4\" aria-busy=\"true\">\n <Skeleton className=\"h-10 w-64\" />\n <Skeleton className=\"h-9 w-full max-w-md\" />\n <Skeleton className=\"h-72 w-full\" />\n </div>\n );\n }\n\n if (!user) {\n return (\n <div className=\"not-content mx-auto w-full max-w-md py-10 text-center text-sm text-muted-foreground\">\n {signIn ?? labels.signInRequired}\n </div>\n );\n }\n\n // Two deliberately different predicates: `superuserOnly` needs dual evidence\n // (role + is_superuser), `minRole` is the role hierarchy alone - the same\n // split the backend makes between its superuser and admin dependencies.\n // Each is only a display gate; every panel still self-gates and the service\n // stays the authority.\n const visibleTabs = extraTabs.filter(\n (tab) =>\n (!tab.superuserOnly ||\n hasSuperuserPrivileges(user.role, user.is_superuser)) &&\n (!tab.minRole || hasMinimumRole(user.role, tab.minRole)),\n );\n const [activeTab, setActiveTab] = React.useState<string>(\"dashboard\");\n const navItems = [\n {\n id: \"dashboard\",\n label: labels.dashboardTab,\n icon: LayoutDashboard,\n content: <DashboardOverview scope={scope} labels={labels.dashboard} />,\n },\n ...visibleTabs,\n ];\n const columnClass = navItems.length >= 5 ? \"lg:grid-cols-5\" : \"lg:grid-cols-4\";\n\n return (\n <div className=\"not-content mx-auto flex w-full max-w-6xl flex-col gap-6\">\n <div className=\"flex flex-col gap-4 border-b pb-5 lg:flex-row lg:items-end lg:justify-between\">\n <div className=\"min-w-0 space-y-2\">\n <h1 className=\"text-2xl font-semibold tracking-tight md:text-3xl\">\n {user.email}\n </h1>\n <div className=\"flex flex-wrap items-center gap-2 text-sm text-muted-foreground\">\n <span className=\"rounded-md border px-2 py-0.5 text-xs uppercase tracking-wide\">\n {user.role}\n </span>\n {user.is_superuser ? (\n <span className=\"rounded-md border px-2 py-0.5 text-xs uppercase tracking-wide\">\n superuser\n </span>\n ) : null}\n </div>\n </div>\n <Button\n variant=\"outline\"\n onClick={() => void logout()}\n className=\"w-full justify-center gap-2 sm:w-auto\"\n >\n <LogOut className=\"size-4\" />\n {labels.signOut}\n </Button>\n </div>\n\n <div className=\"space-y-4\">\n <NavigationMenu viewport={false} className=\"w-full max-w-none justify-stretch\">\n <NavigationMenuList\n className={cn(\n \"grid h-auto w-full grid-cols-1 items-stretch justify-stretch rounded-lg border border-border bg-muted/40 p-1 sm:grid-cols-2\",\n columnClass,\n )}\n >\n {navItems.map((tab) => {\n const Icon = tab.icon;\n const active = activeTab === tab.id;\n return (\n <NavigationMenuItem key={tab.id}>\n <button\n type=\"button\"\n aria-current={active ? \"page\" : undefined}\n className=\"inline-flex h-9 w-full min-w-0 items-center justify-center gap-2 rounded-md px-3 text-sm font-medium whitespace-nowrap transition-colors outline-none select-none hover:bg-background hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50 data-[active=true]:bg-background data-[active=true]:text-foreground data-[active=true]:shadow-xs\"\n data-active={active}\n onClick={() => setActiveTab(tab.id)}\n >\n {Icon ? <Icon className=\"size-4 shrink-0\" /> : null}\n <span className=\"truncate\">{tab.label}</span>\n </button>\n </NavigationMenuItem>\n );\n })}\n </NavigationMenuList>\n </NavigationMenu>\n\n {navItems.map((tab) =>\n activeTab === tab.id ? <React.Fragment key={tab.id}>{tab.content}</React.Fragment> : null,\n )}\n </div>\n </div>\n );\n}\n\nexport default function AccountDashboard({\n apiBase,\n scope = \"me\",\n extraTabs = [],\n labels,\n signIn,\n}: AccountDashboardProps) {\n const resolved: AccountDashboardLabels = {\n ...DEFAULT_LABELS,\n ...labels,\n dashboard: { ...DEFAULT_LABELS.dashboard, ...labels?.dashboard },\n };\n const config = apiBase ? { apiBase } : undefined;\n return (\n <AuthProvider config={config}>\n <AccountShell\n scope={scope}\n extraTabs={extraTabs}\n labels={resolved}\n signIn={signIn}\n />\n </AuthProvider>\n );\n}\n",
16
+ "content": "\"use client\";\n\n// fa-auth account view whose FIRST/landing tab is the activity dashboard.\n// Headless auth state comes from the package (@mano8/astro-auth-m8/react); this\n// file is only the shadcn skin and is copied into the consumer via the\n// @fa-m8-auth registry. Secondary tabs (profile/sessions/api-keys/admin) are\n// passed in by the consumer via `extraTabs`, so locale + app-specific panels\n// stay owned by the app. Edit freely per app.\nimport * as React from \"react\";\nimport { LayoutDashboard, LogOut } from \"lucide-react\";\nimport {\n AuthProvider,\n useAuth,\n type AuthContextValue,\n} from \"@mano8/astro-auth-m8/react\";\nimport {\n hasMinimumRole,\n hasSuperuserPrivileges,\n} from \"@mano8/astro-auth-m8/authorization\";\nimport type { RoleType } from \"@mano8/astro-auth-m8/schemas\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { Skeleton } from \"@/components/ui/skeleton\";\nimport {\n NavigationMenu,\n NavigationMenuItem,\n NavigationMenuList,\n} from \"@/components/ui/navigation-menu\";\nimport {\n DashboardOverview,\n type DashboardOverviewLabels,\n} from \"@/components/fa-auth/dashboard-overview\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface AccountTab {\n id: string;\n label: string;\n icon?: React.ComponentType<{ className?: string }>;\n content: React.ReactNode;\n /** Only render this tab when the signed-in user is a superuser. */\n superuserOnly?: boolean;\n /**\n * Only render this tab when the signed-in user holds at least this role.\n * Uses the ordered hierarchy, so `minRole: \"admin\"` also admits a superadmin.\n * This is the admin tier: `fa-auth-m8` 2.0.0 authorizes the audit-log read\n * from the role hierarchy alone, so gating it with `superuserOnly` would hide\n * an admin's own surface from them.\n */\n minRole?: RoleType;\n}\n\nexport interface AccountDashboardLabels {\n dashboardTab: string;\n signOut: string;\n signInRequired: string;\n dashboard: Partial<DashboardOverviewLabels>;\n}\n\nconst DEFAULT_LABELS: AccountDashboardLabels = {\n dashboardTab: \"Dashboard\",\n signOut: \"Sign out\",\n signInRequired: \"Please sign in to view your account.\",\n dashboard: {},\n};\n\nexport interface AccountDashboardProps {\n /** Auth API base path; defaults to PUBLIC_FA_AUTH_API_BASE or \"/user\". */\n apiBase?: string;\n /** Dashboard scope: \"me\" (default) or \"global\" for superuser fleet stats. */\n scope?: \"me\" | \"global\";\n extraTabs?: AccountTab[];\n labels?: Partial<AccountDashboardLabels>;\n /** Rendered when the user is not authenticated. */\n signIn?: React.ReactNode;\n}\n\nfunction AccountShell({\n scope,\n extraTabs,\n labels,\n signIn,\n}: Required<Pick<AccountDashboardProps, \"scope\" | \"extraTabs\">> & {\n labels: AccountDashboardLabels;\n signIn?: React.ReactNode;\n}) {\n const { user, loading, logout }: AuthContextValue = useAuth();\n // Declared before the loading and signed-out early returns: this component\n // renders those branches first and the signed-in branch afterwards, so a hook\n // placed below them changes hook order between renders and React throws.\n const [activeTab, setActiveTab] = React.useState<string>(\"dashboard\");\n\n if (loading) {\n return (\n <div className=\"not-content mx-auto w-full max-w-6xl space-y-4\" aria-busy=\"true\">\n <Skeleton className=\"h-10 w-64\" />\n <Skeleton className=\"h-9 w-full max-w-md\" />\n <Skeleton className=\"h-72 w-full\" />\n </div>\n );\n }\n\n if (!user) {\n return (\n <div className=\"not-content mx-auto w-full max-w-md py-10 text-center text-sm text-muted-foreground\">\n {signIn ?? labels.signInRequired}\n </div>\n );\n }\n\n // Two deliberately different predicates: `superuserOnly` needs dual evidence\n // (role + is_superuser), `minRole` is the role hierarchy alone - the same\n // split the backend makes between its superuser and admin dependencies.\n // Each is only a display gate; every panel still self-gates and the service\n // stays the authority.\n const visibleTabs = extraTabs.filter(\n (tab) =>\n (!tab.superuserOnly ||\n hasSuperuserPrivileges(user.role, user.is_superuser)) &&\n (!tab.minRole || hasMinimumRole(user.role, tab.minRole)),\n );\n const navItems = [\n {\n id: \"dashboard\",\n label: labels.dashboardTab,\n icon: LayoutDashboard,\n content: <DashboardOverview scope={scope} labels={labels.dashboard} />,\n },\n ...visibleTabs,\n ];\n const columnClass = navItems.length >= 5 ? \"lg:grid-cols-5\" : \"lg:grid-cols-4\";\n\n return (\n <div className=\"not-content mx-auto flex w-full max-w-6xl flex-col gap-6\">\n <div className=\"flex flex-col gap-4 border-b pb-5 lg:flex-row lg:items-end lg:justify-between\">\n <div className=\"min-w-0 space-y-2\">\n <h1 className=\"text-2xl font-semibold tracking-tight md:text-3xl\">\n {user.email}\n </h1>\n <div className=\"flex flex-wrap items-center gap-2 text-sm text-muted-foreground\">\n <span className=\"rounded-md border px-2 py-0.5 text-xs uppercase tracking-wide\">\n {user.role}\n </span>\n {user.is_superuser ? (\n <span className=\"rounded-md border px-2 py-0.5 text-xs uppercase tracking-wide\">\n superuser\n </span>\n ) : null}\n </div>\n </div>\n <Button\n variant=\"outline\"\n onClick={() => void logout()}\n className=\"w-full justify-center gap-2 sm:w-auto\"\n >\n <LogOut className=\"size-4\" />\n {labels.signOut}\n </Button>\n </div>\n\n <div className=\"space-y-4\">\n <NavigationMenu viewport={false} className=\"w-full max-w-none justify-stretch\">\n <NavigationMenuList\n className={cn(\n \"grid h-auto w-full grid-cols-1 items-stretch justify-stretch rounded-lg border border-border bg-muted/40 p-1 sm:grid-cols-2\",\n columnClass,\n )}\n >\n {navItems.map((tab) => {\n const Icon = tab.icon;\n const active = activeTab === tab.id;\n return (\n <NavigationMenuItem key={tab.id}>\n <button\n type=\"button\"\n aria-current={active ? \"page\" : undefined}\n className=\"inline-flex h-9 w-full min-w-0 items-center justify-center gap-2 rounded-md px-3 text-sm font-medium whitespace-nowrap transition-colors outline-none select-none hover:bg-background hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50 data-[active=true]:bg-background data-[active=true]:text-foreground data-[active=true]:shadow-xs\"\n data-active={active}\n onClick={() => setActiveTab(tab.id)}\n >\n {Icon ? <Icon className=\"size-4 shrink-0\" /> : null}\n <span className=\"truncate\">{tab.label}</span>\n </button>\n </NavigationMenuItem>\n );\n })}\n </NavigationMenuList>\n </NavigationMenu>\n\n {navItems.map((tab) =>\n activeTab === tab.id ? <React.Fragment key={tab.id}>{tab.content}</React.Fragment> : null,\n )}\n </div>\n </div>\n );\n}\n\nexport default function AccountDashboard({\n apiBase,\n scope = \"me\",\n extraTabs = [],\n labels,\n signIn,\n}: AccountDashboardProps) {\n const resolved: AccountDashboardLabels = {\n ...DEFAULT_LABELS,\n ...labels,\n dashboard: { ...DEFAULT_LABELS.dashboard, ...labels?.dashboard },\n };\n const config = apiBase ? { apiBase } : undefined;\n return (\n <AuthProvider config={config}>\n <AccountShell\n scope={scope}\n extraTabs={extraTabs}\n labels={resolved}\n signIn={signIn}\n />\n </AuthProvider>\n );\n}\n",
17
17
  "type": "registry:component",
18
18
  "target": "components/fa-auth/account-dashboard.tsx"
19
19
  }
@@ -19,7 +19,7 @@
19
19
  "files": [
20
20
  {
21
21
  "path": "registry/blocks/account/security-panel.tsx",
22
- "content": "\"use client\";\n\n// fa-auth security panel: the admin-tier privileged-action audit log plus the\n// two superadmin-only retention purges. Headless logic stays a live dependency\n// — `useAuditLog` / `useSecurityPurges` (@mano8/astro-auth-m8/hooks) own the\n// calls and the package Zod schemas own the closed retention-window enum. This\n// file is only the shadcn skin, copied into the consumer via the @fa-m8-auth\n// registry — edit (and translate via `labels`) freely per app.\n//\n// Two tiers, two deliberately different gates, mirroring fa-auth-m8 2.0.0:\n// * the audit-log READ is authorized by the role hierarchy alone\n// (`get_current_active_admin`), so it is gated with `RequireRole\n// roles={[\"admin\"]}` — gating it on superuser would hide an admin's own\n// surface from them;\n// * both PURGES are superuser actions (`get_current_active_superuser`), so\n// they are gated with `RequireRole superuser` (dual evidence).\n// Which rows the log returns — an admin's own, or every row for a superadmin —\n// is decided server-side from the authenticated principal. This panel renders\n// what it receives and never sends an actor id to widen or narrow that.\nimport * as React from \"react\";\nimport type { ColumnDef } from \"@tanstack/react-table\";\nimport { RotateCcw, Trash2 } from \"lucide-react\";\nimport { RequireRole } from \"@mano8/astro-auth-m8/react\";\nimport { useAuditLog, useSecurityPurges } from \"@mano8/astro-auth-m8/hooks\";\nimport { ApiError } from \"@mano8/astro-auth-m8/errors\";\nimport {\n RetentionWindowSchema,\n type PrivilegedActionAuditPublic,\n type PurgeResponse,\n type RetentionWindow,\n} from \"@mano8/astro-auth-m8/schemas\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { Label } from \"@/components/ui/label\";\nimport { Badge } from \"@/components/ui/badge\";\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from \"@/components/ui/card\";\nimport { DataTable } from \"@/components/m8-ui/data-table\";\nimport { DataTableColumnHeader } from \"@/components/m8-ui/data-table-column-header\";\nimport {\n AccountToastHost,\n accountToast,\n ConfirmDeleteDialog,\n errorMessage,\n useClientTable,\n type UseClientTableOptions,\n} from \"./account-crud\";\n\nexport interface SecurityPanelLabels {\n auditTitle: string;\n auditDescription: string;\n auditScopeNotice: string;\n adminRequired: string;\n refresh: string;\n loading: string;\n empty: string;\n search: string;\n when: string;\n action: string;\n actor: string;\n actorRole: string;\n table: string;\n row: string;\n targetOwner: string;\n notAvailable: string;\n auditLoadFailed: string;\n purgeTitle: string;\n purgeDescription: string;\n retentionFloorNotice: string;\n window: string;\n windowLabels: Record<RetentionWindow, string>;\n purgeAuditTitle: string;\n purgeAuditDescription: string;\n purgeAuditConfirmTitle: string;\n purgeAuditConfirmBody: string;\n purgeKeysTitle: string;\n purgeKeysDescription: string;\n purgeKeysConfirmTitle: string;\n purgeKeysConfirmBody: string;\n purge: string;\n purging: string;\n cancel: string;\n purged: string;\n purgedRemoved: string;\n purgeFailed: string;\n unknownOutcomeTitle: string;\n unknownOutcomeBody: string;\n unknownOutcomeAcknowledge: string;\n}\n\nconst DEFAULT_LABELS: SecurityPanelLabels = {\n auditTitle: \"Privileged action audit log\",\n auditDescription:\n \"Every privileged write recorded by the auth service, newest first.\",\n auditScopeNotice:\n \"Scope is decided by the auth service from your own credentials: an admin sees the entries it authored, a superadmin sees every entry. This view never requests another user's entries.\",\n adminRequired: \"The audit log is available to admin accounts and above.\",\n refresh: \"Refresh\",\n loading: \"Loading audit entries...\",\n empty: \"No audit entries found.\",\n search: \"Search entries\",\n when: \"When\",\n action: \"Action\",\n actor: \"Actor\",\n actorRole: \"Actor role\",\n table: \"Table\",\n row: \"Row\",\n targetOwner: \"Target owner\",\n notAvailable: \"n/a\",\n auditLoadFailed: \"Failed to load the audit log.\",\n purgeTitle: \"Retention purges\",\n purgeDescription:\n \"Superuser-only maintenance: permanently delete records older than the selected retention window.\",\n retentionFloorNotice:\n \"The auth service enforces a minimum retention floor. It is server-side configuration and is not published by any endpoint, so a window shorter than the floor cannot be caught here - the service rejects it and its reason is shown verbatim.\",\n window: \"Retention window\",\n windowLabels: {\n \"1w\": \"Older than 1 week\",\n \"1m\": \"Older than 1 month\",\n \"3m\": \"Older than 3 months\",\n \"6m\": \"Older than 6 months\",\n \"1y\": \"Older than 1 year\",\n },\n purgeAuditTitle: \"Purge audit entries\",\n purgeAuditDescription:\n \"Deletes privileged-action audit entries older than the selected window.\",\n purgeAuditConfirmTitle: \"Purge audit entries?\",\n purgeAuditConfirmBody:\n \"This permanently deletes every audit entry older than the selected retention window. Audit history cannot be restored, and entries below the service's retention floor are refused.\",\n purgeKeysTitle: \"Purge revoked API keys\",\n purgeKeysDescription:\n \"Deletes revoked or expired API key records older than the selected window.\",\n purgeKeysConfirmTitle: \"Purge API key records?\",\n purgeKeysConfirmBody:\n \"This permanently deletes revoked and expired API key records older than the selected retention window. The records cannot be restored, and windows below the service's retention floor are refused.\",\n purge: \"Purge\",\n purging: \"Purging...\",\n cancel: \"Cancel\",\n purged: \"Purge complete.\",\n purgedRemoved: \"Records removed\",\n purgeFailed: \"Purge failed.\",\n unknownOutcomeTitle: \"Outcome unknown\",\n unknownOutcomeBody:\n \"The auth service could not confirm whether this purge ran. Check the current record counts before doing anything else - re-running it now could delete more than you intend, and the reported count would be wrong either way.\",\n unknownOutcomeAcknowledge: \"I have checked - re-enable\",\n};\n\nfunction formatDate(value: string | null | undefined, fallback: string): string {\n return value ? new Date(value).toLocaleString() : fallback;\n}\n\n// Raw identifiers are shown verbatim in a mono face: they are what an operator\n// correlates against the service's own logs, so they are never truncated.\nfunction monoCell(value: string | null | undefined, fallback: string) {\n return <span className=\"font-mono text-xs\">{value ?? fallback}</span>;\n}\n\n// Human-readable, sortable columns.\nfunction auditDetailColumns(\n t: SecurityPanelLabels,\n): ColumnDef<PrivilegedActionAuditPublic>[] {\n return [\n {\n accessorKey: \"created_at\",\n header: ({ column }) => (\n <DataTableColumnHeader column={column} title={t.when} />\n ),\n cell: ({ row }) => formatDate(row.original.created_at, t.notAvailable),\n },\n {\n accessorKey: \"action\",\n header: ({ column }) => (\n <DataTableColumnHeader column={column} title={t.action} />\n ),\n cell: ({ row }) => (\n <Badge variant=\"outline\" className=\"capitalize\">\n {row.original.action}\n </Badge>\n ),\n },\n {\n accessorKey: \"table_name\",\n header: ({ column }) => (\n <DataTableColumnHeader column={column} title={t.table} />\n ),\n },\n {\n accessorKey: \"actor_role\",\n header: ({ column }) => (\n <DataTableColumnHeader column={column} title={t.actorRole} />\n ),\n cell: ({ row }) => (\n <span className=\"capitalize\">{row.original.actor_role}</span>\n ),\n },\n ];\n}\n\n// The three id columns differ only by which field they read, so they share one\n// builder rather than repeating the same cell three times.\nfunction auditIdentifierColumns(\n t: SecurityPanelLabels,\n): ColumnDef<PrivilegedActionAuditPublic>[] {\n const identifier = (\n accessorKey: \"row_pk\" | \"actor_user_id\" | \"target_owner_id\",\n header: string,\n ): ColumnDef<PrivilegedActionAuditPublic> => ({\n accessorKey,\n header,\n enableSorting: false,\n cell: ({ row }) => monoCell(row.original[accessorKey], t.notAvailable),\n });\n\n return [\n identifier(\"row_pk\", t.row),\n identifier(\"actor_user_id\", t.actor),\n identifier(\"target_owner_id\", t.targetOwner),\n ];\n}\n\n// Client-side search/sort behaviour for the audit rows. Static, so it is built\n// once here rather than on every render of the section.\nconst AUDIT_TABLE_OPTIONS: UseClientTableOptions<PrivilegedActionAuditPublic> = {\n search: (entry) => `${entry.action} ${entry.table_name} ${entry.actor_user_id}`,\n sorters: {\n created_at: (entry) => entry.created_at,\n action: (entry) => entry.action,\n actor_role: (entry) => entry.actor_role,\n table_name: (entry) => entry.table_name,\n },\n initialSortBy: \"created_at\",\n initialSortDir: \"desc\",\n};\n\nfunction AuditRefreshButton({\n t,\n reload,\n}: {\n t: SecurityPanelLabels;\n reload: () => Promise<unknown>;\n}) {\n return (\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"outline\"\n onClick={() => {\n reload().catch((error) => {\n accountToast.error(errorMessage(error, t.auditLoadFailed));\n });\n }}\n >\n <RotateCcw className=\"size-4\" />\n {t.refresh}\n </Button>\n );\n}\n\nfunction AuditLogSection({ t }: { t: SecurityPanelLabels }) {\n // No actor filter is sent: the service scopes the rows from the caller's own\n // credentials, and passing one here could only ever ask for someone else's.\n const { rows, count, loading, reload } = useAuditLog({}, false);\n\n React.useEffect(() => {\n reload().catch(() => {});\n }, [reload]);\n\n const controller = useClientTable(rows, AUDIT_TABLE_OPTIONS);\n const columns = React.useMemo(\n () => [...auditDetailColumns(t), ...auditIdentifierColumns(t)],\n [t],\n );\n\n return (\n <Card>\n <CardHeader>\n <CardTitle>{t.auditTitle}</CardTitle>\n <CardDescription>{t.auditDescription}</CardDescription>\n </CardHeader>\n <CardContent className=\"space-y-4\">\n <p className=\"text-sm text-muted-foreground\">{t.auditScopeNotice}</p>\n <DataTable<PrivilegedActionAuditPublic, unknown>\n columns={columns}\n data={controller.data}\n rowCount={controller.rowCount}\n page={controller.page}\n pageSize={controller.pageSize}\n onPageChange={controller.onPageChange}\n onPageSizeChange={controller.onPageSizeChange}\n sortBy={controller.sortBy}\n sortDir={controller.sortDir}\n onSortChange={controller.onSortChange}\n q={controller.q}\n onSearchChange={controller.onSearchChange}\n loading={loading && count === 0}\n getRowId={(entry) => entry.id}\n labels={{\n loading: t.loading,\n empty: t.empty,\n toolbar: { search: t.search },\n }}\n addButton={<AuditRefreshButton t={t} reload={reload} />}\n />\n </CardContent>\n </Card>\n );\n}\n\nfunction PurgeCard({\n t,\n title,\n description,\n confirmTitle,\n confirmBody,\n action,\n testId,\n}: {\n t: SecurityPanelLabels;\n title: string;\n description: string;\n confirmTitle: string;\n confirmBody: string;\n action: (retention: RetentionWindow) => Promise<PurgeResponse>;\n testId: string;\n}) {\n const [retention, setRetention] = React.useState<RetentionWindow>(\"1y\");\n const [confirming, setConfirming] = React.useState(false);\n const [pending, setPending] = React.useState(false);\n // Set on a 503 only. The purge may or may not have run, so the control is\n // locked until the operator explicitly acknowledges having checked: a purge\n // is not idempotent in its reporting, and a blind re-run would both delete\n // more than intended and report a count the operator would misread.\n const [outcomeUnknown, setOutcomeUnknown] = React.useState(false);\n\n const confirm = async () => {\n setPending(true);\n try {\n const result = await action(retention);\n setConfirming(false);\n accountToast.success({\n title: t.purged,\n description: `${t.purgedRemoved}: ${result.removed}`,\n });\n } catch (error) {\n if (error instanceof ApiError && error.status === 503) {\n setOutcomeUnknown(true);\n setConfirming(false);\n }\n // 429 (rate limited, not attempted), 503 (unknown) and the free-text 400\n // retention-floor rejection are all mapped by the package's\n // describeApiError; nothing is retried automatically here.\n accountToast.error(errorMessage(error, t.purgeFailed));\n } finally {\n setPending(false);\n }\n };\n\n const selectId = `${testId}-window`;\n\n return (\n <Card className=\"h-full\" data-account-purge={testId}>\n <CardHeader>\n <CardTitle className=\"text-base\">{title}</CardTitle>\n <CardDescription>{description}</CardDescription>\n </CardHeader>\n <CardContent className=\"space-y-4\">\n <div className=\"space-y-1\">\n <Label htmlFor={selectId}>{t.window}</Label>\n {/* Closed enum, never free text or a date: the service accepts only\n these five windows, and the list is derived from the package\n schema so it cannot drift from the contract. */}\n <select\n id={selectId}\n aria-label={t.window}\n className=\"h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50\"\n value={retention}\n onChange={(event) =>\n setRetention(event.target.value as RetentionWindow)\n }\n >\n {RetentionWindowSchema.options.map((option) => (\n <option key={option} value={option}>\n {t.windowLabels[option]}\n </option>\n ))}\n </select>\n </div>\n\n {outcomeUnknown ? (\n <div\n role=\"alert\"\n className=\"space-y-2 rounded-md border border-destructive/50 p-3 text-sm\"\n >\n <p className=\"font-medium\">{t.unknownOutcomeTitle}</p>\n <p className=\"text-muted-foreground\">{t.unknownOutcomeBody}</p>\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"outline\"\n onClick={() => setOutcomeUnknown(false)}\n data-account-action=\"acknowledge-unknown\"\n >\n {t.unknownOutcomeAcknowledge}\n </Button>\n </div>\n ) : null}\n\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"destructive\"\n disabled={pending || outcomeUnknown}\n onClick={() => setConfirming(true)}\n data-account-action=\"purge\"\n >\n <Trash2 className=\"size-3.5\" />\n {pending ? t.purging : t.purge}\n </Button>\n </CardContent>\n\n {/* Purges are never a one-click action: each goes through its own\n confirmation naming what is deleted and that a window below the\n service's retention floor is refused. */}\n <ConfirmDeleteDialog\n open={confirming}\n onOpenChange={(open) => {\n if (!open) setConfirming(false);\n }}\n title={confirmTitle}\n description={`${confirmBody} ${t.retentionFloorNotice}`}\n confirmLabel={t.purge}\n cancelLabel={t.cancel}\n pending={pending}\n onConfirm={() => {\n void confirm();\n }}\n />\n </Card>\n );\n}\n\nfunction PurgeSection({ t }: { t: SecurityPanelLabels }) {\n const { purgeAudit, purgeKeys } = useSecurityPurges();\n\n return (\n <Card>\n <CardHeader>\n <CardTitle>{t.purgeTitle}</CardTitle>\n <CardDescription>{t.purgeDescription}</CardDescription>\n </CardHeader>\n <CardContent className=\"space-y-4\">\n <p className=\"text-sm text-muted-foreground\">{t.retentionFloorNotice}</p>\n <div className=\"grid auto-rows-fr gap-4 lg:grid-cols-2\">\n <PurgeCard\n t={t}\n testId=\"audit-log\"\n title={t.purgeAuditTitle}\n description={t.purgeAuditDescription}\n confirmTitle={t.purgeAuditConfirmTitle}\n confirmBody={t.purgeAuditConfirmBody}\n action={purgeAudit}\n />\n <PurgeCard\n t={t}\n testId=\"api-keys\"\n title={t.purgeKeysTitle}\n description={t.purgeKeysDescription}\n confirmTitle={t.purgeKeysConfirmTitle}\n confirmBody={t.purgeKeysConfirmBody}\n action={purgeKeys}\n />\n </div>\n </CardContent>\n </Card>\n );\n}\n\nexport function SecurityPanel({\n labels,\n}: {\n labels?: Partial<SecurityPanelLabels>;\n}) {\n const t = {\n ...DEFAULT_LABELS,\n ...labels,\n windowLabels: { ...DEFAULT_LABELS.windowLabels, ...labels?.windowLabels },\n };\n\n return (\n <div className=\"not-content flex w-full flex-col gap-6\">\n <AccountToastHost />\n {/* Admin tier: role hierarchy only, so a superadmin is admitted too. */}\n <RequireRole\n roles={[\"admin\"]}\n fallback={\n <p className=\"text-sm text-muted-foreground\">{t.adminRequired}</p>\n }\n >\n <AuditLogSection t={t} />\n </RequireRole>\n {/* Superadmin tier: dual evidence. Rendering nothing (not a message) for\n everyone else keeps the maintenance surface out of an admin's view. */}\n <RequireRole superuser>\n <PurgeSection t={t} />\n </RequireRole>\n </div>\n );\n}\n",
22
+ "content": "\"use client\";\n\n// fa-auth security panel: the admin-tier privileged-action audit log plus the\n// two superadmin-only retention purges. Headless logic stays a live dependency\n// — `useAuditLog` / `useSecurityPurges` (@mano8/astro-auth-m8/hooks) own the\n// calls and the package Zod schemas own the closed retention-window enum. This\n// file is only the shadcn skin, copied into the consumer via the @fa-m8-auth\n// registry — edit (and translate via `labels`) freely per app.\n//\n// Two tiers, two deliberately different gates, mirroring fa-auth-m8 2.0.0:\n// * the audit-log READ is authorized by the role hierarchy alone\n// (`get_current_active_admin`), so it is gated with `RequireRole\n// minimumRole=\"admin\"` — gating it on superuser would hide an admin's own\n// surface from them;\n// * both PURGES are superuser actions (`get_current_active_superuser`), so\n// they are gated with `RequireRole superuser` (dual evidence).\n// Which rows the log returns — an admin's own, or every row for a superadmin —\n// is decided server-side from the authenticated principal. This panel renders\n// what it receives and never sends an actor id to widen or narrow that.\nimport * as React from \"react\";\nimport type { ColumnDef } from \"@tanstack/react-table\";\nimport { RotateCcw, Trash2 } from \"lucide-react\";\nimport { RequireRole } from \"@mano8/astro-auth-m8/react\";\nimport { useAuditLog, useSecurityPurges } from \"@mano8/astro-auth-m8/hooks\";\nimport { ApiError } from \"@mano8/astro-auth-m8/errors\";\nimport {\n RetentionWindowSchema,\n type PrivilegedActionAuditPublic,\n type PurgeResponse,\n type RetentionWindow,\n} from \"@mano8/astro-auth-m8/schemas\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { Label } from \"@/components/ui/label\";\nimport { Badge } from \"@/components/ui/badge\";\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from \"@/components/ui/card\";\nimport { DataTable } from \"@/components/m8-ui/data-table\";\nimport { DataTableColumnHeader } from \"@/components/m8-ui/data-table-column-header\";\nimport {\n AccountToastHost,\n accountToast,\n ConfirmDeleteDialog,\n errorMessage,\n useClientTable,\n type UseClientTableOptions,\n} from \"./account-crud\";\n\nexport interface SecurityPanelLabels {\n auditTitle: string;\n auditDescription: string;\n auditScopeNotice: string;\n adminRequired: string;\n refresh: string;\n loading: string;\n empty: string;\n search: string;\n when: string;\n action: string;\n actor: string;\n actorRole: string;\n table: string;\n row: string;\n targetOwner: string;\n notAvailable: string;\n auditLoadFailed: string;\n purgeTitle: string;\n purgeDescription: string;\n retentionFloorNotice: string;\n window: string;\n windowLabels: Record<RetentionWindow, string>;\n purgeAuditTitle: string;\n purgeAuditDescription: string;\n purgeAuditConfirmTitle: string;\n purgeAuditConfirmBody: string;\n purgeKeysTitle: string;\n purgeKeysDescription: string;\n purgeKeysConfirmTitle: string;\n purgeKeysConfirmBody: string;\n purge: string;\n purging: string;\n cancel: string;\n purged: string;\n purgedRemoved: string;\n purgeFailed: string;\n unknownOutcomeTitle: string;\n unknownOutcomeBody: string;\n unknownOutcomeAcknowledge: string;\n}\n\nconst DEFAULT_LABELS: SecurityPanelLabels = {\n auditTitle: \"Privileged action audit log\",\n auditDescription:\n \"Every privileged write recorded by the auth service, newest first.\",\n auditScopeNotice:\n \"Scope is decided by the auth service from your own credentials: an admin sees the entries it authored, a superadmin sees every entry. This view never requests another user's entries.\",\n adminRequired: \"The audit log is available to admin accounts and above.\",\n refresh: \"Refresh\",\n loading: \"Loading audit entries...\",\n empty: \"No audit entries found.\",\n search: \"Search entries\",\n when: \"When\",\n action: \"Action\",\n actor: \"Actor\",\n actorRole: \"Actor role\",\n table: \"Table\",\n row: \"Row\",\n targetOwner: \"Target owner\",\n notAvailable: \"n/a\",\n auditLoadFailed: \"Failed to load the audit log.\",\n purgeTitle: \"Retention purges\",\n purgeDescription:\n \"Superuser-only maintenance: permanently delete records older than the selected retention window.\",\n retentionFloorNotice:\n \"The auth service enforces a minimum retention floor. It is server-side configuration and is not published by any endpoint, so a window shorter than the floor cannot be caught here - the service rejects it and its reason is shown verbatim.\",\n window: \"Retention window\",\n windowLabels: {\n \"1w\": \"Older than 1 week\",\n \"1m\": \"Older than 1 month\",\n \"3m\": \"Older than 3 months\",\n \"6m\": \"Older than 6 months\",\n \"1y\": \"Older than 1 year\",\n },\n purgeAuditTitle: \"Purge audit entries\",\n purgeAuditDescription:\n \"Deletes privileged-action audit entries older than the selected window.\",\n purgeAuditConfirmTitle: \"Purge audit entries?\",\n purgeAuditConfirmBody:\n \"This permanently deletes every audit entry older than the selected retention window. Audit history cannot be restored, and entries below the service's retention floor are refused.\",\n purgeKeysTitle: \"Purge revoked API keys\",\n purgeKeysDescription:\n \"Deletes revoked or expired API key records older than the selected window.\",\n purgeKeysConfirmTitle: \"Purge API key records?\",\n purgeKeysConfirmBody:\n \"This permanently deletes revoked and expired API key records older than the selected retention window. The records cannot be restored, and windows below the service's retention floor are refused.\",\n purge: \"Purge\",\n purging: \"Purging...\",\n cancel: \"Cancel\",\n purged: \"Purge complete.\",\n purgedRemoved: \"Records removed\",\n purgeFailed: \"Purge failed.\",\n unknownOutcomeTitle: \"Outcome unknown\",\n unknownOutcomeBody:\n \"The auth service could not confirm whether this purge ran. Check the current record counts before doing anything else - re-running it now could delete more than you intend, and the reported count would be wrong either way.\",\n unknownOutcomeAcknowledge: \"I have checked - re-enable\",\n};\n\nfunction formatDate(value: string | null | undefined, fallback: string): string {\n return value ? new Date(value).toLocaleString() : fallback;\n}\n\n// Raw identifiers are shown verbatim in a mono face: they are what an operator\n// correlates against the service's own logs, so they are never truncated.\nfunction monoCell(value: string | null | undefined, fallback: string) {\n return <span className=\"font-mono text-xs\">{value ?? fallback}</span>;\n}\n\n// Human-readable, sortable columns.\nfunction auditDetailColumns(\n t: SecurityPanelLabels,\n): ColumnDef<PrivilegedActionAuditPublic>[] {\n return [\n {\n accessorKey: \"created_at\",\n header: ({ column }) => (\n <DataTableColumnHeader column={column} title={t.when} />\n ),\n cell: ({ row }) => formatDate(row.original.created_at, t.notAvailable),\n },\n {\n accessorKey: \"action\",\n header: ({ column }) => (\n <DataTableColumnHeader column={column} title={t.action} />\n ),\n cell: ({ row }) => (\n <Badge variant=\"outline\" className=\"capitalize\">\n {row.original.action}\n </Badge>\n ),\n },\n {\n accessorKey: \"table_name\",\n header: ({ column }) => (\n <DataTableColumnHeader column={column} title={t.table} />\n ),\n },\n {\n accessorKey: \"actor_role\",\n header: ({ column }) => (\n <DataTableColumnHeader column={column} title={t.actorRole} />\n ),\n cell: ({ row }) => (\n <span className=\"capitalize\">{row.original.actor_role}</span>\n ),\n },\n ];\n}\n\n// The three id columns differ only by which field they read, so they share one\n// builder rather than repeating the same cell three times.\nfunction auditIdentifierColumns(\n t: SecurityPanelLabels,\n): ColumnDef<PrivilegedActionAuditPublic>[] {\n const identifier = (\n accessorKey: \"row_pk\" | \"actor_user_id\" | \"target_owner_id\",\n header: string,\n ): ColumnDef<PrivilegedActionAuditPublic> => ({\n accessorKey,\n header,\n enableSorting: false,\n cell: ({ row }) => monoCell(row.original[accessorKey], t.notAvailable),\n });\n\n return [\n identifier(\"row_pk\", t.row),\n identifier(\"actor_user_id\", t.actor),\n identifier(\"target_owner_id\", t.targetOwner),\n ];\n}\n\n// Client-side search/sort behaviour for the audit rows. Static, so it is built\n// once here rather than on every render of the section.\nconst AUDIT_TABLE_OPTIONS: UseClientTableOptions<PrivilegedActionAuditPublic> = {\n search: (entry) => `${entry.action} ${entry.table_name} ${entry.actor_user_id}`,\n sorters: {\n created_at: (entry) => entry.created_at,\n action: (entry) => entry.action,\n actor_role: (entry) => entry.actor_role,\n table_name: (entry) => entry.table_name,\n },\n initialSortBy: \"created_at\",\n initialSortDir: \"desc\",\n};\n\nfunction AuditRefreshButton({\n t,\n reload,\n}: {\n t: SecurityPanelLabels;\n reload: () => Promise<unknown>;\n}) {\n return (\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"outline\"\n onClick={() => {\n reload().catch((error) => {\n accountToast.error(errorMessage(error, t.auditLoadFailed));\n });\n }}\n >\n <RotateCcw className=\"size-4\" />\n {t.refresh}\n </Button>\n );\n}\n\nfunction AuditLogSection({ t }: { t: SecurityPanelLabels }) {\n // No actor filter is sent: the service scopes the rows from the caller's own\n // credentials, and passing one here could only ever ask for someone else's.\n const { rows, count, loading, reload } = useAuditLog({}, false);\n\n React.useEffect(() => {\n reload().catch(() => {});\n }, [reload]);\n\n const controller = useClientTable(rows, AUDIT_TABLE_OPTIONS);\n const columns = React.useMemo(\n () => [...auditDetailColumns(t), ...auditIdentifierColumns(t)],\n [t],\n );\n\n return (\n <Card>\n <CardHeader>\n <CardTitle>{t.auditTitle}</CardTitle>\n <CardDescription>{t.auditDescription}</CardDescription>\n </CardHeader>\n <CardContent className=\"space-y-4\">\n <p className=\"text-sm text-muted-foreground\">{t.auditScopeNotice}</p>\n <DataTable<PrivilegedActionAuditPublic, unknown>\n columns={columns}\n data={controller.data}\n rowCount={controller.rowCount}\n page={controller.page}\n pageSize={controller.pageSize}\n onPageChange={controller.onPageChange}\n onPageSizeChange={controller.onPageSizeChange}\n sortBy={controller.sortBy}\n sortDir={controller.sortDir}\n onSortChange={controller.onSortChange}\n q={controller.q}\n onSearchChange={controller.onSearchChange}\n loading={loading && count === 0}\n getRowId={(entry) => entry.id}\n labels={{\n loading: t.loading,\n empty: t.empty,\n toolbar: { search: t.search },\n }}\n addButton={<AuditRefreshButton t={t} reload={reload} />}\n />\n </CardContent>\n </Card>\n );\n}\n\nfunction PurgeCard({\n t,\n title,\n description,\n confirmTitle,\n confirmBody,\n action,\n testId,\n}: {\n t: SecurityPanelLabels;\n title: string;\n description: string;\n confirmTitle: string;\n confirmBody: string;\n action: (retention: RetentionWindow) => Promise<PurgeResponse>;\n testId: string;\n}) {\n const [retention, setRetention] = React.useState<RetentionWindow>(\"1y\");\n const [confirming, setConfirming] = React.useState(false);\n const [pending, setPending] = React.useState(false);\n // Set on a 503 only. The purge may or may not have run, so the control is\n // locked until the operator explicitly acknowledges having checked: a purge\n // is not idempotent in its reporting, and a blind re-run would both delete\n // more than intended and report a count the operator would misread.\n const [outcomeUnknown, setOutcomeUnknown] = React.useState(false);\n\n const confirm = async () => {\n setPending(true);\n try {\n const result = await action(retention);\n setConfirming(false);\n accountToast.success({\n title: t.purged,\n description: `${t.purgedRemoved}: ${result.removed}`,\n });\n } catch (error) {\n if (error instanceof ApiError && error.status === 503) {\n setOutcomeUnknown(true);\n setConfirming(false);\n }\n // 429 (rate limited, not attempted), 503 (unknown) and the free-text 400\n // retention-floor rejection are all mapped by the package's\n // describeApiError; nothing is retried automatically here.\n accountToast.error(errorMessage(error, t.purgeFailed));\n } finally {\n setPending(false);\n }\n };\n\n const selectId = `${testId}-window`;\n\n return (\n <Card className=\"h-full\" data-account-purge={testId}>\n <CardHeader>\n <CardTitle className=\"text-base\">{title}</CardTitle>\n <CardDescription>{description}</CardDescription>\n </CardHeader>\n <CardContent className=\"space-y-4\">\n <div className=\"space-y-1\">\n <Label htmlFor={selectId}>{t.window}</Label>\n {/* Closed enum, never free text or a date: the service accepts only\n these five windows, and the list is derived from the package\n schema so it cannot drift from the contract. */}\n <select\n id={selectId}\n aria-label={t.window}\n className=\"h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50\"\n value={retention}\n onChange={(event) =>\n setRetention(event.target.value as RetentionWindow)\n }\n >\n {RetentionWindowSchema.options.map((option) => (\n <option key={option} value={option}>\n {t.windowLabels[option]}\n </option>\n ))}\n </select>\n </div>\n\n {outcomeUnknown ? (\n <div\n role=\"alert\"\n className=\"space-y-2 rounded-md border border-destructive/50 p-3 text-sm\"\n >\n <p className=\"font-medium\">{t.unknownOutcomeTitle}</p>\n <p className=\"text-muted-foreground\">{t.unknownOutcomeBody}</p>\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"outline\"\n onClick={() => setOutcomeUnknown(false)}\n data-account-action=\"acknowledge-unknown\"\n >\n {t.unknownOutcomeAcknowledge}\n </Button>\n </div>\n ) : null}\n\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"destructive\"\n disabled={pending || outcomeUnknown}\n onClick={() => setConfirming(true)}\n data-account-action=\"purge\"\n >\n <Trash2 className=\"size-3.5\" />\n {pending ? t.purging : t.purge}\n </Button>\n </CardContent>\n\n {/* Purges are never a one-click action: each goes through its own\n confirmation naming what is deleted and that a window below the\n service's retention floor is refused. */}\n <ConfirmDeleteDialog\n open={confirming}\n onOpenChange={(open) => {\n if (!open) setConfirming(false);\n }}\n title={confirmTitle}\n description={`${confirmBody} ${t.retentionFloorNotice}`}\n confirmLabel={t.purge}\n cancelLabel={t.cancel}\n pending={pending}\n onConfirm={() => {\n void confirm();\n }}\n />\n </Card>\n );\n}\n\nfunction PurgeSection({ t }: { t: SecurityPanelLabels }) {\n const { purgeAudit, purgeKeys } = useSecurityPurges();\n\n return (\n <Card>\n <CardHeader>\n <CardTitle>{t.purgeTitle}</CardTitle>\n <CardDescription>{t.purgeDescription}</CardDescription>\n </CardHeader>\n <CardContent className=\"space-y-4\">\n <p className=\"text-sm text-muted-foreground\">{t.retentionFloorNotice}</p>\n <div className=\"grid auto-rows-fr gap-4 lg:grid-cols-2\">\n <PurgeCard\n t={t}\n testId=\"audit-log\"\n title={t.purgeAuditTitle}\n description={t.purgeAuditDescription}\n confirmTitle={t.purgeAuditConfirmTitle}\n confirmBody={t.purgeAuditConfirmBody}\n action={purgeAudit}\n />\n <PurgeCard\n t={t}\n testId=\"api-keys\"\n title={t.purgeKeysTitle}\n description={t.purgeKeysDescription}\n confirmTitle={t.purgeKeysConfirmTitle}\n confirmBody={t.purgeKeysConfirmBody}\n action={purgeKeys}\n />\n </div>\n </CardContent>\n </Card>\n );\n}\n\nexport function SecurityPanel({\n labels,\n}: {\n labels?: Partial<SecurityPanelLabels>;\n}) {\n const t = {\n ...DEFAULT_LABELS,\n ...labels,\n windowLabels: { ...DEFAULT_LABELS.windowLabels, ...labels?.windowLabels },\n };\n\n return (\n <div className=\"not-content flex w-full flex-col gap-6\">\n <AccountToastHost />\n {/* Admin tier: role hierarchy only, so a superadmin is admitted too. */}\n <RequireRole\n minimumRole=\"admin\"\n fallback={\n <p className=\"text-sm text-muted-foreground\">{t.adminRequired}</p>\n }\n >\n <AuditLogSection t={t} />\n </RequireRole>\n {/* Superadmin tier: dual evidence. Rendering nothing (not a message) for\n everyone else keeps the maintenance surface out of an admin's view. */}\n <RequireRole superuser>\n <PurgeSection t={t} />\n </RequireRole>\n </div>\n );\n}\n",
23
23
  "type": "registry:component",
24
24
  "target": "components/fa-auth/security-panel.tsx"
25
25
  }
@@ -1,10 +1,10 @@
1
1
  ---
2
- import { AuthProvider } from "@mano8/astro-auth-m8/react";
2
+ import { StarterLogoutPage } from "@mano8/astro-auth-m8/default-ui";
3
3
  import { logout } from "@mano8/astro-auth-m8/client";
4
4
  import AuthStyles from "./_AuthStyles.astro";
5
5
  ---
6
6
  <AuthStyles />
7
- <AuthProvider client:load config={{ apiBase: import.meta.env.PUBLIC_FA_AUTH_API_BASE }}>
7
+ <StarterLogoutPage client:load config={{ apiBase: import.meta.env.PUBLIC_FA_AUTH_API_BASE }}>
8
8
  <form
9
9
  class="fa-auth-panel mx-auto flex w-full max-w-md flex-col gap-6 rounded-2xl border border-border/70 bg-card/95 p-6 text-card-foreground shadow-sm backdrop-blur supports-[backdrop-filter]:bg-card/90"
10
10
  method="post"
@@ -21,7 +21,7 @@ import AuthStyles from "./_AuthStyles.astro";
21
21
  Sign out
22
22
  </button>
23
23
  </form>
24
- </AuthProvider>
24
+ </StarterLogoutPage>
25
25
  <script>
26
26
  import { logout } from "@mano8/astro-auth-m8/client";
27
27
  document.getElementById("fa-auth-logout")?.addEventListener("click", async () => {