@flowselections/core 1.0.22 → 1.0.23

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 (55) hide show
  1. package/README.md +61 -0
  2. package/dist/auth/redirect.d.ts +33 -4
  3. package/dist/auth/redirect.d.ts.map +1 -1
  4. package/dist/auth/redirect.js +58 -7
  5. package/dist/auth/useAuth.d.ts +1 -1
  6. package/dist/auth/useAuth.d.ts.map +1 -1
  7. package/dist/auth/useIsSuperadmin.d.ts +19 -0
  8. package/dist/auth/useIsSuperadmin.d.ts.map +1 -0
  9. package/dist/auth/useIsSuperadmin.js +16 -0
  10. package/dist/components/layout/AuthenticatedLayout.d.ts +18 -9
  11. package/dist/components/layout/AuthenticatedLayout.d.ts.map +1 -1
  12. package/dist/components/layout/AuthenticatedLayout.js +42 -8
  13. package/dist/components/layout/InstellingenPage.d.ts.map +1 -1
  14. package/dist/components/layout/InstellingenPage.js +9 -1
  15. package/dist/components/layout/ResetWachtwoordPage.d.ts +3 -1
  16. package/dist/components/layout/ResetWachtwoordPage.d.ts.map +1 -1
  17. package/dist/components/layout/ResetWachtwoordPage.js +5 -3
  18. package/dist/components/layout/Sidebar.d.ts +30 -6
  19. package/dist/components/layout/Sidebar.d.ts.map +1 -1
  20. package/dist/components/layout/Sidebar.js +31 -9
  21. package/dist/extensions/ShellExtensions.d.ts +14 -1
  22. package/dist/extensions/ShellExtensions.d.ts.map +1 -1
  23. package/dist/extensions/ShellExtensions.js +21 -2
  24. package/dist/hooks/useLogoSrc.d.ts +7 -0
  25. package/dist/hooks/useLogoSrc.d.ts.map +1 -0
  26. package/dist/hooks/useLogoSrc.js +29 -0
  27. package/dist/index.d.ts +17 -8
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +11 -4
  30. package/dist/permissions/resolve.d.ts +22 -0
  31. package/dist/permissions/resolve.d.ts.map +1 -0
  32. package/dist/permissions/resolve.js +76 -0
  33. package/dist/permissions/store.d.ts +38 -0
  34. package/dist/permissions/store.d.ts.map +1 -0
  35. package/dist/permissions/store.js +180 -0
  36. package/dist/permissions/useModulePermission.d.ts +52 -32
  37. package/dist/permissions/useModulePermission.d.ts.map +1 -1
  38. package/dist/permissions/useModulePermission.js +72 -104
  39. package/dist/routes/index.d.ts +48 -0
  40. package/dist/routes/index.d.ts.map +1 -0
  41. package/dist/routes/index.js +63 -0
  42. package/dist/server/index.d.ts +1 -1
  43. package/dist/server/index.d.ts.map +1 -1
  44. package/dist/server/index.js +1 -1
  45. package/dist/server/permissions.server.d.ts +21 -8
  46. package/dist/server/permissions.server.d.ts.map +1 -1
  47. package/dist/server/permissions.server.js +54 -9
  48. package/dist/shell/ShellContext.d.ts +26 -0
  49. package/dist/shell/ShellContext.d.ts.map +1 -0
  50. package/dist/shell/ShellContext.js +14 -0
  51. package/dist/styles.css +127 -0
  52. package/dist/types/module.d.ts +39 -4
  53. package/dist/types/module.d.ts.map +1 -1
  54. package/dist/types/module.js +33 -5
  55. package/package.json +13 -5
package/README.md CHANGED
@@ -111,3 +111,64 @@ retry-storm veroorzaken.
111
111
  De browser-client is env-gedreven en lazy (`VITE_SUPABASE_URL` /
112
112
  `VITE_SUPABASE_PUBLISHABLE_KEY`, met `SUPABASE_*` fallback voor SSR). Er staat
113
113
  geen projectref of key in de code, ook niet als fallback.
114
+
115
+ ## Rechten in 1.0.23
116
+
117
+ > **Zichtbaarheid, geen beveiliging.** Alles hieronder verbergt of toont UI. De
118
+ > data wordt afgeschermd door RLS en serverfuncties (`requireModulePermission`).
119
+
120
+ - **Automatisch via `AuthenticatedLayout` + `requireAuth`** — het gegenereerde
121
+ `_authenticated.tsx` hoeft niet te veranderen.
122
+ - Zijbalk: eerst het rechtenfilter, dan extensie-transforms (ordening). Uit met
123
+ `permissions={false}`. Tijdens het eerste laden een skeleton; na een fout of
124
+ 3 s time-out de volledige lijst (fail-open).
125
+ - `requireAuth` geeft `{ moduleAccess }` terug uit `beforeLoad` (context wordt
126
+ niet gemuteerd). Bij `none` toont de layout "Geen toegang". Wacht max. 3 s.
127
+ - Werkt zonder `QueryClientProvider` (gedeelde store, `useSyncExternalStore`).
128
+ - `useCan(module, feature?, level?)` / `<Can>` — niveaus `none < view < edit`.
129
+ - `NavItem.featureId` (anders `featureKey(href)`); groepen zonder zichtbare
130
+ kinderen verdwijnen, tenzij de module een eigen link heeft.
131
+ - `SettingsCard.moduleId/featureId`: kaarten erven het recht van hun module.
132
+ - Footer: `ShellExtensionsProvider useFooter` kan Instellingen verbergen;
133
+ Uitloggen is nooit te verbergen.
134
+ - `useIsSuperadmin()` (claim `user_roles`, terugval tabel); server:
135
+ `getRoleFlags(claims)`, `isSuperadminServer()`. Nooit voor moduletoegang.
136
+ - `useShell()` / `useShellModules()` — ruwe modulelijst + `shellId`.
137
+ - Admin en superadmin zien altijd alles.
138
+
139
+ ### Gedragswijziging `requireModulePermission`
140
+
141
+ **Vóór 1.0.23 liet deze functie alles door**: de RPC werd zonder `_user_id`
142
+ aangeroepen, werd niet gevonden, en dat gold als "add-on ontbreekt" →
143
+ toegestaan. Sinds 1.0.23 roept hij de 3-argumentversie aan; `_user_id` komt
144
+ uitsluitend uit het geverifieerde token van het verzoek, moduleniveau is
145
+ `_feature_id ''`. Zonder geldige sessie: 401. Controleer serverfuncties die
146
+ erop leunen: ze kunnen nu echt 403 geven.
147
+
148
+ ### Huisstijl
149
+
150
+ Tokens staan op één plek: `src/core/styles.css`, ook als
151
+ `@flowselections/core/styles.css`. Logo: `logoSrc`-prop, anders `logo` uit
152
+ `/huisstijl.json`, anders `/logo.png`.
153
+
154
+ ## Systeemroutes (`@flowselections/core/routes`, vanaf 1.0.23)
155
+
156
+ Shells houden per systeemroute een dun omhulsel; core levert de opties:
157
+
158
+ ```tsx
159
+ // src/routes/login.tsx
160
+ import { createFileRoute } from "@tanstack/react-router";
161
+ import { loginRoute } from "@flowselections/core/routes";
162
+ export const Route = createFileRoute("/login")(loginRoute({ landing: "/voorraad" }));
163
+ ```
164
+
165
+ Ook: `resetPasswordRoute({ landing })` (`/reset-wachtwoord`), `landingRoute({ landing })` (`/`),
166
+ `handoverRoute({ landing })` (`/auth/handover`, `ssr: false`). Bij `loginRoute` wint een veilig `?redirect`
167
+ (same-site pad) van `landing`, ook als je al ingelogd bent. Shells met eigen routebestanden blijven werken.
168
+
169
+ ## Publiceren
170
+
171
+ `vite build` (preview/hosting) schrijft verplicht naar `dist/` en overschrijft dan het pakket. Daarom:
172
+ `prepublishOnly` draait `build:pkg`, dat `dist/` eerst leegmaakt, opnieuw bouwt en met
173
+ `scripts/check-pkg.mjs` controleert dat `dist/` precies het pakket bevat. `npm publish` publiceert dus nooit
174
+ een preview-build.
@@ -1,3 +1,4 @@
1
+ import { type PermissionLevel } from "../permissions/resolve.js";
1
2
  /**
2
3
  * Accepteert alleen een same-site pad: begint met "/", niet met "//",
3
4
  * geen backslash, geen schema en geen stuurtekens. Anders `fallback`.
@@ -12,12 +13,40 @@ export interface RequireAuthArgs {
12
13
  context: unknown;
13
14
  location: {
14
15
  href: string;
16
+ pathname?: string;
15
17
  };
16
18
  }
19
+ /** Sinds 1.0.23: wat `requireAuth` aan de routecontext toevoegt. */
20
+ export interface ModuleAccessContext {
21
+ moduleAccess: PermissionLevel;
22
+ }
23
+ /**
24
+ * Sinds 1.0.23. Moduletoegang voor een pad. Wacht max. 3 s; fout, time-out,
25
+ * vrijgesteld pad of geen modulerij → `edit` (fail-open).
26
+ * Zichtbaarheid, geen beveiliging.
27
+ */
28
+ export declare function resolveModuleAccess(path: string, opts?: {
29
+ userId?: string | null;
30
+ accessToken?: string | null;
31
+ roles?: string[];
32
+ }): Promise<PermissionLevel>;
33
+ /** Sinds 1.0.23. `true` tenzij het niveau `none` is. Zichtbaarheid, geen beveiliging. */
34
+ export declare function canAccessModule(path: string, opts?: {
35
+ userId?: string | null;
36
+ accessToken?: string | null;
37
+ roles?: string[];
38
+ }): Promise<boolean>;
17
39
  /**
18
- * Guard voor de `_authenticated`-route (gebruik in beforeLoad, met ssr: false).
19
- * Zolang auth laadt: geen redirect; de root invalideert de router zodra auth
20
- * geladen is, waarna deze guard opnieuw draait.
40
+ * Guard voor de `_authenticated`-route (beforeLoad, met ssr: false).
41
+ *
42
+ * - Zolang auth laadt: niets (de root invalideert de router daarna).
43
+ * - Geen sessie: synchrone redirect naar `loginPath` met `?redirect=`.
44
+ * - Sinds 1.0.23: geeft `{ moduleAccess }` terug (TanStack voegt dat samen in
45
+ * de routecontext; de context wordt niet gemuteerd). Bij `none` rendert
46
+ * AuthenticatedLayout "Geen toegang". Fail-open na 3 s of bij een fout.
47
+ *
48
+ * Zichtbaarheid, geen beveiliging: data wordt afgeschermd door RLS en
49
+ * serverfuncties.
21
50
  */
22
- export declare function requireAuth({ context, location }: RequireAuthArgs, loginPath?: string): void;
51
+ export declare function requireAuth({ context, location }: RequireAuthArgs, loginPath?: string): void | ModuleAccessContext | Promise<ModuleAccessContext>;
23
52
  //# sourceMappingURL=redirect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../../src/core/auth/redirect.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAezE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5B;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,eAAe,EAAE,SAAS,SAAW,GAAG,IAAI,CAI9F"}
1
+ {"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../../src/core/auth/redirect.ts"],"names":[],"mappings":"AAEA,OAAO,EAA6B,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAG5F;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAazE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/C;AAED,oEAAoE;AACpE,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,eAAe,CAAC;CAC/B;AAUD;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,GACnF,OAAO,CAAC,eAAe,CAAC,CAM1B;AAED,yFAAyF;AACzF,wBAAsB,eAAe,CACnC,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAC/E,OAAO,CAAC,OAAO,CAAC,CAElB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CACzB,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,eAAe,EACtC,SAAS,SAAW,GACnB,IAAI,GAAG,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAuB3D"}
@@ -1,4 +1,7 @@
1
1
  import { redirect } from "@tanstack/react-router";
2
+ import { navKey } from "../types/module.js";
3
+ import { EXEMPT_KEYS, resolveLevel } from "../permissions/resolve.js";
4
+ import { getPermissionSnapshot, waitForPermissions } from "../permissions/store.js";
2
5
  /**
3
6
  * Accepteert alleen een same-site pad: begint met "/", niet met "//",
4
7
  * geen backslash, geen schema en geen stuurtekens. Anders `fallback`.
@@ -13,8 +16,6 @@ export function safeRedirectPath(value, fallback) {
13
16
  // eslint-disable-next-line no-control-regex
14
17
  if (/[\u0000-\u001f\u007f]/.test(value))
15
18
  return fallback;
16
- // Schema vóór het eerste "/", "?" of "#" (bijv. "/javascript:..." is ok, "javascript:" niet;
17
- // dat laatste valt al af op de "/"-regel, dit vangt varianten als "/\t//").
18
19
  try {
19
20
  const url = new URL(value, "http://same.invalid");
20
21
  if (url.origin !== "http://same.invalid")
@@ -34,14 +35,64 @@ export function readRedirectParam(fallback) {
34
35
  return fallback;
35
36
  return safeRedirectPath(new URLSearchParams(window.location.search).get("redirect"), fallback);
36
37
  }
38
+ function pathOf(location) {
39
+ return location.pathname ?? location.href.split("?")[0].split("#")[0];
40
+ }
41
+ function isAdminRoles(roles) {
42
+ return Array.isArray(roles) && (roles.includes("admin") || roles.includes("superadmin"));
43
+ }
44
+ /**
45
+ * Sinds 1.0.23. Moduletoegang voor een pad. Wacht max. 3 s; fout, time-out,
46
+ * vrijgesteld pad of geen modulerij → `edit` (fail-open).
47
+ * Zichtbaarheid, geen beveiliging.
48
+ */
49
+ export async function resolveModuleAccess(path, opts = {}) {
50
+ const key = navKey(path);
51
+ if (EXEMPT_KEYS.has(key) || isAdminRoles(opts.roles))
52
+ return "edit";
53
+ const snap = await waitForPermissions(opts.userId ?? null, opts.accessToken);
54
+ if (snap.status !== "ready" || isAdminRoles(snap.roles))
55
+ return "edit";
56
+ return resolveLevel(snap.rows, key);
57
+ }
58
+ /** Sinds 1.0.23. `true` tenzij het niveau `none` is. Zichtbaarheid, geen beveiliging. */
59
+ export async function canAccessModule(path, opts) {
60
+ return (await resolveModuleAccess(path, opts)) !== "none";
61
+ }
37
62
  /**
38
- * Guard voor de `_authenticated`-route (gebruik in beforeLoad, met ssr: false).
39
- * Zolang auth laadt: geen redirect; de root invalideert de router zodra auth
40
- * geladen is, waarna deze guard opnieuw draait.
63
+ * Guard voor de `_authenticated`-route (beforeLoad, met ssr: false).
64
+ *
65
+ * - Zolang auth laadt: niets (de root invalideert de router daarna).
66
+ * - Geen sessie: synchrone redirect naar `loginPath` met `?redirect=`.
67
+ * - Sinds 1.0.23: geeft `{ moduleAccess }` terug (TanStack voegt dat samen in
68
+ * de routecontext; de context wordt niet gemuteerd). Bij `none` rendert
69
+ * AuthenticatedLayout "Geen toegang". Fail-open na 3 s of bij een fout.
70
+ *
71
+ * Zichtbaarheid, geen beveiliging: data wordt afgeschermd door RLS en
72
+ * serverfuncties.
41
73
  */
42
74
  export function requireAuth({ context, location }, loginPath = "/login") {
43
75
  const auth = context?.auth;
44
- if (!auth || auth.loading || auth.isAuthenticated)
76
+ if (!auth || auth.loading)
45
77
  return;
46
- throw redirect({ to: loginPath, search: { redirect: location.href } });
78
+ if (!auth.isAuthenticated) {
79
+ throw redirect({ to: loginPath, search: { redirect: location.href } });
80
+ }
81
+ const path = pathOf(location);
82
+ const key = navKey(path);
83
+ const roles = Array.isArray(auth.roles) ? auth.roles : [];
84
+ if (EXEMPT_KEYS.has(key) || isAdminRoles(roles))
85
+ return { moduleAccess: "edit" };
86
+ const userId = auth.user?.id ?? null;
87
+ const snap = getPermissionSnapshot();
88
+ if (snap.userId === userId && snap.status !== "loading") {
89
+ // Synchroon antwoord als de cache al bekend is (geen wachttijd bij navigatie).
90
+ const level = snap.status === "ready" && !isAdminRoles(snap.roles) ? resolveLevel(snap.rows, key) : "edit";
91
+ return { moduleAccess: level };
92
+ }
93
+ return resolveModuleAccess(path, {
94
+ userId,
95
+ accessToken: auth.session?.access_token ?? null,
96
+ roles,
97
+ }).then((moduleAccess) => ({ moduleAccess }));
47
98
  }
@@ -1,5 +1,5 @@
1
1
  import { User, Session } from "@supabase/supabase-js";
2
- export type AppRole = "admin" | "manager" | "warehouse" | "sales" | "developer";
2
+ export type AppRole = "admin" | "manager" | "warehouse" | "sales" | "developer" | "superadmin" | "administratie" | "ai_admin" | "monteur" | "planner" | "receptie";
3
3
  export interface AuthState {
4
4
  user: User | null;
5
5
  session: Session | null;
@@ -1 +1 @@
1
- {"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/core/auth/useAuth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGtD,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,WAAW,GAAG,OAAO,GAAG,WAAW,CAAC;AAEhF,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE;QAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;CACvE;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IAC9E,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IACnE,YAAY,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACnC;AAED,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,WAAW,CAAC;AAElD,wBAAgB,YAAY,IAAI,WAAW,CAsE1C;AACD,wBAAgB,OAAO,IAAI,WAAW,CAErC"}
1
+ {"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/core/auth/useAuth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGtD,MAAM,MAAM,OAAO,GACf,OAAO,GAAG,SAAS,GAAG,WAAW,GAAG,OAAO,GAAG,WAAW,GACzD,YAAY,GAAG,eAAe,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,CAAC;AAErF,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE;QAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;CACvE;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IAC9E,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IACnE,YAAY,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACnC;AAED,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,WAAW,CAAC;AAElD,wBAAgB,YAAY,IAAI,WAAW,CAsE1C;AACD,wBAAgB,OAAO,IAAI,WAAW,CAErC"}
@@ -0,0 +1,19 @@
1
+ /** Pure: superadmin ⇒ admin (contract §4). */
2
+ export declare function roleFlags(roles: string[]): {
3
+ isSuperadmin: boolean;
4
+ isAdmin: boolean;
5
+ roles: string[];
6
+ };
7
+ /**
8
+ * Sinds 1.0.23. Rollen uit de JWT-claim `user_roles`, terugval op tabel
9
+ * `user_roles`. Nooit gebruiken voor moduletoegang (daarvoor
10
+ * `my_module_permissions`). Werkt zonder QueryClientProvider.
11
+ * Zichtbaarheid, geen beveiliging.
12
+ */
13
+ export declare function useIsSuperadmin(): {
14
+ isLoading: boolean;
15
+ isSuperadmin: boolean;
16
+ isAdmin: boolean;
17
+ roles: string[];
18
+ };
19
+ //# sourceMappingURL=useIsSuperadmin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIsSuperadmin.d.ts","sourceRoot":"","sources":["../../src/core/auth/useIsSuperadmin.ts"],"names":[],"mappings":"AAEA,8CAA8C;AAC9C,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE;;;;EAGxC;AAED;;;;;GAKG;AACH,wBAAgB,eAAe;;;;;EAG9B"}
@@ -0,0 +1,16 @@
1
+ import { usePermissionSnapshot } from "../permissions/store.js";
2
+ /** Pure: superadmin ⇒ admin (contract §4). */
3
+ export function roleFlags(roles) {
4
+ const isSuperadmin = roles.includes("superadmin");
5
+ return { isSuperadmin, isAdmin: isSuperadmin || roles.includes("admin"), roles };
6
+ }
7
+ /**
8
+ * Sinds 1.0.23. Rollen uit de JWT-claim `user_roles`, terugval op tabel
9
+ * `user_roles`. Nooit gebruiken voor moduletoegang (daarvoor
10
+ * `my_module_permissions`). Werkt zonder QueryClientProvider.
11
+ * Zichtbaarheid, geen beveiliging.
12
+ */
13
+ export function useIsSuperadmin() {
14
+ const snap = usePermissionSnapshot();
15
+ return { ...roleFlags(snap.roles), isLoading: !snap.rolesLoaded };
16
+ }
@@ -1,20 +1,29 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { SidebarProps } from "./Sidebar";
3
- /**
4
- * Alle Sidebar-props (auth, modules, shellId, ...) plus optionele children.
5
- * Zo verliest een shell bij migratie naar AuthenticatedLayout geen enkele
6
- * prop die hij voorheen rechtstreeks aan <Sidebar /> gaf.
7
- */
8
3
  export type AuthenticatedLayoutProps = SidebarProps & {
9
4
  /** Optioneel; standaard rendert de layout <Outlet />. */
10
5
  children?: ReactNode;
11
6
  /** Toon de gedeelde paginakop. Standaard ingeschakeld. */
12
7
  header?: boolean;
13
8
  };
9
+ type MatchLike = {
10
+ staticData?: unknown;
11
+ context?: unknown;
12
+ };
13
+ /** Sinds 1.0.23: diepste match met een niet-lege titel. */
14
+ export declare function pickTitle(matches: MatchLike[]): string;
15
+ /** Sinds 1.0.23: `moduleAccess` uit de diepste routecontext die hem heeft. */
16
+ export declare function pickModuleAccess(matches: MatchLike[]): string | undefined;
17
+ export declare function NoAccess(): import("react/jsx-runtime").JSX.Element;
14
18
  /**
15
- * Zijbalk + content-offset + mobiele topbalk. Desktop: ml-64 (gelijk aan de
16
- * oude shell-layout). Mobiel: geen marge, pt-14 onder de topbalk; de sticky
17
- * Header schuift via --core-topbar-h onder de topbalk.
19
+ * Zijbalk + content-offset + mobiele topbalk + paginakop.
20
+ *
21
+ * Sinds 1.0.23: filtert de zijbalk standaard op rechten (eerst rechten, dan
22
+ * extensie-transforms; uit met `permissions={false}`), toont "Geen toegang"
23
+ * als `requireAuth` `moduleAccess: "none"` teruggaf, en levert `useShell()`.
24
+ * Zichtbaarheid, geen beveiliging: data wordt afgeschermd door RLS en
25
+ * serverfuncties.
18
26
  */
19
- export declare function AuthenticatedLayout({ children, header, ...sidebarProps }: AuthenticatedLayoutProps): import("react/jsx-runtime").JSX.Element;
27
+ export declare function AuthenticatedLayout({ children, header, permissions, ...sidebarProps }: AuthenticatedLayoutProps): import("react/jsx-runtime").JSX.Element;
28
+ export {};
20
29
  //# sourceMappingURL=AuthenticatedLayout.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AuthenticatedLayout.d.ts","sourceRoot":"","sources":["../../../src/core/components/layout/AuthenticatedLayout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAG9C;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAAG,YAAY,GAAG;IACpD,yDAAyD;IACzD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,QAAQ,EAAE,MAAa,EAAE,GAAG,YAAY,EAAE,EAAE,wBAAwB,2CAkBzG"}
1
+ {"version":3,"file":"AuthenticatedLayout.d.ts","sourceRoot":"","sources":["../../../src/core/components/layout/AuthenticatedLayout.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAI9C,MAAM,MAAM,wBAAwB,GAAG,YAAY,GAAG;IACpD,yDAAyD;IACzD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,KAAK,SAAS,GAAG;IAAE,UAAU,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAE7D,2DAA2D;AAC3D,wBAAgB,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,MAAM,CAMtD;AAED,8EAA8E;AAC9E,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,MAAM,GAAG,SAAS,CAMzE;AAED,wBAAgB,QAAQ,4CAWvB;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,QAAQ,EACR,MAAa,EACb,WAAkB,EAClB,GAAG,YAAY,EAChB,EAAE,wBAAwB,2CA6B1B"}
@@ -1,15 +1,49 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo } from "react";
2
3
  import { Outlet, useMatches } from "@tanstack/react-router";
3
- import { Sidebar } from "./Sidebar";
4
+ import { Sidebar, useSidebarModules } from "./Sidebar";
4
5
  import { Header } from "./Header";
6
+ import { ShellContext } from "../../shell/ShellContext.js";
7
+ /** Sinds 1.0.23: diepste match met een niet-lege titel. */
8
+ export function pickTitle(matches) {
9
+ for (let i = matches.length - 1; i >= 0; i--) {
10
+ const t = matches[i].staticData?.title;
11
+ if (typeof t === "string" && t.trim() !== "")
12
+ return t;
13
+ }
14
+ return "";
15
+ }
16
+ /** Sinds 1.0.23: `moduleAccess` uit de diepste routecontext die hem heeft. */
17
+ export function pickModuleAccess(matches) {
18
+ for (let i = matches.length - 1; i >= 0; i--) {
19
+ const v = matches[i].context?.moduleAccess;
20
+ if (typeof v === "string")
21
+ return v;
22
+ }
23
+ return undefined;
24
+ }
25
+ export function NoAccess() {
26
+ return (_jsx("div", { className: "flex min-h-[60vh] items-center justify-center p-8", children: _jsxs("div", { className: "max-w-md text-center", children: [_jsx("h1", { className: "text-lg font-semibold text-foreground", children: "Geen toegang" }), _jsx("p", { className: "mt-2 text-sm text-muted-foreground", children: "Je hebt geen rechten voor deze module. Vraag een beheerder om toegang." })] }) }));
27
+ }
5
28
  /**
6
- * Zijbalk + content-offset + mobiele topbalk. Desktop: ml-64 (gelijk aan de
7
- * oude shell-layout). Mobiel: geen marge, pt-14 onder de topbalk; de sticky
8
- * Header schuift via --core-topbar-h onder de topbalk.
29
+ * Zijbalk + content-offset + mobiele topbalk + paginakop.
30
+ *
31
+ * Sinds 1.0.23: filtert de zijbalk standaard op rechten (eerst rechten, dan
32
+ * extensie-transforms; uit met `permissions={false}`), toont "Geen toegang"
33
+ * als `requireAuth` `moduleAccess: "none"` teruggaf, en levert `useShell()`.
34
+ * Zichtbaarheid, geen beveiliging: data wordt afgeschermd door RLS en
35
+ * serverfuncties.
9
36
  */
10
- export function AuthenticatedLayout({ children, header = true, ...sidebarProps }) {
37
+ export function AuthenticatedLayout({ children, header = true, permissions = true, ...sidebarProps }) {
11
38
  const matches = useMatches();
12
- const titleMatch = [...matches].reverse().find((match) => typeof match.staticData?.title === "string");
13
- const title = titleMatch?.staticData?.title ?? "";
14
- return (_jsxs("div", { className: "min-h-screen bg-background [--core-topbar-h:3.5rem] md:[--core-topbar-h:0px]", children: [_jsx(Sidebar, { ...sidebarProps }), _jsxs("div", { className: "flex min-h-dvh flex-col pt-14 md:ml-64 md:pt-0", children: [header && _jsx(Header, { title: title }), _jsx("main", { className: "flex-1", children: children ?? _jsx(Outlet, {}) })] })] }));
39
+ const title = pickTitle(matches);
40
+ const access = pickModuleAccess(matches);
41
+ const { visibleModules, loading } = useSidebarModules(sidebarProps.modules, permissions);
42
+ const shell = useMemo(() => ({
43
+ shellId: sidebarProps.shellId,
44
+ modules: sidebarProps.modules,
45
+ visibleModules,
46
+ permissionsLoading: loading,
47
+ }), [sidebarProps.shellId, sidebarProps.modules, visibleModules, loading]);
48
+ return (_jsx(ShellContext.Provider, { value: shell, children: _jsxs("div", { className: "min-h-screen bg-background [--core-topbar-h:3.5rem] md:[--core-topbar-h:0px]", children: [_jsx(Sidebar, { ...sidebarProps, permissions: permissions, visibleModules: visibleModules, loading: loading }), _jsxs("div", { className: "flex min-h-dvh flex-col pt-14 md:ml-64 md:pt-0", children: [header && _jsx(Header, { title: title }), _jsx("main", { className: "flex-1", children: permissions && access === "none" ? _jsx(NoAccess, {}) : (children ?? _jsx(Outlet, {})) })] })] }) }));
15
49
  }
@@ -1 +1 @@
1
- {"version":3,"file":"InstellingenPage.d.ts","sourceRoot":"","sources":["../../../src/core/components/layout/InstellingenPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAgB,MAAM,oBAAoB,CAAC;AAqInE,wBAAgB,gBAAgB,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,UAAU,EAAE,CAAA;CAAE,2CAWtE"}
1
+ {"version":3,"file":"InstellingenPage.d.ts","sourceRoot":"","sources":["../../../src/core/components/layout/InstellingenPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAgB,MAAM,oBAAoB,CAAC;AAwInE,wBAAgB,gBAAgB,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,UAAU,EAAE,CAAA;CAAE,2CAsBtE"}
@@ -1,4 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { moduleKey } from "../../types/module.js";
3
+ import { resolveLevel } from "../../permissions/resolve.js";
4
+ import { usePermissionSnapshot } from "../../permissions/store.js";
2
5
  import { useState } from "react";
3
6
  import { Button } from "../ui/button";
4
7
  import { Input } from "../ui/input";
@@ -72,7 +75,12 @@ const coreCards = [
72
75
  ];
73
76
  // ─── Main export ──────────────────────────────────────────────────────────────
74
77
  export function InstellingenPage({ modules }) {
75
- const moduleCards = modules.flatMap((m) => m.settingsCards);
78
+ // Sinds 1.0.23: modulekaarten erven het recht van hun module (of featureId).
79
+ // Core-kaarten altijd. Laden/fout/admin → tonen. Zichtbaarheid, geen beveiliging.
80
+ const snap = usePermissionSnapshot();
81
+ const filterOn = snap.status === "ready" && !snap.roles.includes("admin") && !snap.roles.includes("superadmin");
82
+ const moduleCards = modules.flatMap((m) => m.settingsCards.filter((card) => !filterOn ||
83
+ resolveLevel(snap.rows, card.moduleId ?? moduleKey(m), card.featureId ?? null) !== "none"));
76
84
  const allCards = [...coreCards, ...moduleCards].sort((a, b) => a.order - b.order);
77
85
  return (_jsx("div", { className: "p-6", children: _jsx("div", { className: "grid gap-6 lg:grid-cols-2", children: allCards.map((card, i) => _jsx(card.component, {}, i)) }) }));
78
86
  }
@@ -1,6 +1,8 @@
1
1
  interface ResetWachtwoordPageProps {
2
2
  redirectTo: string;
3
+ /** Pad van de inlogpagina. Standaard "/login". */
4
+ loginPath?: string;
3
5
  }
4
- export declare function ResetWachtwoordPage({ redirectTo }: ResetWachtwoordPageProps): import("react/jsx-runtime").JSX.Element;
6
+ export declare function ResetWachtwoordPage({ redirectTo, loginPath }: ResetWachtwoordPageProps): import("react/jsx-runtime").JSX.Element;
5
7
  export {};
6
8
  //# sourceMappingURL=ResetWachtwoordPage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ResetWachtwoordPage.d.ts","sourceRoot":"","sources":["../../../src/core/components/layout/ResetWachtwoordPage.tsx"],"names":[],"mappings":"AAQA,UAAU,wBAAwB;IAChC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,mBAAmB,CAAC,EAAE,UAAU,EAAE,EAAE,wBAAwB,2CAuF3E"}
1
+ {"version":3,"file":"ResetWachtwoordPage.d.ts","sourceRoot":"","sources":["../../../src/core/components/layout/ResetWachtwoordPage.tsx"],"names":[],"mappings":"AASA,UAAU,wBAAwB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,mBAAmB,CAAC,EAAE,UAAU,EAAE,SAAoB,EAAE,EAAE,wBAAwB,2CAwFjG"}
@@ -1,12 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState, useEffect } from "react";
3
+ import { useRouter } from "@tanstack/react-router";
3
4
  import { Button } from "../ui/button";
4
5
  import { Input } from "../ui/input";
5
6
  import { Label } from "../ui/label";
6
7
  import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "../ui/card";
7
8
  import { toast } from "sonner";
8
9
  import { supabase } from "../../supabase/client";
9
- export function ResetWachtwoordPage({ redirectTo }) {
10
+ export function ResetWachtwoordPage({ redirectTo, loginPath = "/login" }) {
11
+ const router = useRouter();
10
12
  const [password, setPassword] = useState("");
11
13
  const [confirmPassword, setConfirmPassword] = useState("");
12
14
  const [isLoading, setIsLoading] = useState(false);
@@ -41,11 +43,11 @@ export function ResetWachtwoordPage({ redirectTo }) {
41
43
  }
42
44
  else {
43
45
  toast.success("Wachtwoord succesvol gewijzigd!");
44
- window.location.href = redirectTo;
46
+ await router.navigate({ href: redirectTo });
45
47
  }
46
48
  };
47
49
  if (!isReady) {
48
- return (_jsx("div", { className: "min-h-screen flex items-center justify-center bg-background p-4", children: _jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { className: "text-center", children: [_jsx(CardTitle, { className: "text-2xl", children: "Ongeldige link" }), _jsx(CardDescription, { children: "Deze reset-link is ongeldig of verlopen. Vraag een nieuwe aan via de inlogpagina." })] }), _jsx(CardFooter, { className: "justify-center", children: _jsx(Button, { onClick: () => window.location.href = "/login", children: "Naar inlogpagina" }) })] }) }));
50
+ return (_jsx("div", { className: "min-h-screen flex items-center justify-center bg-background p-4", children: _jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { className: "text-center", children: [_jsx(CardTitle, { className: "text-2xl", children: "Ongeldige link" }), _jsx(CardDescription, { children: "Deze reset-link is ongeldig of verlopen. Vraag een nieuwe aan via de inlogpagina." })] }), _jsx(CardFooter, { className: "justify-center", children: _jsx(Button, { onClick: () => router.navigate({ href: loginPath }), children: "Naar inlogpagina" }) })] }) }));
49
51
  }
50
52
  return (_jsx("div", { className: "min-h-screen flex items-center justify-center bg-background p-4", children: _jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { className: "text-center", children: [_jsx(CardTitle, { className: "text-2xl", children: "Nieuw wachtwoord instellen" }), _jsx(CardDescription, { children: "Kies een nieuw wachtwoord voor je account" })] }), _jsxs("form", { onSubmit: handleSubmit, children: [_jsxs(CardContent, { className: "space-y-4", children: [_jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "password", children: "Nieuw wachtwoord" }), _jsx(Input, { id: "password", type: "password", value: password, onChange: (e) => setPassword(e.target.value), required: true, minLength: 6, maxLength: 128 })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "confirmPassword", children: "Bevestig wachtwoord" }), _jsx(Input, { id: "confirmPassword", type: "password", value: confirmPassword, onChange: (e) => setConfirmPassword(e.target.value), required: true, minLength: 6, maxLength: 128 })] })] }), _jsx(CardFooter, { children: _jsx(Button, { type: "submit", className: "w-full", disabled: isLoading, children: isLoading ? "Opslaan..." : "Wachtwoord opslaan" }) })] })] }) }));
51
53
  }
@@ -4,16 +4,40 @@ export interface SidebarProps {
4
4
  auth: AuthContext;
5
5
  modules: FlowModule[];
6
6
  /**
7
- * Identificeert de shell (bijv. "floriday-voorraad"). De core gebruikt hem
8
- * niet voor logica; hij komt als data-attribuut op de zijbalk, zodat
9
- * extensies en shells per-shell zijbalkvolgorde of styling kunnen koppelen.
7
+ * Identificeert de shell (bijv. "floriday-voorraad"). Komt als data-attribuut
8
+ * op de zijbalk, zodat extensies en shells per-shell volgorde of styling
9
+ * kunnen koppelen.
10
10
  */
11
11
  shellId?: string;
12
+ /**
13
+ * Sinds 1.0.23. Rechtenfilter vóór de extensie-transforms. Standaard `false`
14
+ * bij losse `<Sidebar>` (gedrag 1.0.22); AuthenticatedLayout zet hem aan.
15
+ * Zichtbaarheid, geen beveiliging.
16
+ */
17
+ permissions?: boolean;
18
+ /** Sinds 1.0.23. Logopad; anders `logo` uit /huisstijl.json, anders /logo.png. */
19
+ logoSrc?: string;
20
+ /** Sinds 1.0.23. Instellingen tonen (standaard true). Uitloggen is nooit te verbergen. */
21
+ showSettings?: boolean;
22
+ /**
23
+ * Sinds 1.0.23. Al berekende lijst (AuthenticatedLayout geeft die door);
24
+ * de Sidebar slaat dan zijn eigen pipeline over.
25
+ */
26
+ visibleModules?: FlowModule[];
27
+ /** Sinds 1.0.23. Toon een skeleton i.p.v. de lijst (eerste laden rechten). */
28
+ loading?: boolean;
12
29
  }
13
30
  /**
14
- * Desktop (md+): vaste zijbalk links, w-64 — ongewijzigd t.o.v. eerdere versies.
31
+ * Sinds 1.0.23. Pipeline: eerst rechten, dan extensie-transforms (ordening).
32
+ * Zichtbaarheid, geen beveiliging.
33
+ */
34
+ export declare function useSidebarModules(modules: FlowModule[], permissions: boolean): {
35
+ visibleModules: FlowModule[];
36
+ loading: boolean;
37
+ };
38
+ /**
39
+ * Desktop (md+): vaste zijbalk links, w-64.
15
40
  * Mobiel (<md): vaste topbalk (h-14) met menuknop die de zijbalk als Sheet opent.
16
- * Shells die AuthenticatedLayout gebruiken krijgen de juiste content-offset.
17
41
  */
18
- export declare function Sidebar({ auth, modules, shellId }: SidebarProps): import("react/jsx-runtime").JSX.Element;
42
+ export declare function Sidebar({ auth, modules, shellId, permissions, logoSrc, showSettings, visibleModules, loading, }: SidebarProps): import("react/jsx-runtime").JSX.Element;
19
43
  //# sourceMappingURL=Sidebar.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Sidebar.d.ts","sourceRoot":"","sources":["../../../src/core/components/layout/Sidebar.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAW,MAAM,uBAAuB,CAAC;AAMjE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AA6ID;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,YAAY,2CA8C/D"}
1
+ {"version":3,"file":"Sidebar.d.ts","sourceRoot":"","sources":["../../../src/core/components/layout/Sidebar.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAW,MAAM,uBAAuB,CAAC;AAOjE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0FAA0F;IAC1F,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,cAAc,CAAC,EAAE,UAAU,EAAE,CAAC;IAC9B,8EAA8E;IAC9E,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,WAAW,EAAE,OAAO;;;EAI5E;AAmKD;;;GAGG;AACH,wBAAgB,OAAO,CAAC,EACtB,IAAI,EACJ,OAAO,EACP,OAAO,EACP,WAAmB,EACnB,OAAO,EACP,YAAmB,EACnB,cAAc,EACd,OAAO,GACR,EAAE,YAAY,2CA2Dd"}
@@ -3,8 +3,20 @@ import { useEffect, useState } from "react";
3
3
  import { Link, useLocation } from "@tanstack/react-router";
4
4
  import { Settings, LogOut, ChevronDown, Menu } from "lucide-react";
5
5
  import { Sheet, SheetContent, SheetTitle } from "../ui/sheet";
6
+ import { Skeleton } from "../ui/skeleton";
6
7
  import { cn } from "../../lib/utils";
7
- import { useModuleListTransform } from "../../extensions/ShellExtensions.js";
8
+ import { useFooterItems, useModuleListTransform } from "../../extensions/ShellExtensions.js";
9
+ import { usePermissionFilteredModules } from "../../permissions/useModulePermission.js";
10
+ import { useLogoSrc } from "../../hooks/useLogoSrc.js";
11
+ /**
12
+ * Sinds 1.0.23. Pipeline: eerst rechten, dan extensie-transforms (ordening).
13
+ * Zichtbaarheid, geen beveiliging.
14
+ */
15
+ export function useSidebarModules(modules, permissions) {
16
+ const filtered = usePermissionFilteredModules(modules, permissions);
17
+ const visible = useModuleListTransform(filtered.modules);
18
+ return { visibleModules: visible, loading: filtered.loading };
19
+ }
8
20
  // ─── Single flat nav link ─────────────────────────────────────────────────────
9
21
  function SidebarLink({ item, pathname, indent = false, onNavigate, }) {
10
22
  const isActive = pathname === item.href;
@@ -21,29 +33,39 @@ function SidebarGroup({ item, pathname, onNavigate, }) {
21
33
  : "text-sidebar-muted hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"), children: [_jsx(item.icon, { className: "h-5 w-5" }), _jsx("span", { className: "flex-1 text-left", children: item.label }), _jsx(ChevronDown, { className: cn("h-4 w-4 transition-transform", open && "rotate-180") })] }), open && (_jsx("div", { className: "ml-3 space-y-1", children: item.children.map((child) => (_jsx(SidebarLink, { item: child, pathname: pathname, indent: true, onNavigate: onNavigate }, child.href))) }))] }));
22
34
  }
23
35
  // ─── Shared content (desktop aside + mobile sheet) ────────────────────────────
24
- function SidebarContent({ auth, modules, pathname, onNavigate, }) {
25
- // Zonder ShellExtensionsProvider komt de lijst ongewijzigd terug (code-volgorde).
26
- const visibleModules = useModuleListTransform(modules);
36
+ function SidebarContent({ auth, visibleModules, loading, logoSrc, showSettings, pathname, onNavigate, }) {
27
37
  const handleSignOut = async () => {
28
38
  onNavigate?.();
29
39
  await auth.signOut();
30
40
  };
31
- return (_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsx("div", { className: "flex shrink-0 items-center justify-center px-12 py-0 border-b border-sidebar-border", children: _jsx("img", { src: "/logo.png", alt: "Logo", className: "max-h-24 w-auto max-w-full object-contain" }) }), _jsx("nav", { className: "min-h-0 flex-1 space-y-1 px-3 py-4 overflow-y-auto sidebar-scroll", children: visibleModules.map((mod) => mod.nav.children?.length ? (_jsx(SidebarGroup, { item: mod.nav, pathname: pathname, onNavigate: onNavigate }, mod.id)) : (_jsx(SidebarLink, { item: mod.nav, pathname: pathname, onNavigate: onNavigate }, mod.id))) }), _jsxs("div", { className: "shrink-0 border-t border-sidebar-border px-3 py-4", children: [_jsx(SidebarLink, { item: { label: "Instellingen", href: "/instellingen", icon: Settings }, pathname: pathname, onNavigate: onNavigate }), _jsxs("button", { onClick: handleSignOut, className: "flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium transition-colors text-sidebar-muted hover:bg-sidebar-accent hover:text-sidebar-accent-foreground mt-1 cursor-pointer", children: [_jsx(LogOut, { className: "h-5 w-5" }), "Uitloggen"] })] })] }));
41
+ return (_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsx("div", { className: "flex shrink-0 items-center justify-center px-12 py-0 border-b border-sidebar-border", children: _jsx("img", { src: logoSrc, alt: "Logo", className: "max-h-24 w-auto max-w-full object-contain" }) }), _jsx("nav", { className: "min-h-0 flex-1 space-y-1 px-3 py-4 overflow-y-auto sidebar-scroll", "aria-busy": loading || undefined, children: loading ? (_jsx("div", { "data-testid": "sidebar-skeleton", className: "space-y-2", children: [0, 1, 2, 3].map((i) => (_jsx(Skeleton, { className: "h-9 w-full bg-sidebar-accent" }, i))) })) : (visibleModules.map((mod) => mod.nav.children?.length ? (_jsx(SidebarGroup, { item: mod.nav, pathname: pathname, onNavigate: onNavigate }, mod.id)) : (_jsx(SidebarLink, { item: mod.nav, pathname: pathname, onNavigate: onNavigate }, mod.id)))) }), _jsxs("div", { className: "shrink-0 border-t border-sidebar-border px-3 py-4", children: [showSettings && (_jsx(SidebarLink, { item: { label: "Instellingen", href: "/instellingen", icon: Settings }, pathname: pathname, onNavigate: onNavigate })), _jsxs("button", { onClick: handleSignOut, className: "flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium transition-colors text-sidebar-muted hover:bg-sidebar-accent hover:text-sidebar-accent-foreground mt-1 cursor-pointer", children: [_jsx(LogOut, { className: "h-5 w-5" }), "Uitloggen"] })] })] }));
32
42
  }
33
43
  // ─── Main Sidebar ─────────────────────────────────────────────────────────────
34
44
  /**
35
- * Desktop (md+): vaste zijbalk links, w-64 — ongewijzigd t.o.v. eerdere versies.
45
+ * Desktop (md+): vaste zijbalk links, w-64.
36
46
  * Mobiel (<md): vaste topbalk (h-14) met menuknop die de zijbalk als Sheet opent.
37
- * Shells die AuthenticatedLayout gebruiken krijgen de juiste content-offset.
38
47
  */
39
- export function Sidebar({ auth, modules, shellId }) {
48
+ export function Sidebar({ auth, modules, shellId, permissions = false, logoSrc, showSettings = true, visibleModules, loading, }) {
40
49
  const location = useLocation();
41
50
  const pathname = location.pathname;
42
51
  const [mobileOpen, setMobileOpen] = useState(false);
52
+ const own = useSidebarModules(modules, permissions);
53
+ const list = visibleModules ?? own.visibleModules;
54
+ const isLoading = loading ?? (visibleModules ? false : own.loading);
55
+ const footer = useFooterItems({ settings: showSettings });
56
+ const logo = useLogoSrc(logoSrc);
43
57
  // Sluit het mobiele menu bij elke routewijziging.
44
58
  useEffect(() => {
45
59
  setMobileOpen(false);
46
60
  }, [pathname]);
47
61
  const close = () => setMobileOpen(false);
48
- return (_jsxs(_Fragment, { children: [_jsx("aside", { "data-shell": shellId, className: "fixed left-0 top-0 z-40 hidden h-screen h-dvh w-64 bg-sidebar md:block", children: _jsx(SidebarContent, { auth: auth, modules: modules, pathname: pathname }) }), _jsxs("div", { className: "fixed inset-x-0 top-0 z-40 flex h-14 items-center gap-3 border-b border-sidebar-border bg-sidebar px-3 md:hidden", children: [_jsx("button", { type: "button", onClick: () => setMobileOpen(true), "aria-label": "Menu openen", className: "flex h-10 w-10 shrink-0 items-center justify-center rounded-lg text-sidebar-muted hover:bg-sidebar-accent hover:text-sidebar-accent-foreground", children: _jsx(Menu, { className: "h-5 w-5" }) }), _jsx("img", { src: "/logo.png", alt: "Logo", className: "h-8 w-auto max-w-[10rem] object-contain" })] }), _jsx(Sheet, { open: mobileOpen, onOpenChange: setMobileOpen, children: _jsxs(SheetContent, { side: "left", "data-shell": shellId, className: "w-64 max-w-[85vw] border-sidebar-border bg-sidebar p-0 md:hidden", children: [_jsx(SheetTitle, { className: "sr-only", children: "Navigatie" }), _jsx(SidebarContent, { auth: auth, modules: modules, pathname: pathname, onNavigate: close })] }) })] }));
62
+ const contentProps = {
63
+ auth,
64
+ visibleModules: list,
65
+ loading: isLoading,
66
+ logoSrc: logo,
67
+ showSettings: footer.settings,
68
+ pathname,
69
+ };
70
+ return (_jsxs(_Fragment, { children: [_jsx("aside", { "data-shell": shellId, className: "fixed left-0 top-0 z-40 hidden h-screen h-dvh w-64 bg-sidebar md:block", children: _jsx(SidebarContent, { ...contentProps }) }), _jsxs("div", { className: "fixed inset-x-0 top-0 z-40 flex h-14 items-center gap-3 border-b border-sidebar-border bg-sidebar px-3 md:hidden", children: [_jsx("button", { type: "button", onClick: () => setMobileOpen(true), "aria-label": "Menu openen", className: "flex h-10 w-10 shrink-0 items-center justify-center rounded-lg text-sidebar-muted hover:bg-sidebar-accent hover:text-sidebar-accent-foreground", children: _jsx(Menu, { className: "h-5 w-5" }) }), _jsx("img", { src: logo, alt: "Logo", className: "h-8 w-auto max-w-[10rem] object-contain" })] }), _jsx(Sheet, { open: mobileOpen, onOpenChange: setMobileOpen, children: _jsxs(SheetContent, { side: "left", "data-shell": shellId, className: "w-64 max-w-[85vw] border-sidebar-border bg-sidebar p-0 md:hidden", children: [_jsx(SheetTitle, { className: "sr-only", children: "Navigatie" }), _jsx(SidebarContent, { ...contentProps, onNavigate: close })] }) })] }));
49
71
  }
@@ -3,6 +3,17 @@ import type { FlowModule } from "../types/module.js";
3
3
  /** Transformeert de modulelijst (filteren en/of sorteren). Puur, geen side effects. */
4
4
  export type ModuleListTransform = (modules: FlowModule[]) => FlowModule[];
5
5
  export type UseModuleListTransform = () => ModuleListTransform;
6
+ /**
7
+ * Sinds 1.0.23. Footer-items van de zijbalk. Uitloggen staat bewust NIET in dit
8
+ * type: het is nooit te verbergen. Zichtbaarheid, geen beveiliging.
9
+ */
10
+ export interface FooterItems {
11
+ settings: boolean;
12
+ }
13
+ export type FooterTransform = (items: FooterItems) => FooterItems;
14
+ export type UseFooterTransform = () => FooterTransform;
15
+ /** Sinds 1.0.23. Past de footer-transform toe; fout → ongewijzigd. Zichtbaarheid, geen beveiliging. */
16
+ export declare function useFooterItems(base: FooterItems): FooterItems;
6
17
  export interface ShellExtensionsProviderProps {
7
18
  /**
8
19
  * Eén of meer hooks die elk een ModuleListTransform teruggeven.
@@ -16,9 +27,11 @@ export interface ShellExtensionsProviderProps {
16
27
  guard?: ComponentType<{
17
28
  children: ReactNode;
18
29
  }>;
30
+ /** Sinds 1.0.23. Optionele footer-transform (stabiele referentie). Uitloggen blijft altijd. */
31
+ useFooter?: UseFooterTransform;
19
32
  children: ReactNode;
20
33
  }
21
- export declare function ShellExtensionsProvider({ useModuleList, guard, children, }: ShellExtensionsProviderProps): import("react/jsx-runtime").JSX.Element;
34
+ export declare function ShellExtensionsProvider({ useModuleList, guard, useFooter, children, }: ShellExtensionsProviderProps): import("react/jsx-runtime").JSX.Element;
22
35
  export declare function useShellGuard(): ComponentType<{
23
36
  children: ReactNode;
24
37
  }> | undefined;